U kf;@sUdZddlmZddlZddlmZddlmZddlmZddlmZddlmZdd lm Z dd lm Z dd lm Z dd lm Z dd lm Z ddlmZddlmZddlmZddlZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZeeZ de!d<dddd d!Z"Gd"d#d#Z#Gd$d%d%eeZ$Gd&d'd'e$eZ%d(d)d*d+d,Z&Gd-d.d.eeZ'Gd/d0d0e$eZ(Gd1d2d2e'eZ)Gd3d4d4eeZ*Gd5d6d6e*eZ+dS)7aBase 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``. ) annotationsN)Any)cast)Dict)Generic)Iterator)List)Mapping)MutableMapping)Optional)overload)Tuple)Type)Union)_ClsLevelDispatch)_EmptyListener)_InstanceLevelDispatch)_JoinedListener)_ET) _EventKey)util)Literalz8MutableMapping[str, List[Type[_HasEventsDispatch[Any]]]] _registrarsstrboolnamereturncCs|d r|dkp|dS)N_dispatchZ _sa_event) startswith)rr#E/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/event/base.py_is_event_name2sr%c@s eZdZdZdddddZdS)_UnpickleDispatchzSerializable callable that re-generates an instance of :class:`_Dispatch` given a particular :class:`.Events` subclass. Type[_ET]_Dispatch[_ET]) _instance_clsrcCs>|jD]*}d|jkrtd|jdj|SqtddS)Nr!r(z*No class with a 'dispatch' member present.)__mro____dict__rr! _for_classAttributeError)selfr)clsr#r#r$__call__Bs    z_UnpickleDispatch.__call__N)__name__ __module__ __qualname____doc__r0r#r#r#r$r&<sr&c@sLeZdZUdZded<dddddZd d d d d ZeddddZdS)_DispatchCommonr#Optional[Type[_ET]]r)_DispatchCommon[_ET]_JoinedDispatcher[_ET]otherrcCs tdSNNotImplementedErrorr.r:r#r#r$_joinQsz_DispatchCommon._joinr_InstanceLevelDispatch[_ET]rcCs tdSr;r<r.rr#r#r$ __getattr__Tsz_DispatchCommon.__getattr__Type[_HasEventsDispatch[_ET]]rcCs tdSr;r<r.r#r#r$_eventsWsz_DispatchCommon._eventsN) r1r2r3 __slots____annotations__r?rBpropertyrFr#r#r#r$r5Ls r5c@seZdZUdZdZded<eZded<ded<d ed <d ed <d ed<ded<d _DispatchaMMirror 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 :meth:`._HasEventsDispatch._create_dispatcher_class` method. 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. )_parentr)r+_empty_listenersrZ_active_historyz9MutableMapping[Type[_ET], Dict[str, _EmptyListener[_ET]]]_empty_listener_regzDict[str, _EmptyListener[_ET]]rLz List[str] _event_namesr6r)zType[_JoinedDispatcher[_ET]]_joined_dispatch_clsrCrFNzOptional[_Dispatch[_ET]])parent instance_clscsn||_|_rd|dk stz|j|_Wqjtk r`fdd|jD|_|j<YqjXni|_dS)Ncsi|]}|jt|qSr#)rr).0lsrQr#r$ sz&_Dispatch.__init__..)rKr)AssertionErrorrMrLKeyError_event_descriptors)r.rPrQr#rTr$__init__s    z_Dispatch.__init__rr@rcCsBz|j|}Wntk r*t|YnXt||j||SdSr;)rLrWr-setattrr)r.rrSr#r#r$rBs z_Dispatch.__getattr__z Iterator[_ClsLevelDispatch[_ET]]rDccs|jD]}t||VqdSr;)rNgetattr)r.kr#r#r$rXs z_Dispatch._event_descriptors_EventKey[_ET]rNone event_keykwrcKs|jj|f|Sr;)rF_listenr.r`rar#r#r$rbsz_Dispatch._listenr'r()rQrcCs |||Sr;) __class__)r.rQr#r#r$r,sz_Dispatch._for_classr)instancercCs|j}||Sr;)rdr,)r.rerQr#r#r$ _for_instancesz_Dispatch._for_instancer7r8r9cCsd|jjkst|||S)zCreate a 'join' of this :class:`._Dispatch` and another. This new dispatcher will dispatch events to both :class:`._Dispatch` objects. rO)rdr+rVrOr>r#r#r$r?sz_Dispatch._joinzUnion[str, Tuple[Any, ...]]cCst|jffSr;)r&r)rEr#r#r$ __reduce__sz_Dispatch.__reduce__T)r:only_propagatercCs8|jD],}t|trqt||j|j||dqdS)zIPopulate from the listeners in another :class:`_Dispatch` object.)rhN)rX isinstancerr[r for_modify_update)r.r:rhrSr#r#r$rks  z_Dispatch._updatecCs|jD]}||qdSr;)rXrjclear)r.rSr#r#r$_clears z_Dispatch._clear)N)T)r1r2r3r4rGrHweakrefWeakKeyDictionaryrMrYrBrIrXrbr,rfr?rgrkrmr#r#r#r$rJ\s.      rJrCr^)r/rcCs.|jjD] }t||t|st|=qdSr;)r!rNrremove)r/r\r#r#r$_remove_dispatchers rqc @seZdZUded<ded<ejr0ddddd Zd d d d ZeddddddZ eddddddddddd dddZ e ddddddZ eddd d d!d"d#Z d$S)%_HasEventsDispatchr6_dispatch_targetr(r!rr@rcCsdSr;r#rAr#r#r$rBz_HasEventsDispatch.__getattr__r^rDcCs||j|j|jdS)zOIntercept new Event subclasses and create associated _Dispatch classes.N)_create_dispatcher_classr1 __bases__r+r/r#r#r$__init_subclass__sz$_HasEventsDispatch.__init_subclass__Union[_ET, Type[_ET]]Optional[Union[_ET, Type[_ET]]]target identifierrcCs tdSr;r<)r/r|r}r#r#r$ _accept_withsz_HasEventsDispatch._accept_withF propagateinsertnamedasyncior]rr`rrrrrcCs tdSr;r<r/r`rrrrr#r#r$rbs z_HasEventsDispatch._listenrCType[_Dispatch[_ET]])klass dispatch_clsrcCs|d|_||_|jSr;)r!rF)rrr#r#r$ _set_dispatchs z _HasEventsDispatch._set_dispatchzTuple[type, ...]zMapping[str, Any]) classnamebasesdict_rc CsJt|dr|jj}nt}dd|D}tdtd||fd|i}||_|||}|jD](}t||t |||t | |qZ|j D]B} t | tr| tk r| jjjD] } t|| j| |j | jqqt|ddr|j} | dk stt| drd | jkrt|| _n t|| _td |jtfd|i} | |_| t| j<dS) zVCreate a :class:`._Dispatch` class corresponding to an :class:`.Events` class.r!cSsg|]}t|r|qSr#)r%)rRr\r#r#r$ %sz?_HasEventsDispatch._create_dispatcher_class..rz %sDispatchrGrsN_slots_dispatchzJoined%s)hasattrr!rdrJrtyperNrrZrrappendrv issubclassrFrXrr[rsrVrGslots_dispatcher dispatcherr1_JoinedDispatcherrOglobals) r/rrrZ dispatch_baseZ event_namesrZ dispatch_instr\Zsuper_rSZdispatch_target_clsrr#r#r$rusL         z+_HasEventsDispatch._create_dispatcher_classN)r1r2r3rHtyping TYPE_CHECKINGrBrx classmethodr~rb staticmethodrrur#r#r#r$rrs"   rrc@seZdZUdZdZded<ded<ded<dddd d Zd d d dZdddddZdd ddddZ e dd ddZ dS)rz5Represent a connection between two _Dispatch objects.localrPr)r7rrPr6r))rrPcCs||_||_|jj|_dSr;r)r.rrPr#r#r$rYZsz_JoinedDispatcher.__init__rrDcCs|j|j|jffSr;)rdrrPrEr#r#r$rgasz_JoinedDispatcher.__reduce__rz_JoinedListener[_ET]rcCs.t|j|}t|j|j|}t||j||Sr;)r[rrrPrrZ)r.rrSjlr#r#r$rBds z_JoinedDispatcher.__getattr__r]r^r_cKs|jj|f|Sr;)rPrbrcr#r#r$rblsz_JoinedDispatcher._listenrCcCs|jjSr;)rPrFrEr#r#r$rFosz_JoinedDispatcher._eventsN) r1r2r3r4rGrHrYrgrBrbrIrFr#r#r#r$rQs rc @steZdZdZeddddddZeddddd d d d d d d d ddZed d dddZed dddZdS)Eventsz>Define event listening functions for a particular target type.ryrrzr{cshdddfdd }dddfdd }td rd||jjs`|t|jjs`|trd||jjrdSdS) N Type[Any]r)typesrcstfdd|DS)Nc3s|]}tj|VqdSr;)rir!)rRtr|r#r$ |sz;Events._accept_with..dispatch_is..)all)rrr#r$ dispatch_is{sz(Events._accept_with..dispatch_is)rrcsttdjj|S)Nr8)rirr!rP)rrr#r$dispatch_parent_is~s z/Events._accept_with..dispatch_parent_isr!)rr!rdrr)r/r|r}rrr#rr$r~ws    zEvents._accept_withFrr]rr^rcCs|j||||ddS)Nr)Z base_listenrr#r#r$rbs zEvents._listen)r`rcCs |dSr;)rp)r/r`r#r#r$_removeszEvents._removerDcCs|jdSr;)r!rmrwr#r#r$rmsz Events._clearN) r1r2r3r4rr~rbrrmr#r#r#r$rts rc@s\eZdZdZddddZedddd d d Zed dd d dd Zd dd d dd ZdS)rzDescriptor used by target classes to deliver the _Dispatch class at the class level and produce new _Dispatch instances for target instances. rC)eventscCs|j|_||_dSr;)r!r)r.rr#r#r$rYszdispatcher.__init__z Literal[None]rrobjr/rcCsdSr;r#r.rr/r#r#r$__get__szdispatcher.__get__rr7cCsdSr;r#rr#r#r$rsc Cs`|dkr|jS|j|}z||jd<Wn2tk rZ}ztd|f|W5d}~XYnX|S)Nr!zGtarget %r doesn't have __dict__, should it be defining _slots_dispatch?)r!rfr+r- TypeError)r.rr/dispZaer#r#r$rs N)r1r2r3r4rYr rr#r#r#r$rsrc@seZdZddddddZdS)rrrrcCs4|dkr|jSt|dr|jS|j|}||_|S)Nr)r!rrrf)r.rr/rr#r#r$rs  zslots_dispatcher.__get__N)r1r2r3rr#r#r#r$rsr),r4 __future__rrrrrrrrr r r r r rrrnattrrrrrregistryrrrZ util.typingr defaultdictlistrrHr%r&r5rJrqrrrrrrr#r#r#r$sH                        ~p#5#