summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-12-30 14:07:15 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-12-30 14:07:15 -0500
commitecf1571ba79a81567428d345a4ec10255305de97 (patch)
tree4cd51f2f11ead15a1faad2ca307a08836549fcee /lib/sqlalchemy
parent7f7bccfc83a5238b2772b68c4b11f9258050e88a (diff)
downloadsqlalchemy-ecf1571ba79a81567428d345a4ec10255305de97.tar.gz
- factor out the dependency on the "on_" name
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/event.py33
-rw-r--r--lib/sqlalchemy/orm/attributes.py16
-rw-r--r--lib/sqlalchemy/orm/events.py2
-rw-r--r--lib/sqlalchemy/orm/mapper.py4
-rw-r--r--lib/sqlalchemy/pool.py2
5 files changed, 30 insertions, 27 deletions
diff --git a/lib/sqlalchemy/event.py b/lib/sqlalchemy/event.py
index ad46a0c60..ae49517b4 100644
--- a/lib/sqlalchemy/event.py
+++ b/lib/sqlalchemy/event.py
@@ -33,13 +33,16 @@ def remove(target, identifier, fn):
_registrars = util.defaultdict(list)
+def _is_event_name(name):
+ return not name.startswith('_') and name != 'dispatch'
+
class _UnpickleDispatch(object):
"""Serializable callable that re-generates an instance of :class:`_Dispatch`
given a particular :class:`.Events` subclass.
"""
- def __call__(self, parent_cls):
- return parent_cls.__dict__['dispatch'].dispatch_cls(parent_cls)
+ def __call__(self, _parent_cls):
+ return _parent_cls.__dict__['dispatch'].dispatch_cls(_parent_cls)
class _Dispatch(object):
"""Mirror the event listening definitions of an Events class with
@@ -61,23 +64,23 @@ class _Dispatch(object):
"""
- def __init__(self, parent_cls):
- self.parent_cls = parent_cls
+ def __init__(self, _parent_cls):
+ self._parent_cls = _parent_cls
def __reduce__(self):
- return _UnpickleDispatch(), (self.parent_cls, )
+ return _UnpickleDispatch(), (self._parent_cls, )
@property
- def descriptors(self):
- return (getattr(self, k) for k in dir(self) if k.startswith("on_"))
+ def _descriptors(self):
+ return (getattr(self, k) for k in dir(self) if _is_event_name(k))
- def update(self, other, only_propagate=True):
+ 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, only_propagate=only_propagate)
+ for ls in other._descriptors:
+ getattr(self, ls.name)._update(ls, only_propagate=only_propagate)
class _EventMeta(type):
@@ -102,13 +105,13 @@ def _create_dispatcher_class(cls, classname, bases, dict_):
dispatch_cls._clear = cls._clear
for k in dict_:
- if k.startswith('on_'):
+ if _is_event_name(k):
setattr(dispatch_cls, k, _DispatchDescriptor(dict_[k]))
_registrars[k].append(cls)
def _remove_dispatcher(cls):
for k in dir(cls):
- if k.startswith('on_'):
+ if _is_event_name(k):
_registrars[k].remove(cls)
if not _registrars[k]:
del _registrars[k]
@@ -143,7 +146,7 @@ class Events(object):
@classmethod
def _clear(cls):
for attr in dir(cls.dispatch):
- if attr.startswith("on_"):
+ if _is_event_name(attr):
getattr(cls.dispatch, attr).clear()
class _DispatchDescriptor(object):
@@ -175,7 +178,7 @@ class _DispatchDescriptor(object):
if obj is None:
return self
obj.__dict__[self.__name__] = result = \
- _ListenerCollection(self, obj.parent_cls)
+ _ListenerCollection(self, obj._parent_cls)
return result
class _ListenerCollection(object):
@@ -231,7 +234,7 @@ class _ListenerCollection(object):
def __nonzero__(self):
return bool(self.listeners or self.parent_listeners)
- def update(self, other, only_propagate=True):
+ def _update(self, other, only_propagate=True):
"""Populate from the listeners in another :class:`_Dispatch`
object."""
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py
index d6dc10ad4..d32d4f1b1 100644
--- a/lib/sqlalchemy/orm/attributes.py
+++ b/lib/sqlalchemy/orm/attributes.py
@@ -68,10 +68,10 @@ class QueryableAttribute(interfaces.PropComparator):
# immediate superclass
for base in manager._bases:
if key in base:
- self.dispatch.update(base[key].dispatch)
+ self.dispatch._update(base[key].dispatch)
dispatch = event.dispatcher(events.AttributeEvents)
- dispatch.dispatch_cls.active_history = False
+ dispatch.dispatch_cls._active_history = False
@util.memoized_property
def _supports_population(self):
@@ -276,17 +276,17 @@ class AttributeImpl(object):
ext._adapt_listener(attr, ext)
if active_history:
- self.dispatch.active_history = True
+ self.dispatch._active_history = True
self.expire_missing = expire_missing
def _get_active_history(self):
"""Backwards compat for impl.active_history"""
- return self.dispatch.active_history
+ return self.dispatch._active_history
def _set_active_history(self, value):
- self.dispatch.active_history = value
+ self.dispatch._active_history = value
active_history = property(_get_active_history, _set_active_history)
@@ -442,7 +442,7 @@ class ScalarAttributeImpl(AttributeImpl):
def delete(self, state, dict_):
# TODO: catch key errors, convert to attributeerror?
- if self.dispatch.active_history:
+ if self.dispatch._active_history:
old = self.get(state, dict_)
else:
old = dict_.get(self.key, NO_VALUE)
@@ -460,7 +460,7 @@ class ScalarAttributeImpl(AttributeImpl):
if initiator and initiator.parent_token is self.parent_token:
return
- if self.dispatch.active_history:
+ if self.dispatch._active_history:
old = self.get(state, dict_)
else:
old = dict_.get(self.key, NO_VALUE)
@@ -606,7 +606,7 @@ class ScalarObjectAttributeImpl(ScalarAttributeImpl):
if initiator and initiator.parent_token is self.parent_token:
return
- if self.dispatch.active_history:
+ if self.dispatch._active_history:
old = self.get(state, dict_, passive=PASSIVE_ONLY_PERSISTENT)
else:
old = self.get(state, dict_, passive=PASSIVE_NO_FETCH)
diff --git a/lib/sqlalchemy/orm/events.py b/lib/sqlalchemy/orm/events.py
index db7623bd2..e8dd07142 100644
--- a/lib/sqlalchemy/orm/events.py
+++ b/lib/sqlalchemy/orm/events.py
@@ -858,7 +858,7 @@ class AttributeEvents(event.Events):
raw=False, retval=False,
propagate=False):
if active_history:
- target.dispatch.active_history = True
+ target.dispatch._active_history = True
# TODO: for removal, need to package the identity
# of the wrapper with the original function.
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py
index cfd175008..563de116a 100644
--- a/lib/sqlalchemy/orm/mapper.py
+++ b/lib/sqlalchemy/orm/mapper.py
@@ -331,7 +331,7 @@ class Mapper(object):
def _configure_legacy_instrument_class(self):
if self.inherits:
- self.dispatch.update(self.inherits.dispatch)
+ self.dispatch._update(self.inherits.dispatch)
super_extensions = set(chain(*[m._deprecated_extensions
for m in self.inherits.iterate_to_root()]))
else:
@@ -353,7 +353,7 @@ class Mapper(object):
ext._adapt_listener(self, ext)
if self.inherits:
- self.class_manager.dispatch.update(
+ self.class_manager.dispatch._update(
self.inherits.class_manager.dispatch)
def _configure_class_instrumentation(self):
diff --git a/lib/sqlalchemy/pool.py b/lib/sqlalchemy/pool.py
index 4ae6ec022..572087217 100644
--- a/lib/sqlalchemy/pool.py
+++ b/lib/sqlalchemy/pool.py
@@ -135,7 +135,7 @@ class Pool(log.Identified):
self._reset_on_return = reset_on_return
self.echo = echo
if _dispatch:
- self.dispatch.update(_dispatch, only_propagate=False)
+ self.dispatch._update(_dispatch, only_propagate=False)
if events:
for fn, target in events:
event.listen(self, target, fn)