B 4] &@sdZddlmZddlZddlmZddlmZddlmZdd lm Z e e Z d d Z Gd d d eZGdddeZGdddeZddZddZGddde eeZGdddeZGdddeZdS)aBase implementation classes. The public-facing ``Events`` serves as the base class for an event interface; its public attributes represent different kinds of events. These attributes are mirrored onto a ``_Dispatch`` class, which serves as a container for collections of listener functions. These collections are represented both at the class level of a particular ``_Dispatch`` class as well as within instances of ``_Dispatch``. )absolute_importN)_ClsLevelDispatch)_EmptyListener)_JoinedListener)utilcCs|d o|dkS)N_dispatch) startswith)namer H/opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/event/base.py_is_event_namesrc@seZdZdZddZdS)_UnpickleDispatchzSerializable callable that re-generates an instance of :class:`_Dispatch` given a particular :class:`.Events` subclass. cCs8x2|jD] }d|jkr|jdj|SqWtddS)Nr z*No class with a 'dispatch' member present.)__mro____dict__r _for_classAttributeError)self _instance_clsclsr r r__call__)s     z_UnpickleDispatch.__call__N)__name__ __module__ __qualname____doc__rr r r rr#src@sxeZdZdZdZeZdddZddZ e dd Z e d d Z d d Z ddZddZddZdddZddZdS) _Dispatcha;Mirror the event listening definitions of an Events class with listener collections. Classes which define a "dispatch" member will return a non-instantiated :class:`._Dispatch` subclass when the member is accessed at the class level. When the "dispatch" member is accessed at the instance level of its owner, an instance of the :class:`._Dispatch` class is returned. A :class:`._Dispatch` class is generated for each :class:`.Events` class defined, by the :func:`._create_dispatcher_class` function. The original :class:`.Events` classes remain untouched. This decouples the construction of :class:`.Events` subclasses from the implementation used by the event internals, and allows inspecting tools like Sphinx to work in an unsurprising way against the public API. )_parentrr_empty_listenersNcsb||_|_rXy|j|_Wq^tk rTfdd|jD|_|j<Yq^Xni|_dS)Ncsi|]}t||jqSr )rr ).0ls) instance_clsr r Wsz&_Dispatch.__init__..)rr_empty_listener_regrKeyError_event_descriptors)rparentr"r )r"r__init__Ms z_Dispatch.__init__cCsBy|j|}Wntk r*t|YnXt||j||SdS)N)rr%rsetattrr )rr r!r r r __getattr__^s z_Dispatch.__getattr__ccs x|jD]}t||VqWdS)N) _event_namesgetattr)rkr r rr&is z_Dispatch._event_descriptorscCs|jjS)N)_events_listen)rr r rr/psz_Dispatch._listencCs |||S)N) __class__)rr"r r rrtsz_Dispatch._for_classcCs|j}||S)N)r0r)rinstancer"r r r _for_instancewsz_Dispatch._for_instancecCs<d|jjkr0td|jjtfd|ji}||j_|||S)zCreate a 'join' of this :class:`._Dispatch` and another. This new dispatcher will dispatch events to both :class:`._Dispatch` objects. _joined_dispatch_clszJoined%s __slots__)r0rtyper_JoinedDispatcherr+r3)rotherrr r r_join{s   z_Dispatch._joincCst|jffS)N)rr)rr r r __reduce__sz_Dispatch.__reduce__TcCs<x6|jD],}t|trqt||j|j||dqWdS)zMPopulate from the listeners in another :class:`_Dispatch` object.)only_propagateN)r& isinstancerr,r for_modify_update)rr7r:r!r r rr=s   z_Dispatch._updatecCs"x|jD]}||qWdS)N)r&r<clear)rr!r r r_clears z_Dispatch._clear)N)T)rrrrr4weakrefWeakKeyDictionaryr$r(r*propertyr&r/rr2r8r9r=r?r r r rr3s    rc@seZdZdZddZdS) _EventMetazKIntercept new Event subclasses and create associated _Dispatch classes.cCst||||t||||S)N)_create_dispatcher_classr5r()r classnamebasesdict_r r rr(sz_EventMeta.__init__N)rrrrr(r r r rrCsrCc Cst|dr|jj}nt}dd|D}td||fd|i}||_|||}x2|jD](}t||t|||t | |qVWxP|j D]F} t | tr| tk rx.| j jjD] } t|| j| |j | jqWqWt|ddrt||j_dS)zRCreate a :class:`._Dispatch` class corresponding to an :class:`.Events` class.r cSsg|]}t|r|qSr )r)r r-r r r sz,_create_dispatcher_class..z %sDispatchr4_dispatch_targetN)hasattrr r0rr5r+ _set_dispatchr)r _registrarsappend __bases__ issubclassr.r&r r, dispatcherrI) rrErFrGZ dispatch_baseZ event_names dispatch_clsZ dispatch_instr-Zsuper_r!r r rrDs$      rDcCs2x,|jjD] }t||t|s t|=q WdS)N)r r+rLremove)rr-r r r_remove_dispatchersrSc@sNeZdZdZeddZeddZedddZed d Z ed d Z d S)Eventsz>Define event listening functions for a particular target type.cCs|d|_||_|jS)N)r r.)rrQr r rrKs zEvents._set_dispatchcsXfdd}fdd}tdrT||jjsP|t|jjsP|trT||jjrTSdS)Ncstfdd|DS)Nc3s|]}tj|VqdS)N)r;r )r t)targetr r sz;Events._accept_with..dispatch_is..)all)types)rVr r dispatch_issz(Events._accept_with..dispatch_iscstjj|S)N)r;r r')rU)rVr rdispatch_parent_issz/Events._accept_with..dispatch_parent_isr )rJr r0r5r6)rrVrZr[r )rVr _accept_withs     zEvents._accept_withFcCs|j|||ddS)N) propagateinsertnamed)Z base_listen)r event_keyr]r^r_r r rr/szEvents._listencCs |dS)N)rR)rr`r r r_removeszEvents._removecCs|jdS)N)r r?)rr r rr?sz Events._clearN)FFF) rrrr staticmethodrK classmethodr\r/rar?r r r rrTs   rTc@s<eZdZdZdZddZddZeddZed d Z d S) r6z5Represent a connection between two _Dispatch objects.)localr'rcCs||_||_|jj|_dS)N)rdr'r)rrdr'r r rr(sz_JoinedDispatcher.__init__cCs.t|j|}t|j|j|}t||j||S)N)r,rdrr'r r))rr r!Zjlr r rr* s z_JoinedDispatcher.__getattr__cCs|jjS)N)r'r/)rr r rr/sz_JoinedDispatcher._listencCs|jjS)N)r'r.)rr r rr.sz_JoinedDispatcher._eventsN) rrrrr4r(r*rBr/r.r r r rr6s  r6c@s eZdZdZddZddZdS)rPzDescriptor used by target classes to deliver the _Dispatch class at the class level and produce new _Dispatch instances for target instances. cCs|j|_||_dS)N)r events)rrer r rr(#szdispatcher.__init__cCs(|dkr|jS|j||jd<}|S)Nr )r r2r)robjrZdispr r r__get__'szdispatcher.__get__N)rrrrr(rgr r r rrPsrP)rZ __future__rr@attrrrrr defaultdictlistrLrobjectrrr5rCrDrSZwith_metaclassrTr6rPr r r rs       k "0