o znh&@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 @/usr/local/lib/python3.10/dist-packages/sqlalchemy/event/base.py_is_event_namesrc@eZdZdZddZdS)_UnpickleDispatchzSerializable callable that re-generates an instance of :class:`_Dispatch` given a particular :class:`.Events` subclass. cCs4|jD]}d|jvr|jdj|Sqtd)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#s rc@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||_|_r,z |j|_WdSty+fdd|jD|_|j<YdSwi|_dS)Ncsi|] }|jt|qSr )r r).0ls instance_clsr r Ws z&_Dispatch.__init__..)rr_empty_listener_regr KeyError_event_descriptors)rparentr$r r#r__init__Ms    z_Dispatch.__init__cCs8z|j|}Wn tyt|wt||j||SN)r r'rsetattrr )rr r"r r r __getattr__^s z_Dispatch.__getattr__ccs|jD]}t||VqdSr+) _event_namesgetattr)rkr r rr(is z_Dispatch._event_descriptorscC|jjSr+)_events_listenrr r rr3pz_Dispatch._listencCs |||Sr+) __class__)rr$r r rrts z_Dispatch._for_classcCs|j}||Sr+)r6r)rinstancer$r r r _for_instancews z_Dispatch._for_instancecCs<d|jjvrtd|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__)r6rtyper_JoinedDispatcherr.r9)rotherrr r r_join{s   z_Dispatch._joincCst|jffSr+)rrr4r r r __reduce__z_Dispatch.__reduce__TcCs8|jD]}t|tr qt||j|j||dqdS)zMPopulate from the listeners in another :class:`_Dispatch` object.)only_propagateN)r( isinstancerr/r for_modify_update)rr=rAr"r r rrDs  z_Dispatch._updatecCs|jD] }||qdSr+)r(rCclear)rr"r r r_clears z_Dispatch._clearr+)T)rrrrr:weakrefWeakKeyDictionaryr&r*r-propertyr(r3rr8r>r?rDrFr r r rr3s      rc@r) _EventMetazKIntercept new Event subclasses and create associated _Dispatch classes.cCs"t||||t||||dSr+)_create_dispatcher_classr;r*)r classnamebasesdict_r r rr*sz_EventMeta.__init__N)rrrrr*r r r rrJs rJc Cst|dr |jj}nt}dd|D}td||fd|i}||_|||}|jD]}t||t|||t | |q*|j D]!} t | trc| turc| j jjD]} t|| j| |j | jqRqBt|ddrrt||j_dSdS)zRCreate a :class:`._Dispatch` class corresponding to an :class:`.Events` class.r cSsg|]}t|r|qSr )r)r!r0r r r sz,_create_dispatcher_class..z %sDispatchr:_dispatch_targetN)hasattrr r6rr;r. _set_dispatchr,r _registrarsappend __bases__ issubclassr2r(r r/ dispatcherrP) rrLrMrN dispatch_base event_names dispatch_cls dispatch_instr0super_r"r r rrKs*      rKcCs.|jjD]}t||t|st|=qdSr+)r r.rSremove)rr0r r r_remove_dispatchers r^c@sNeZdZdZeddZeddZedddZed d Z ed d Z d S)Eventsz>Define event listening functions for a particular target type.cCs|d|_||_|jSr+)r r2)rrZr r rrRs zEvents._set_dispatchcs`fdd}fdd}tdr*||jjs(|t|jjs(|tr,||jjr.SdSdSdS)Ncstfdd|DS)Nc3s|] }tj|VqdSr+)rBr )r!ttargetr r sz;Events._accept_with..dispatch_is..)all)typesrar r dispatch_issz(Events._accept_with..dispatch_iscstjj|Sr+)rBr r))r`rar rdispatch_parent_isr@z/Events._accept_with..dispatch_parent_isr )rQr r6r;r<)rrbrfrgr rar _accept_withs      zEvents._accept_withFcCs|j|||ddS)N) propagateinsertnamed) base_listen)r event_keyrirjrkr r rr3szEvents._listencCs |dSr+)r])rrmr r r_removes zEvents._removecCs|jdSr+)r rF)rr r rrFsz Events._clearN)FFF) rrrr staticmethodrR classmethodrhr3rnrFr r r rr_s    r_c@s<eZdZdZdZddZddZeddZed d Z d S) r<z5Represent a connection between two _Dispatch objects.localr)rcCs||_||_|jj|_dSr+rq)rrrr)r r rr*sz_JoinedDispatcher.__init__cCs.t|j|}t|j|j|}t||j||Sr+)r/rrrr)r r,)rr r"jlr r rr- s z_JoinedDispatcher.__getattr__cCr1r+)r)r3r4r r rr3r5z_JoinedDispatcher._listencCr1r+)r)r2r4r r rr2r5z_JoinedDispatcher._eventsN) rrrrr:r*r-rIr3r2r r r rr<s r<c@s eZdZdZddZddZdS)rWzDescriptor used by target classes to deliver the _Dispatch class at the class level and produce new _Dispatch instances for target instances. cCs|j|_||_dSr+)r events)rrtr r rr*#s zdispatcher.__init__cCs(|dur|jS|j||jd<}|S)Nr )r r8r)robjrdispr r r__get__'szdispatcher.__get__N)rrrrr*rwr r r rrWs rW)r __future__rrGattrrrrr defaultdictlistrSrobjectrrr;rJrKr^with_metaclassr_r<rWr r r rs"      k "0