diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-06 14:30:15 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-06 14:30:15 -0400 |
commit | f23a43f694bd139329bac5603e82f2813ae2dc8f (patch) | |
tree | 5b3f9e68b74430471857e5e93bcb659ffc6b5894 /lib/sqlalchemy/orm/deprecated_interfaces.py | |
parent | 4e2c0f10cd164511b9c6377b72a8c0527e4eb716 (diff) | |
download | sqlalchemy-f23a43f694bd139329bac5603e82f2813ae2dc8f.tar.gz |
- nearly complete implementation of MapperEvents, tests still failing and optimizations needed
Diffstat (limited to 'lib/sqlalchemy/orm/deprecated_interfaces.py')
-rw-r--r-- | lib/sqlalchemy/orm/deprecated_interfaces.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/deprecated_interfaces.py b/lib/sqlalchemy/orm/deprecated_interfaces.py index 86f6ed74e..2145bef4b 100644 --- a/lib/sqlalchemy/orm/deprecated_interfaces.py +++ b/lib/sqlalchemy/orm/deprecated_interfaces.py @@ -30,6 +30,48 @@ class MapperExtension(object): """ + @classmethod + def _adapt_instrument_class(cls, self, listener): + cls._adapt_listener_methods(self, listener, ('instrument_class',)) + + @classmethod + def _adapt_listener(cls, self, listener): + cls._adapt_listener_methods( + self, listener, + ( + 'init_instance', + 'init_failed', + 'translate_row', + 'create_instance', + 'append_result', + 'populate_instance', + 'reconstruct_instance', + 'before_insert', + 'after_insert', + 'before_update', + 'after_update', + 'before_delete', + 'after_delete' + )) + + @classmethod + def _adapt_listener_methods(cls, self, listener, methods): + for meth in methods: + me_meth = getattr(MapperExtension, meth) + ls_meth = getattr(listener, meth) + # TODO: comparing self.methods to cls.method, + # this comparison is probably moot + if me_meth is not ls_meth: + if meth == 'reconstruct_instance': + def go(ls_meth): + def reconstruct(instance): + ls_meth(self, instance) + return reconstruct + event.listen(go(ls_meth), 'on_load', self.class_manager, raw=False) + else: + event.listen(ls_meth, "on_%s" % meth, self, raw=False, retval=True) + + def instrument_class(self, mapper, class_): """Receive a class when the mapper is first constructed, and has applied instrumentation to the mapped class. |