From: Mike Bayer Date: Thu, 30 Dec 2010 18:43:39 +0000 (-0500) Subject: - they don't want "on_". First step, change the naming convention on Events X-Git-Tag: rel_0_7b1~104 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f7bccfc83a5238b2772b68c4b11f9258050e88a;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - they don't want "on_". First step, change the naming convention on Events so that non-events are just _name. --- diff --git a/lib/sqlalchemy/engine/threadlocal.py b/lib/sqlalchemy/engine/threadlocal.py index adcce08c6d..b56f2d378e 100644 --- a/lib/sqlalchemy/engine/threadlocal.py +++ b/lib/sqlalchemy/engine/threadlocal.py @@ -29,12 +29,12 @@ class TLConnection(base.Connection): class TLEvents(events.EngineEvents): @classmethod - def listen(cls, target, identifier, fn): + def _listen(cls, target, identifier, fn): if target.TLConnection is TLConnection: target.TLConnection = base._listener_connection_cls( TLConnection, target.dispatch) - events.EngineEvents.listen(target, identifier, fn) + events.EngineEvents._listen(target, identifier, fn) class TLEngine(base.Engine): """An Engine that includes support for thread-local managed transactions.""" diff --git a/lib/sqlalchemy/event.py b/lib/sqlalchemy/event.py index dce09220ca..ad46a0c60e 100644 --- a/lib/sqlalchemy/event.py +++ b/lib/sqlalchemy/event.py @@ -11,9 +11,9 @@ def listen(target, identifier, fn, *args, **kw): """ 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)) @@ -27,8 +27,8 @@ def remove(target, identifier, fn): """ 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) @@ -93,13 +93,13 @@ def _create_dispatcher_class(cls, classname, bases, dict_): :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_'): @@ -120,7 +120,7 @@ class Events(object): __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 ( @@ -133,15 +133,15 @@ class Events(object): 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() diff --git a/lib/sqlalchemy/events.py b/lib/sqlalchemy/events.py index 3d9eb4d3bc..5801c94a77 100644 --- a/lib/sqlalchemy/events.py +++ b/lib/sqlalchemy/events.py @@ -142,7 +142,7 @@ class PoolEvents(event.Events): """ @classmethod - def accept_with(cls, target): + def _accept_with(cls, target): from sqlalchemy.engine import Engine from sqlalchemy.pool import Pool @@ -241,7 +241,7 @@ class EngineEvents(event.Events): """ @classmethod - def listen(cls, target, identifier, fn, retval=False): + def _listen(cls, target, identifier, fn, retval=False): from sqlalchemy.engine.base import Connection, \ _listener_connection_cls if target.Connection is Connection: @@ -271,7 +271,7 @@ class EngineEvents(event.Events): "'on_before_cursor_execute' engine " "event listeners accept the 'retval=True' " "argument.") - event.Events.listen(target, identifier, fn) + event.Events._listen(target, identifier, fn) def on_before_execute(self, conn, clauseelement, multiparams, params): """Intercept high level execute() events.""" diff --git a/lib/sqlalchemy/orm/events.py b/lib/sqlalchemy/orm/events.py index 383950add0..db7623bd22 100644 --- a/lib/sqlalchemy/orm/events.py +++ b/lib/sqlalchemy/orm/events.py @@ -17,7 +17,7 @@ class InstrumentationEvents(event.Events): """ @classmethod - def accept_with(cls, target): + def _accept_with(cls, target): from sqlalchemy.orm.instrumentation import instrumentation_registry if isinstance(target, type): @@ -26,11 +26,11 @@ class InstrumentationEvents(event.Events): 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): @@ -61,7 +61,7 @@ class InstanceEvents(event.Events): """ @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 @@ -81,20 +81,20 @@ class InstanceEvents(event.Events): 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): @@ -232,7 +232,7 @@ class MapperEvents(event.Events): """ @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 @@ -245,7 +245,7 @@ class MapperEvents(event.Events): 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 @@ -271,9 +271,9 @@ class MapperEvents(event.Events): 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, @@ -661,7 +661,7 @@ class MapperEvents(event.Events): """ @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): @@ -690,7 +690,7 @@ 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 \ @@ -711,7 +711,7 @@ class SessionEvents(event.Events): 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): @@ -845,7 +845,7 @@ class AttributeEvents(event.Events): """ @classmethod - def accept_with(cls, target): + def _accept_with(cls, target): from sqlalchemy.orm import interfaces # TODO: coverage if isinstance(target, interfaces.MapperProperty): @@ -854,7 +854,7 @@ class AttributeEvents(event.Events): 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: @@ -875,7 +875,7 @@ class AttributeEvents(event.Events): 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 @@ -883,10 +883,10 @@ class AttributeEvents(event.Events): 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): diff --git a/test/base/test_events.py b/test/base/test_events.py index 5fce23724a..664decbf1e 100644 --- a/test/base/test_events.py +++ b/test/base/test_events.py @@ -148,7 +148,7 @@ class TestCustomTargets(TestBase): class TargetEvents(event.Events): @classmethod - def accept_with(cls, target): + def _accept_with(cls, target): if target == 'one': return Target else: @@ -188,14 +188,14 @@ class TestListenOverride(TestBase): class TargetEvents(event.Events): @classmethod - def listen(cls, target, identifier, fn, add=False): + def _listen(cls, target, identifier, fn, add=False): if add: def adapt(x, y): fn(x + y) else: adapt = fn - event.Events.listen(target, identifier, adapt) + event.Events._listen(target, identifier, adapt) def on_event_one(self, x, y): pass diff --git a/test/engine/test_pool.py b/test/engine/test_pool.py index 91f675b849..392223d79b 100644 --- a/test/engine/test_pool.py +++ b/test/engine/test_pool.py @@ -404,7 +404,7 @@ class PoolEventsTest(PoolTestBase): def teardown(self): # TODO: need to get remove() functionality # going - pool.Pool.dispatch.clear() + pool.Pool.dispatch._clear() class DeprecatedPoolListenerTest(PoolTestBase): @testing.uses_deprecated(r".*Use event.listen") diff --git a/test/ext/test_mutable.py b/test/ext/test_mutable.py index e9573f50d7..8a51bd3fab 100644 --- a/test/ext/test_mutable.py +++ b/test/ext/test_mutable.py @@ -51,8 +51,8 @@ class _MutableDictTestBase(object): def teardown(self): # clear out mapper events - Mapper.dispatch.clear() - ClassManager.dispatch.clear() + Mapper.dispatch._clear() + ClassManager.dispatch._clear() super(_MutableDictTestBase, self).teardown() @testing.resolve_artifact_names @@ -180,8 +180,8 @@ class MutableCompositesTest(_base.MappedTest): def teardown(self): # clear out mapper events - Mapper.dispatch.clear() - ClassManager.dispatch.clear() + Mapper.dispatch._clear() + ClassManager.dispatch._clear() super(MutableCompositesTest, self).teardown() @classmethod diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py index ba7a82c62a..11a66c17f1 100644 --- a/test/orm/test_mapper.py +++ b/test/orm/test_mapper.py @@ -2304,8 +2304,8 @@ class MapperEventsTest(_fixtures.FixtureTest): def teardown(self): # TODO: need to get remove() functionality # going - Mapper.dispatch.clear() - ClassManager.dispatch.clear() + Mapper.dispatch._clear() + ClassManager.dispatch._clear() super(MapperEventsTest, self).teardown() def listen_all(self, mapper, **kw): diff --git a/test/orm/test_session.py b/test/orm/test_session.py index ed7a8dda67..8596e585a1 100644 --- a/test/orm/test_session.py +++ b/test/orm/test_session.py @@ -1482,7 +1482,7 @@ class SessionEventsTest(_fixtures.FixtureTest): def teardown(self): # TODO: need to get remove() functionality # going - Session.dispatch.clear() + Session.dispatch._clear() super(SessionEventsTest, self).teardown()