File: //opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyc
�
���ec @� se d Z d d l m Z d d l m Z d d l Z d d l m Z d d l Z d d l m Z d d l m
Z
d d
l m Z d d l m Z d d l m
Z
d d
l m Z d e j f d � � YZ d e f d � � YZ d e f d � � YZ d e f d � � YZ d e f d � � YZ d e f d � � YZ d e f d � � YZ d e f d � � YZ d S( s� Attribute implementation for _Dispatch classes.
The various listener targets for a particular event class are represented
as attributes, which refer to collections of listeners to be fired off.
These collections can exist at the class level as well as at the instance
level. An event is fired off using code like this::
some_object.dispatch.first_connect(arg1, arg2)
Above, ``some_object.dispatch`` would be an instance of ``_Dispatch`` and
``first_connect`` is typically an instance of ``_ListenerCollection``
if event listeners are present, or ``_EmptyListener`` if none are present.
The attribute mechanics here spend effort trying to ensure listener functions
are available with a minimum of function call overhead, that unnecessary
objects aren't created (i.e. many empty per-instance listener collections),
as well as that everything is garbage collectable when owning references are
lost. Other features such as "propagation" of listener functions across
many ``_Dispatch`` instances, "joining" of multiple ``_Dispatch`` instances,
as well as support for subclass propagation (e.g. events assigned to
``Pool`` vs. ``QueuePool``) are all implemented here.
i ( t absolute_import( t with_statementN( t chaini ( t legacy( t registryi ( t exc( t util( t threading( t AsyncAdaptedLockt
RefCollectionc B� s e Z d Z d � Z RS( t refc C� s t j | t j � S( N( t weakrefR
R t _collection_gced( t self( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyt _memoized_attr_ref2 s ( R
( t __name__t
__module__t __slots__R ( ( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyR / s t _empty_collectionc B� s5 e Z d � Z d � Z d � Z d � Z d � Z RS( c C� s d S( N( ( R
t element( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyt append7 s c C� s d S( N( ( R
t other( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyt extend: s c C� s d S( N( ( R
R ( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyt remove= s c C� s
t g � S( N( t iter( R
( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyt __iter__@ s c C� s d S( N( ( R
( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyt clearC s ( R R R R R R R ( ( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyR 6 s
t _ClsLevelDispatchc B� sn e Z d Z d Z d � Z d � Z d
� Z d � Z d � Z d
� Z d � Z
d � Z d � Z d � Z
RS( s2 Class-level events on :class:`._Dispatch` classes.t clsnamet namet arg_namest has_kwt legacy_signaturest _clslevelt __weakref__c C� s� | j | _ | j | _ t j | � } | j d | _ t | j � | _ t
t t t
| d g � d d � �� � | _ t j | | | � | _ t j � | _ d S( Ni t _legacy_signaturest keyc S� s | d S( Ni ( ( t s( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyt <lambda>] t ( R R R R t inspect_getfullargspect argsR t boolt varkwR t listt reversedt sortedt getattrR R t _augment_fn_docst __doc__R t WeakKeyDictionaryR! ( R
t parent_dispatch_clst fnt argspec( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyt __init__T s 'c C� sj | r | j | � } n | j rf y t j | d t �} Wn t k
rM qf Xt j | | | � } n | S( Nt no_self( t _wrap_fn_for_kwR R t get_callable_argspect Truet TypeErrorR t _wrap_fn_for_legacy( R
R4 t namedR5 ( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyt _adjust_fn_spece s
c � s � � f d � } | S( Nc � s/ t t � j | � � } | j | � � | � S( N( t dictt zipR t update( R) t kwt argdict( R4 R
( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyt wrap_kwr s
( ( R
R4 RD ( ( R4 R
sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyR8 q s c C� s� | j } t | t � s$ t d � � t | d t � sO t j d | f � � n x� t j | � D]� } | | k r� | | j
k r� | j | � q_ | | j
k r� | j | � n | r� | j
| j | j
� q_ | j
| j | j
� q_ Wt j | | � d S( Ns* Class-level Event targets must be classes.t _sa_propagate_class_eventss. Can't assign an event directly to the %s class( t dispatch_targett
isinstancet typet AssertionErrorR/ R: R t InvalidRequestErrorR t walk_subclassesR! t update_subclassR t
_listen_fnt
appendleftR t _stored_in_collection( R
t event_keyt is_appendt targett cls( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyt _do_insert_or_appendy s c C� s | j | d t �d S( NRQ ( RT t False( R
RP t propagate( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyt insert� s c C� s | j | d t �d S( NRQ ( RT R: ( R
RP RV ( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyR � s c C� s� | | j k rJ t | d t � r7 t j � | j | <qJ t � | j | <n | j | } xZ | j d D]K } | | j k re | j g | j | D] } | | k r� | ^ q� � qe qe Wd S( NRE i ( R! R/ R: t collectionst dequeR t __mro__R ( R
RR t clslevelRS R4 ( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyRL � s
c C� s` | j } x@ t j | � D]/ } | | j k r | j | j | j � q q Wt j | | � d S( N( RF R RK R! R RM R t _removed_from_collection( R
RP RR RS ( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyR � s
c C� sN t � } x. | j j � D] } | j | � | j � q Wt j | | � d S( s Clear all class level listenersN( t setR! t valuesRA R R t _clear( R
t to_cleart
dispatcher( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyR � s
c C� s | S( s� Return an event collection which can be modified.
For _ClsLevelDispatch at the class level of
a dispatcher, this returns self.
( ( R
t obj( ( sF /opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/event/attr.pyt
for_modify� s ( R R R R R R! R"