diff options
| author | Brian Jarrett <celttechie@gmail.com> | 2014-07-20 12:44:40 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2014-07-20 12:44:40 -0400 |
| commit | cca03097f47f22783d42d1853faac6cf84607c5a (patch) | |
| tree | 4fe1a63d03a2d88d1cf37e1167759dfaf84f4ce7 /lib/sqlalchemy/orm/instrumentation.py | |
| parent | 827329a0cca5351094a1a86b6b2be2b9182f0ae2 (diff) | |
| download | sqlalchemy-cca03097f47f22783d42d1853faac6cf84607c5a.tar.gz | |
- apply pep8 formatting to sqlalchemy/sql, sqlalchemy/util, sqlalchemy/dialects,
sqlalchemy/orm, sqlalchemy/event, sqlalchemy/testing
Diffstat (limited to 'lib/sqlalchemy/orm/instrumentation.py')
| -rw-r--r-- | lib/sqlalchemy/orm/instrumentation.py | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/lib/sqlalchemy/orm/instrumentation.py b/lib/sqlalchemy/orm/instrumentation.py index fd74704df..f58b8807f 100644 --- a/lib/sqlalchemy/orm/instrumentation.py +++ b/lib/sqlalchemy/orm/instrumentation.py @@ -34,6 +34,7 @@ from . import exc, collections, interfaces, state from .. import util from . import base + class ClassManager(dict): """tracks state information at the class level.""" @@ -54,16 +55,16 @@ class ClassManager(dict): self.originals = {} self._bases = [mgr for mgr in [ - manager_of_class(base) - for base in self.class_.__bases__ - if isinstance(base, type) - ] if mgr is not None] + manager_of_class(base) + for base in self.class_.__bases__ + if isinstance(base, type) + ] if mgr is not None] for base in self._bases: self.update(base) self.dispatch._events._new_classmanager_instance(class_, self) - #events._InstanceEventsHold.populate(class_, self) + # events._InstanceEventsHold.populate(class_, self) for basecls in class_.__mro__: mgr = manager_of_class(basecls) @@ -74,10 +75,10 @@ class ClassManager(dict): if '__del__' in class_.__dict__: util.warn("__del__() method on class %s will " - "cause unreachable cycles and memory leaks, " - "as SQLAlchemy instrumentation often creates " - "reference cycles. Please remove this method." % - class_) + "cause unreachable cycles and memory leaks, " + "as SQLAlchemy instrumentation often creates " + "reference cycles. Please remove this method." % + class_) def __hash__(self): return id(self) @@ -99,7 +100,8 @@ class ClassManager(dict): implement :class:`._InspectionAttr`. This includes :class:`.QueryableAttribute` as well as extension - types such as :class:`.hybrid_property` and :class:`.AssociationProxy`. + types such as :class:`.hybrid_property` and + :class:`.AssociationProxy`. """ if exclude is None: @@ -111,7 +113,6 @@ class ClassManager(dict): if isinstance(val, interfaces._InspectionAttr): yield key, val - def _attr_has_impl(self, key): """Return True if the given attribute is fully initialized. @@ -185,7 +186,6 @@ class ClassManager(dict): def dict_getter(self): return _default_dict_getter - def instrument_attribute(self, key, inst, propagated=False): if propagated: if key in self.local_attrs: @@ -210,7 +210,7 @@ class ClassManager(dict): def post_configure_attribute(self, key): _instrumentation_factory.dispatch.\ - attribute_instrument(self.class_, key, self[key]) + attribute_instrument(self.class_, key, self[key]) def uninstrument_attribute(self, key, propagated=False): if key not in self: @@ -284,19 +284,19 @@ class ClassManager(dict): def attributes(self): return iter(self.values()) - ## InstanceState management + # InstanceState management def new_instance(self, state=None): instance = self.class_.__new__(self.class_) setattr(instance, self.STATE_ATTR, - self._state_constructor(instance, self) - if not state else state) + self._state_constructor(instance, self) + if not state else state) return instance def setup_instance(self, instance, state=None): setattr(instance, self.STATE_ATTR, - self._state_constructor(instance, self) - if not state else state) + self._state_constructor(instance, self) + if not state else state) def teardown_instance(self, instance): delattr(instance, self.STATE_ATTR) @@ -320,7 +320,7 @@ class ClassManager(dict): # to be constructed, so that it is usable # in a non-ORM context at least. return self._subclass_manager(instance.__class__).\ - _new_state_if_none(instance) + _new_state_if_none(instance) else: state = self._state_constructor(instance, self) setattr(instance, self.STATE_ATTR, state) @@ -343,6 +343,7 @@ class ClassManager(dict): return '<%s of %r at %x>' % ( self.__class__.__name__, self.class_, id(self)) + class _SerializeManager(object): """Provide serialization of a :class:`.ClassManager`. @@ -350,6 +351,7 @@ class _SerializeManager(object): and ``__call__()`` on deserialize. """ + def __init__(self, state, d): self.class_ = state.class_ manager = state.manager @@ -359,12 +361,12 @@ class _SerializeManager(object): state.manager = manager = manager_of_class(self.class_) if manager is None: raise exc.UnmappedInstanceError( - inst, - "Cannot deserialize object of type %r - " - "no mapper() has " - "been configured for this class within the current " - "Python process!" % - self.class_) + inst, + "Cannot deserialize object of type %r - " + "no mapper() has " + "been configured for this class within the current " + "Python process!" % + self.class_) elif manager.is_mapped and not manager.mapper.configured: manager.mapper._configure_all() @@ -375,6 +377,7 @@ class _SerializeManager(object): manager.setup_instance(inst, state) manager.dispatch.unpickle(state, state_dict) + class InstrumentationFactory(object): """Factory for new ClassManager instances.""" @@ -426,6 +429,7 @@ instance_dict = _default_dict_getter = base.instance_dict manager_of_class = _default_manager_getter = base.manager_of_class + def register_class(class_): """Register class instrumentation. @@ -454,7 +458,7 @@ def is_instrumented(instance, key): """ return manager_of_class(instance.__class__).\ - is_instrumented(key, search=True) + is_instrumented(key, search=True) def _generate_init(class_, class_manager): |
