diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-10-02 13:31:07 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-10-02 13:31:07 -0400 |
commit | d46985d699e6ebffe45c94d91cfa842271e06bb0 (patch) | |
tree | b04fbb7dcc96afc2c0c3973e77e53ef2cbcc7643 /lib/sqlalchemy/orm/instrumentation.py | |
parent | 25c08f6def19e1034a887e972ad286ef122473d0 (diff) | |
download | sqlalchemy-d46985d699e6ebffe45c94d91cfa842271e06bb0.tar.gz |
- add instrumentation events
- simplify listen_for_events example with new system
- add "propagate", "retval", "raw" flags to attribute events. this solves the "return value"
issue as well as the "subclass" issue.
- begin thinking about event removal. Each listen() method will have a corresponding remove().
Custom listen() methods will have to package all the info onto the event function that is needed
to remove its state.
Diffstat (limited to 'lib/sqlalchemy/orm/instrumentation.py')
-rw-r--r-- | lib/sqlalchemy/orm/instrumentation.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/sqlalchemy/orm/instrumentation.py b/lib/sqlalchemy/orm/instrumentation.py index 3f134c58a..02ba5e1a2 100644 --- a/lib/sqlalchemy/orm/instrumentation.py +++ b/lib/sqlalchemy/orm/instrumentation.py @@ -92,7 +92,7 @@ class ClassManager(dict): self.manage() self._instrument_init() - dispatch = event.dispatcher(events.ClassEvents) + dispatch = event.dispatcher(events.InstanceEvents) @property def is_mapped(self): @@ -195,7 +195,8 @@ class ClassManager(dict): manager.instrument_attribute(key, inst, True) def post_configure_attribute(self, key): - pass + instrumentation_registry.dispatch.\ + on_attribute_instrument(self.class_, key, self[key]) def uninstrument_attribute(self, key, propagated=False): if key not in self: @@ -360,6 +361,7 @@ class _ClassInstrumentationAdapter(ClassManager): self._adapted.instrument_attribute(self.class_, key, inst) def post_configure_attribute(self, key): + super(_ClassInstrumentationAdpter, self).post_configure_attribute(key) self._adapted.post_configure_attribute(self.class_, key, self[key]) def install_descriptor(self, key, inst): @@ -470,6 +472,8 @@ class InstrumentationRegistry(object): _dict_finders = util.WeakIdentityMapping() _extended = False + dispatch = event.dispatcher(events.InstrumentationEvents) + def create_manager_for_cls(self, class_, **kw): assert class_ is not None assert manager_of_class(class_) is None @@ -506,6 +510,9 @@ class InstrumentationRegistry(object): self._manager_finders[class_] = manager.manager_getter() self._state_finders[class_] = manager.state_getter() self._dict_finders[class_] = manager.dict_getter() + + self.dispatch.on_class_instrument(class_) + return manager def _collect_management_factories_for(self, cls): @@ -572,6 +579,7 @@ class InstrumentationRegistry(object): def unregister(self, class_): if class_ in self._manager_finders: manager = self.manager_of_class(class_) + self.dispatch.on_class_uninstrument(class_) manager.unregister() manager.dispose() del self._manager_finders[class_] |