summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/inspection.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-07-16 17:29:02 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-07-16 17:29:02 -0400
commitce9a702dbd52946487f45b98ef20d1b7783facb6 (patch)
tree7273a1982850bf9975509295d766053d4fe822b1 /lib/sqlalchemy/inspection.py
parent1dc09bf6ede97ef08b2c8c0886a03b44bba735ff (diff)
downloadsqlalchemy-ce9a702dbd52946487f45b98ef20d1b7783facb6.tar.gz
- express most of the orm.util functions in terms of the inspection system
- modify inspection system: 1. raise a new exception for any case where the inspection context can't be returned. this supersedes the "not mapped" errors. 2. don't configure mappers on a mapper inspection. this allows the inspectors to be used during mapper config time. instead, the mapper configures on "with_polymorphic_selectable" now, which is needed for all queries - add a bunch of new "is_XYZ" attributes to inspectors - finish making the name change of "compile" -> "configure", for some reason this was only done partially
Diffstat (limited to 'lib/sqlalchemy/inspection.py')
-rw-r--r--lib/sqlalchemy/inspection.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/sqlalchemy/inspection.py b/lib/sqlalchemy/inspection.py
index 91f222f69..8b0a751ad 100644
--- a/lib/sqlalchemy/inspection.py
+++ b/lib/sqlalchemy/inspection.py
@@ -7,7 +7,7 @@
"""Base inspect API.
:func:`.inspect` provides access to a contextual object
-regarding a subject.
+regarding a subject.
Various subsections of SQLAlchemy,
such as the :class:`.Inspector`, :class:`.Mapper`, and
@@ -16,21 +16,28 @@ so that they may return a context object given a certain kind
of argument.
"""
-from . import util
+from . import util, exc
_registrars = util.defaultdict(list)
-def inspect(subject):
+def inspect(subject, raiseerr=True):
type_ = type(subject)
for cls in type_.__mro__:
if cls in _registrars:
reg = _registrars[cls]
- break
+ ret = reg(subject)
+ if ret is not None:
+ break
else:
- raise exc.InvalidRequestError(
- "No inspection system is "
- "available for object of type %s" %
- type_)
- return reg(subject)
+ reg = ret = None
+
+ if raiseerr and (
+ reg is None or ret is None
+ ):
+ raise exc.NoInspectionAvailable(
+ "No inspection system is "
+ "available for object of type %s" %
+ type_)
+ return ret
def _inspects(*types):
def decorate(fn_or_cls):
@@ -42,3 +49,6 @@ def _inspects(*types):
_registrars[type_] = fn_or_cls
return fn_or_cls
return decorate
+
+def _self_inspects(*types):
+ _inspects(*types)(lambda subject:subject) \ No newline at end of file