"""
for evt_cls in _registrars[identifier]:
- tgt = evt_cls.accept_with(target)
+ tgt = evt_cls._accept_with(target)
if tgt is not None:
- tgt.dispatch.listen(tgt, identifier, fn, *args, **kw)
+ tgt.dispatch._listen(tgt, identifier, fn, *args, **kw)
return
raise exc.InvalidRequestError("No such event %s for target %s" %
(identifier,target))
"""
for evt_cls in _registrars[identifier]:
- for tgt in evt_cls.accept_with(target):
- tgt.dispatch.remove(identifier, tgt, fn, *args, **kw)
+ for tgt in evt_cls._accept_with(target):
+ tgt.dispatch._remove(identifier, tgt, fn, *args, **kw)
return
_registrars = util.defaultdict(list)
:class:`.Events` class."""
# there's all kinds of ways to do this,
- # i.e. make a Dispatch class that shares the 'listen' method
+ # i.e. make a Dispatch class that shares the '_listen' method
# of the Event class, this is the straight monkeypatch.
dispatch_base = getattr(cls, 'dispatch', _Dispatch)
cls.dispatch = dispatch_cls = type("%sDispatch" % classname,
(dispatch_base, ), {})
- dispatch_cls.listen = cls.listen
- dispatch_cls.clear = cls.clear
+ dispatch_cls._listen = cls._listen
+ dispatch_cls._clear = cls._clear
for k in dict_:
if k.startswith('on_'):
__metaclass__ = _EventMeta
@classmethod
- def accept_with(cls, target):
+ def _accept_with(cls, target):
# Mapper, ClassManager, Session override this to
# also accept classes, scoped_sessions, sessionmakers, etc.
if hasattr(target, 'dispatch') and (
return None
@classmethod
- def listen(cls, target, identifier, fn, propagate=False):
+ def _listen(cls, target, identifier, fn, propagate=False):
getattr(target.dispatch, identifier).append(fn, target, propagate)
@classmethod
- def remove(cls, target, identifier, fn):
+ def _remove(cls, target, identifier, fn):
getattr(target.dispatch, identifier).remove(fn, target)
@classmethod
- def clear(cls):
+ def _clear(cls):
for attr in dir(cls.dispatch):
if attr.startswith("on_"):
getattr(cls.dispatch, attr).clear()
"""
@classmethod
- def accept_with(cls, target):
+ def _accept_with(cls, target):
from sqlalchemy.orm.instrumentation import instrumentation_registry
if isinstance(target, type):
return None
@classmethod
- def listen(cls, target, identifier, fn, propagate=False):
- event.Events.listen(target, identifier, fn, propagate=propagate)
+ def _listen(cls, target, identifier, fn, propagate=False):
+ event.Events._listen(target, identifier, fn, propagate=propagate)
@classmethod
- def remove(cls, identifier, target, fn):
+ def _remove(cls, identifier, target, fn):
raise NotImplementedError("Removal of instrumentation events not yet implemented")
def on_class_instrument(self, cls):
"""
@classmethod
- def accept_with(cls, target):
+ def _accept_with(cls, target):
from sqlalchemy.orm.instrumentation import ClassManager, manager_of_class
from sqlalchemy.orm import Mapper, mapper
return None
@classmethod
- def listen(cls, target, identifier, fn, raw=False, propagate=False):
+ def _listen(cls, target, identifier, fn, raw=False, propagate=False):
if not raw:
orig_fn = fn
def wrap(state, *arg, **kw):
return orig_fn(state.obj(), *arg, **kw)
fn = wrap
- event.Events.listen(target, identifier, fn, propagate=propagate)
+ event.Events._listen(target, identifier, fn, propagate=propagate)
if propagate:
for mgr in target.subclass_managers(True):
- event.Events.listen(mgr, identifier, fn, True)
+ event.Events._listen(mgr, identifier, fn, True)
@classmethod
- def remove(cls, identifier, target, fn):
+ def _remove(cls, identifier, target, fn):
raise NotImplementedError("Removal of instance events not yet implemented")
def on_first_init(self, manager, cls):
"""
@classmethod
- def accept_with(cls, target):
+ def _accept_with(cls, target):
from sqlalchemy.orm import mapper, class_mapper, Mapper
if target is mapper:
return Mapper
return target
@classmethod
- def listen(cls, target, identifier, fn,
+ def _listen(cls, target, identifier, fn,
raw=False, retval=False, propagate=False):
from sqlalchemy.orm.interfaces import EXT_CONTINUE
if propagate:
for mapper in target.self_and_descendants:
- event.Events.listen(mapper, identifier, fn, propagate=True)
+ event.Events._listen(mapper, identifier, fn, propagate=True)
else:
- event.Events.listen(target, identifier, fn)
+ event.Events._listen(target, identifier, fn)
def on_instrument_class(self, mapper, class_):
"""Receive a class when the mapper is first constructed,
"""
@classmethod
- def remove(cls, identifier, target, fn):
+ def _remove(cls, identifier, target, fn):
raise NotImplementedError("Removal of mapper events not yet implemented")
class SessionEvents(event.Events):
"""
@classmethod
- def accept_with(cls, target):
+ def _accept_with(cls, target):
from sqlalchemy.orm import ScopedSession, Session
if isinstance(target, ScopedSession):
if not isinstance(target.session_factory, type) or \
return None
@classmethod
- def remove(cls, identifier, target, fn):
+ def _remove(cls, identifier, target, fn):
raise NotImplementedError("Removal of session events not yet implemented")
def on_before_commit(self, session):
"""
@classmethod
- def accept_with(cls, target):
+ def _accept_with(cls, target):
from sqlalchemy.orm import interfaces
# TODO: coverage
if isinstance(target, interfaces.MapperProperty):
return target
@classmethod
- def listen(cls, target, identifier, fn, active_history=False,
+ def _listen(cls, target, identifier, fn, active_history=False,
raw=False, retval=False,
propagate=False):
if active_history:
return orig_fn(target, value, *arg)
fn = wrap
- event.Events.listen(target, identifier, fn, propagate)
+ event.Events._listen(target, identifier, fn, propagate)
if propagate:
from sqlalchemy.orm.instrumentation import manager_of_class
manager = manager_of_class(target.class_)
for mgr in manager.subclass_managers(True):
- event.Events.listen(mgr[target.key], identifier, fn, True)
+ event.Events._listen(mgr[target.key], identifier, fn, True)
@classmethod
- def remove(cls, identifier, target, fn):
+ def _remove(cls, identifier, target, fn):
raise NotImplementedError("Removal of attribute events not yet implemented")
def on_append(self, target, value, initiator):