diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-06 17:34:54 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-11-06 17:34:54 -0400 |
| commit | 1f2423d23cc3e8bf8db60b56436752fbd3d83f9d (patch) | |
| tree | 85f5ea39fffcd489ae39006092e3dd3c924e2e6b /lib/sqlalchemy/event.py | |
| parent | 1de6d22ace3a2d5a8ff23b2417f502cf2f4326fc (diff) | |
| download | sqlalchemy-1f2423d23cc3e8bf8db60b56436752fbd3d83f9d.tar.gz | |
- attempting system of propagation. getting stuck on attempting to use instance methods as listeners.
Diffstat (limited to 'lib/sqlalchemy/event.py')
| -rw-r--r-- | lib/sqlalchemy/event.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/sqlalchemy/event.py b/lib/sqlalchemy/event.py index 5f46a1153..955c33797 100644 --- a/lib/sqlalchemy/event.py +++ b/lib/sqlalchemy/event.py @@ -18,6 +18,8 @@ def listen(fn, identifier, target, *args, **kw): for evt_cls in _registrars[identifier]: tgt = evt_cls.accept_with(target) if tgt is not None: + if kw.pop('propagate', False): + fn._sa_event_propagate = True tgt.dispatch.listen(fn, identifier, tgt, *args, **kw) return raise exc.InvalidRequestError("No such event %s for target %s" % @@ -63,12 +65,12 @@ class _Dispatch(object): def descriptors(self): return (getattr(self, k) for k in dir(self) if k.startswith("on_")) - def update(self, other): + def update(self, other, only_propagate=True): """Populate from the listeners in another :class:`_Dispatch` object.""" for ls in other.descriptors: - getattr(self, ls.name).update(ls) + getattr(self, ls.name).update(ls, only_propagate=only_propagate) class _EventMeta(type): """Intercept new Event subclasses and create @@ -195,7 +197,7 @@ class _ListenerCollection(object): def __nonzero__(self): return bool(self.listeners or self.parent_listeners) - def update(self, other): + def update(self, other, only_propagate=True): """Populate from the listeners in another :class:`_Dispatch` object.""" @@ -203,7 +205,9 @@ class _ListenerCollection(object): existing_listener_set = set(existing_listeners) existing_listeners.extend([l for l in other.listeners - if l not in existing_listener_set]) + if l not in existing_listener_set + and not only_propagate or getattr(l, '_sa_event_propagate', False) + ]) def append(self, obj, target): if obj not in self.listeners: |
