L iUTdZddlmZddlZddlmZddlZddlmZddl Z ddl m Z ddl m Z ddl m Z dd l m Z dd l mZdd l mZdd l mZdd l mZddl mZddl mZddl mZddl mZddl mZddl mZddl mZddl mZddl mZddlZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#dd l$m%Z%dd!l&m'Z'ed"e #Z(e jRrdd$l*m+Z+dd%l*m,Z,dd&l*m-Z-Gd'd(e#j\eeZ/Gd)d*e e(Z0ee e(e0e(fZ1Gd+d,e/eZ2Gd-d.e/ee e!Z3Gd/d0e3eZ4Gd1d2e'Z5Gd3d4e3eZ6Gd5d6e6eZ7Gd7d8e6eZ8y)9aAttribute 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. ) annotationsN)chain) TracebackType)Any)cast) Collection)Deque) FrozenSet)Generic)Iterator)MutableMapping)MutableSequence)NoReturn)Optional)Sequence)Set)Tuple)Type)TypeVar)Union)legacy)registry)_ET) _EventKey)_ListenerFnType)exc)util)AsyncAdaptedLock)Protocol_T)bound) _Dispatch)_DispatchCommon)_HasEventsDispatchc$eZdZUdZded<ddZy) RefCollection)refweakref.ref[RefCollection[_ET]]r)cJtj|tjSN)weakrefr)r_collection_gcedselfs [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/event/attr.py_memoized_attr_refz RefCollection._memoized_attr_refPs{{4!:!:;;N)returnr*)__name__ __module__ __qualname__ __slots____annotations__r2r3r1r(r(KsI ((s r1 appendleftz_empty_collection.appendleftXrAr3cyr,r:)r0others r1extendz_empty_collection.extend[rAr3cyr,r:r>s r1removez_empty_collection.remove^rAr3cyNFr:r>s r1 __contains__z_empty_collection.__contains__asr3ctgSr,)iterr/s r1__iter__z_empty_collection.__iter__ds Bxr3cyr,r:r/s r1clearz_empty_collection.cleargrAr3cyNrr:r/s r1__len__z_empty_collection.__len__jsr3N)r?r"r4None)rEz Sequence[_T]r4rT)r?rr4bool)r4z Iterator[_T]r4rTr4int) r5r6r7r@rCrFrHrKrNrPrSr:r3r1r<r<Ts*     r3r<ceZdZUdZdZded<ded<ded<ded <d ed <d ed < ddZ ddZddZ ddZ ddZ ddZ ddZ ddZ d dZd!dZy)"_ClsLevelDispatchz2Class-level events on :class:`._Dispatch` classes.)clsnamename arg_nameshas_kwlegacy_signatures _clslevel __weakref__strr[r\z Sequence[str]r]rUr^z,MutableSequence[legacy._LegacySignatureType]r_zCMutableMapping[Type[_ET], _ListenerFnSequenceType[_ListenerFnType]]r`c |j|_|j|_tj|}|j dd|_t|j|_ tttt|dgd|_tj ||||_t%j&|_y)Nr_legacy_signaturesc |dSrRr:)ss r1z,_ClsLevelDispatch.__init__..s 1r3)key)r5r\r[rinspect_getfullargspecargsr]rUvarkwr^listreversedsortedgetattrr_r_augment_fn_docs__doc__r-WeakKeyDictionaryr`)r0parent_dispatch_clsfnargspecs r1__init__z_ClsLevelDispatch.__init__s KK *33 --b1 ab)7==) !% B 4b9~ " ,,T3FK  224r3c|r|j|}|jr1 tj|d}t j |||}|S|S#t $rY|SwxYw)NT)no_self)_wrap_fn_for_kwr_rget_callable_argspecr_wrap_fn_for_legacy TypeError)r0rtnamedrus r1_adjust_fn_specz!_ClsLevelDispatch._adjust_fn_specsr %%b)B  ! ! C33BE//b'B r    sA A A cdfd }|S)Nctttj|}|j|di|S)Nr:)dictzipr]update)rjkwargdictrtr0s r1wrap_kwz2_ClsLevelDispatch._wrap_fn_for_kw..wrap_kws03t~~t45G NN2 == r3)rjrrrr4rr:)r0rtrs`` r1ryz!_ClsLevelDispatch._wrap_fn_for_kws ! r3c"|j}t|tsJdt|ddst j d|dt j|D]}||ur ||jvr|j|'||jvr|j||r)|j|j|jq|j|j|jtj||y)Nz*Class-level Event targets must be classes._sa_propagate_class_eventsTz&Can't assign an event directly to the z class)dispatch_target isinstancetyperorInvalidRequestErrorrwalk_subclassesr`update_subclassr@ _listen_fnrCr_stored_in_collection)r0 event_key is_appendtargetclss r1_do_insert_or_appendz&_ClsLevelDispatch._do_insert_or_appends** D  8 7 8 v;TB))8G  ''/ IC& S%>$$S)dnn,((-NN3'..y/C/CDNN3'2293G3GH I &&y$7r3c*|j|dy)NFrrr0r propagates r1insertz_ClsLevelDispatch.inserts !!)u!=r3c*|j|dy)NTrrrs r1r@z_ClsLevelDispatch.appends !!)t!>&)>>!"% Cdnn$"&.."5LB89KRL Ms ! B9 +B9 c|j}tj|D]9}||jvs|j|j |j ;t j||yr,)rrrr`rHrr_removed_from_collection)r0rrrs r1rHz_ClsLevelDispatch.removesd**''/ ACdnn$s#**9+?+?@ A )))T:r3ct}|jjD]#}|j||j %t j ||y)zClear all class level listenersN)setr`valuesrrPr_clear)r0to_clear dispatchers r1rPz_ClsLevelDispatch.clearsO*-..//1 J OOJ '      h'r3c|SzReturn an event collection which can be modified. For _ClsLevelDispatch at the class level of a dispatcher, this returns self. r:r0objs r1 for_modifyz_ClsLevelDispatch.for_modifys  r3N)rszType[_HasEventsDispatch[_ET]]rtrrtrr}rUr4r)rtrr4r)r_EventKey[_ET]rrUr4rTrrrrUr4rT)r Type[_ET]r4rTrrr4rTrV)r_Dispatch[_ET]r4_ClsLevelDispatch[_ET])r5r6r7rqr8r9rvr~ryrrr@rrHrPrr:r3r1rZrZqs<IL I LCC5:5 5* ! *.   8'8488 84>= ;(r3rZceZdZUdZded< ddZddZddZddZddZ dd Z dd Z dd Z dd Z dd ZddZddZ ddZy)_InstanceLevelDispatchr:rparentc:|jj||Sr,)rr~r0rtr}s r1r~z&_InstanceLevelDispatch._adjust_fn_specs{{**2u55r3ctr,NotImplementedErrorr0items r1rKz#_InstanceLevelDispatch.__contains__ !##r3ctr,rr/s r1rSz_InstanceLevelDispatch.__len__ rr3ctr,rr/s r1rNz_InstanceLevelDispatch.__iter__ rr3ctr,rr/s r1__bool__z_InstanceLevelDispatch.__bool__rr3ctr,rr0rjrs r1 exec_oncez _InstanceLevelDispatch.exec_oncerr3ctr,rrs r1exec_once_unless_exceptionz1_InstanceLevelDispatch.exec_once_unless_exceptionrr3ctr,rrs r1_exec_w_sync_on_first_runz0_InstanceLevelDispatch._exec_w_sync_on_first_runrr3ctr,rrs r1__call__z_InstanceLevelDispatch.__call__rr3ctr,rrs r1rz_InstanceLevelDispatch.insertrr3ctr,rrs r1r@z_InstanceLevelDispatch.append!rr3ctr,rr0rs r1rHz_InstanceLevelDispatch.remove$rr3c|Srr:rs r1rz!_InstanceLevelDispatch.for_modify'  r3Nrrrr4rUrWr4zIterator[_ListenerFnType]r4rUrjrrrr4rTrr)r_DispatchCommon[_ET]r4_InstanceLevelDispatch[_ET])r5r6r7r8r9r~rKrSrNrrrrrrr@rHrr:r3r1rrsvI ""6!6*.6 6 $$$$$$$$$$$ '  $ r3rceZdZUdZdZeZded<dZded<ded <d ed <d ed <ddZ ddZ ddZ ddZ ddZ ddZddZddZddZd dZd!dZd"dZd#dZd$dZy)%_EmptyListenerzServes as a proxy interface to the events served by a _ClsLevelDispatch, when there are no instance-level events present. Is replaced by _ListenerCollection when instance-level events are added. )rparent_listenersr\zFrozenSet[_ListenerFnType]rr:z Tuple[()] listenersrrz(_ListenerFnSequenceType[_ListenerFnType]rrbr\c||jvr|j|||_|j||_|j|_yr,)r`rrrr\)r0r target_clss r1rvz_EmptyListener.__init__EsC V-- -  " ": . & 0 0 <KK r3ctd|}|jJt||j}tj 5||ust |tr!t|j|j}nt |tsJ|cdddS||urt||j|ddd|S#1swYSxYw)zReturn an event collection which can be modified. For _EmptyListener at the instance level of a dispatcher, this generates a new _ListenerCollection, applies it to the instance, and returns it. rN) r _instance_clsror\rmini_gilr_JoinedListener_ListenerCollectionrsetattr)r0rexistingresults r1rz_EmptyListener.for_modifyLs#S)  ,,,3 * ]] 04:h#H,T[[#:K:KL "(,?@@@ 0 04TYY/ 0  0 sA B9B99Cctd)Nzneed to call for_modify()rrs r1 _needs_modifyz_EmptyListener._needs_modifyjs!"=>>r3c(|j|i|yr,rrs r1rz_EmptyListener.exec_oncemD'B'r3c(|j|i|yr,rrs r1rz)_EmptyListener.exec_once_unless_exceptionprr3c(|j|i|yr,rrs r1rz_EmptyListener.insertsrr3c(|j|i|yr,rrs r1r@z_EmptyListener.appendvrr3c(|j|i|yr,rrs r1rHz_EmptyListener.removeyrr3c(|j|i|yr,rrs r1rPz_EmptyListener.clear|rr3c6|jD] }||i| yzExecute this event.Nrr0rjrrts r1rz_EmptyListener.__call__s$'' B OO r3c||jvSr,rrs r1rKz_EmptyListener.__contains__st,,,,r3c,t|jSr,)lenrr/s r1rSz_EmptyListener.__len__s4(())r3c,t|jSr,)rMrr/s r1rNz_EmptyListener.__iter__D))**r3c,t|jSr,)rUrr/s r1rz_EmptyListener.__bool__rr3Nrrrrrrr4_ListenerCollection[_ET])rjrrrr4rrrrWrr)r5r6r7rqr8 frozensetrr9rrvrrrrrr@rHrPrrKrSrNrr:r3r1rr3s5I,5KI)7Iy "">> I ' !<?(((((( -*++r3rc,eZdZddZ ddZy)_MutexProtocolcyr,r:r/s r1 __enter__z_MutexProtocol.__enter__sr3cyr,r:)r0exc_typeexc_valexc_tbs r1__exit__z_MutexProtocol.__exit__s r3Nr)rzOptional[Type[BaseException]]rzOptional[BaseException]rzOptional[TracebackType]r4zOptional[bool])r5r6r7rrr:r3r1rrs0$/)(   r3rceZdZUdZded<ded<ded<ded<ded <dfd Zdd Zdd Z dd ZddZ ddZ ddZ ddZ ddZ ddZddZddZxZS)_CompoundListener)_exec_once_mutex _exec_once_exec_w_sync_once _is_asynciozOptional[_MutexProtocol]r Collection[_ListenerFnType]rrrUr r c2t||i|d|_yrJ)superrvr)r0argr __class__s r1rvz_CompoundListener.__init__s #$$ r3cd|_y)NT)rr/s r1 _set_asyncioz_CompoundListener._set_asyncios r3ctj5|j|jcdddS|jr t }nt j }||_|cdddS#1swYyxYwr,)rrr rr threadingLock)r0mutexs r1_get_exec_once_mutexz&_CompoundListener._get_exec_once_mutexsg ]] $$0,,  (*!($)D !   sA03A00A9c|j5|js ||i|d} |r|sd|_ dddy#d}xYw#r|sd|_wwxYw#1swYyxYw)NFT)rr )r0retry_on_exceptionrjr exceptions r1_exec_once_implz!_CompoundListener._exec_once_implsy & & ( /??/$%"% %I %,>*. / /  $I$,>*.-? / /s+ A ? AAAAAA!cJ|js|jdg|i|yy)z]Execute this event, but only if it has not been executed already for this collection.FNr rrs r1rz_CompoundListener.exec_onces* D  4 4 4r3cJ|js|jdg|i|yy)atExecute this event, but only if it has not been executed already for this collection, or was called by a previous exec_once_unless_exception call and raised an exception. If exec_once was already called, then this method will never run the callable regardless of whether it raised or not. .. versionadded:: 1.3.8 TNr rs r1rz,_CompoundListener.exec_once_unless_exceptions* D  3 3 3r3c|js+|j5 ||i|d|_ dddy||i|y#xYw#1swYyxYw)aExecute this event, and use a mutex if it has not been executed already for this collection, or was called by a previous _exec_w_sync_on_first_run call and raised an exception. If _exec_w_sync_on_first_run was already called and didn't raise an exception, then a mutex is not used. It's not guaranteed the mutex won't be used more than once in the case of very rare race conditions. .. versionadded:: 1.4.11 TN)r rrs r1rz+_CompoundListener._exec_w_sync_on_first_runsh%%**, 22$%"%.2D*  2 2 $ "    2 2s!AAAAAAch|jD] }||i| |jD] }||i| yrrrrs r1rz_CompoundListener.__call__sB'' B OO .. B OO r3c>||jvxs||jvSr,r$rs r1rKz_CompoundListener.__contains__s!t,,,F0FFr3cXt|jt|jzSr,)rrrr/s r1rSz_CompoundListener.__len__s!4(()C,???r3cBt|j|jSr,)rrrr/s r1rNz_CompoundListener.__iter__ sT**DNN;;r3cHt|jxs |jSr,)rUrrr/s r1rz_CompoundListener.__bool__sDNN;d&;&;<> :""9#7#78 ;r3c|j||jr)|r&|jj|jyyyr,)append_to_listrrr:rrs r1r@z_ListenerCollection.append`s;  # #D$.. 9""9#7#78 :r3c|jj|j|jj |jt j ||yr,)rrHrrdiscardrrrs r1rHz_ListenerCollection.removeesB i223 y334)))T:r3ctj||j|jj |jj yr,)rrrrrPr/s r1rPz_ListenerCollection.clearjs4dnn-  r3rr)T)rErr1rUr4rTrrrV)r5r6r7rqr8r9rvrr7rr@rHrPr)r*s@r1rrsI21 "" I%%##  '  ! GKH-H?CH H09 9 ; r3rceZdZUdZded<ded<ded<ded < dd Zejs edd Z dd Z dd Z ddZ ddZ ddZddZy)r)parent_dispatchr\localrrrArbr\rrBrrczd|_d|_d|_||_||_||_|j |_yrJ)r r r rAr\rBr)r0rAr\rBs r1rvz_JoinedListener.__init__xs=  !& $.  $ r3cBt|j|jSr,)rorAr\r/s r1rz_JoinedListener.listenerss4//; ;r3c:|jj||Sr,)rBr~rs r1r~z_JoinedListener._adjust_fn_specszz))"e44r3cT|jj|x|_|_|Sr,)rBrrrs r1rz_JoinedListener.for_modifys%-1ZZ-B-B3-GG T* r3c<|jj||yr,)rBrrs r1rz_JoinedListener.insert )Y/r3c<|jj||yr,)rBr@rs r1r@z_JoinedListener.appendrHr3c:|jj|yr,)rBrHrs r1rHz_JoinedListener.removes )$r3ctr,rr/s r1rPz_JoinedListener.clearrr3N)rArr\rbrBz_EmptyListener[_ET])r4rr)rrr4z_JoinedListener[_ET]rrrV)r5r6r7r8r9rvtyping TYPE_CHECKINGpropertyrr~rrr@rHrPr:r3r1rrpsFI)) I &&11 +- + +# +     <  <5!5*.5 5 00%$r3r)9rq __future__rr itertoolsrrtypesrrLrrrr r r r r rrrrrrrrrr-rrrrrrrutil.concurrencyr util.typingr!r"rMbaser$r%r& MemoizedSlotsr(r<_ListenerFnSequenceTyperZrrrr rrr:r3r1rXs[.# !"%/" T %(