(uSm UMddZddlmZddlmZddlZddlmZddlZddlm Z ddlm Z d d lm Z d d lm Z d d l m Z Gd de jZGddeZGddeZGddeZGddeZGddeZGddeZGddeZdS)aAttribute 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. )absolute_import)with_statementN)chain)legacy)registry)exc)util) threadingceZdZdZdZdS) RefCollection)refc@tj|tjSN)weakrefrr_collection_gcedselfs /srv/buildsys-work-dir/castor/build_node/builder-2/WGSG1/unpkd_srcs/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/sqlalchemy/event/attr.py_memoized_attr_refz RefCollection._memoized_attr_ref1s{4!:;;;N)__name__ __module__ __qualname__ __slots__rrrrr.s(I<<<<z,_ClsLevelDispatch.__init__..Zs 1r)key)rr1r inspect_getfullargspecargsr2boolvarkwr3listreversedsortedgetattrr4r_augment_fn_docs__doc__rWeakKeyDictionaryr5)rparent_dispatch_clsfnargspecs r__init__z_ClsLevelDispatch.__init__RsK -b11 abb)7=)) !% B 4b99~~  " " ,T3FKK  244rc|r||}|jr> tj|d}t j|||}n#t $rYnwxYw|S)NT)no_self)_wrap_fn_for_kwr4r get_callable_argspecr_wrap_fn_for_legacy TypeError)rrJnamedrKs r_adjust_fn_specz!_ClsLevelDispatch._adjust_fn_specbs  *%%b))B  ! C C3BEEE/b'BB     sA AAcfd}|S)Ncttj|}||di|S)Nr)dictzipr2update)r?kwargdictrJrs rwrap_kwz2_ClsLevelDispatch._wrap_fn_for_kw..wrap_kwos@3t~t4455G NN2   2==== rr)rrJr\s`` rrOz!_ClsLevelDispatch._wrap_fn_for_kwns) ! ! ! ! ! ! rc|j}t|ts Jdt|ddst jd|z|g}|r|d}||||ur||j vr| |nC||j vr| ||j | |j |tj||dSNz*Class-level Event targets must be classes._sa_propagate_class_eventsTz.Can't assign an event directly to the %s classr)dispatch_target isinstancetyperEr InvalidRequestErrorpopr'__subclasses__r5update_subclass_assign_cls_collection appendleft _listen_fnr_stored_in_collectionr event_key propagatetargetstackclss rinsertz_ClsLevelDispatch.insertvs>* D   8 8 7 8 8 v;TBB )@6I  E))A,,C LL++-- . . .&  S%>%>$$S))))dn,,//444s#..y/CDDD E &y$77777rc|j}t|ts Jdt|ddst jd|z|g}|r|d}||||ur||j vr| |nC||j vr| ||j | |j |tj||dSr^)r`rarbrEr rcrdr'rer5rfrgr#rirrjrks rr#z_ClsLevelDispatch.appends>* D   8 8 7 8 8 v;TBB )@6I  A))A,,C LL++-- . . .&  S%>%>$$S))))dn,,//444s#**9+?@@@ A &y$77777rct|ddrtj|j|<dSt |j|<dS)Nr_T)rE collectionsdequer5r)rrns rrgz(_ClsLevelDispatch._assign_cls_collectionsJ 67 > > 9%0%6%8%8DN6 " " "%6%8%8DN6 " " "rc||jvr|||j||jddD]7}||jvr,fd|j|D8dS)Nrcg|]}|v| Srr).0rJclslevels r z5_ClsLevelDispatch.update_subclass..s#LLLB89K9KR9K9K9Kr)r5rg__mro__r')rrnrprys @rrfz!_ClsLevelDispatch.update_subclasss  ' '  ' ' / / />&)>!""%  Cdn$$LLLL$."5LLL  rc |j}|g}|rl|d}||||jvr%|j||j|ltj||dSr:) r`rdr'rer5r)rir_removed_from_collection)rrlrnrorps rr)z_ClsLevelDispatch.removes* A))A,,C LL++-- . . .dn$$s#**9+?@@@  A ))T:::::rct}|jD]+}|||,t j||dS)zClear all class level listenersN)setr5valuesrYr.r_clear)rto_clear dispatchers rr.z_ClsLevelDispatch.clearsi55.//11  J OOJ ' ' '       h'''''rc|S)zReturn an event collection which can be modified. For _ClsLevelDispatch at the class level of a dispatcher, this returns self. rrobjs r for_modifyz_ClsLevelDispatch.for_modify  rN)rrrrGrrLrTrOrqr#rgrfr)r.rrrrr0r0Fs<<I555   888*888*999 ;;;(((rr0ceZdZdZdZdS)_InstanceLevelDispatchrc8|j||Sr)parentrTrrJrSs rrTz&_InstanceLevelDispatch._adjust_fn_specs{**2u555rN)rrrrrTrrrrrs(I66666rrcteZdZdZeZdZdZdZdZ dZ e xZ xZ xZ xZxZZdZdZd Zd ZeZd S) _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. r)rparent_listenersr1c||jvr||||_|j||_|j|_dSr)r5rfrrr1rr target_clss rrLz_EmptyListener.__init__sH V- - -  " ": . . . & 0 <K rct|j|j}t||j|urt ||j|n*t t||jtsJ|S)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. )_ListenerCollectionr _instance_clsrEr1setattrra_JoinedListener)rrresults rrz_EmptyListener.for_modifysm%T[#2CDD 3 " "d * * CF + + + +gc4955GG G GG rc td)Nzneed to call for_modify()NotImplementedErrorrr?rZs r _needs_modifyz_EmptyListener._needs_modifys!"=>>>rc*|jD] }||i| dSzExecute this event.N)rrr?rZrJs r__call__z_EmptyListener.__call__s3'  B BOOOOO  rc*t|jSr)lenrrs r__len__z_EmptyListener.__len__s4()))rc*t|jSr)r+rrs rr,z_EmptyListener.__iter__ D)***rc*t|jSr)r@rrs r__bool__z_EmptyListener.__bool__ rrN)rrrrG frozensetrm listenersrrLrr exec_onceexec_once_unless_exceptionrqr#r)r.rrr,r __nonzero__rrrrrs II4I    ??? ,99I9"999 5 ***++++++KKKrrcFeZdZdZdZdZdZdZdZdZ dZ d Z e Z d S) _CompoundListener_exec_once_mutex _exec_oncec(tjSr)r Lockrs r_memoized_attr__exec_once_mutexz1_CompoundListener._memoized_attr__exec_once_mutexs~rc|j5|js1 ||i|d}n#d}xYw |r|sd|_n#|r|sd|_wxYwddddS#1swxYwYdS)NFTr)rretry_on_exceptionr?rZ exceptions r_exec_once_implz!_CompoundListener._exec_once_impls  " / /? //D$%"%%% %II $I %/,>/*.%/,>/*..... / / / / / / / / / / / / / / / / / /s/A 1!1 A >AAAc:|js|jdg|Ri|dSdS)z]Execute this event, but only if it has not been executed already for this collection.FNrrrs rrz_CompoundListener.exec_once&sA 5 D  4 4 4 4 4 4 4 4 4 5 5rc:|js|jdg|Ri|dSdS)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 TNrrs rrz,_CompoundListener.exec_once_unless_exception-sA 4 D  3 3 3 3 3 3 3 3 3 4 4rcN|jD] }||i| |jD] }||i| dSr)rrrs rrz_CompoundListener.__call__<sW'  B BOOOOO.  B BOOOOO  rcTt|jt|jzSr)rrrrs rrz_CompoundListener.__len__Ds"4())C,?,???rc6t|j|jSr)rrrrs rr,z_CompoundListener.__iter__GsT*DN;;;rc8t|jp|jSr)r@rrrs rrz_CompoundListener.__bool__JsDN;d&;<<.}sF   ---".DN"" #""rN)rrrmrYr'unionr_stored_in_collection_multi)rr&rexisting_listenersother_listeners to_associaters` ` @r_updatez_ListenerCollection._updatevs"^ #$6 7 7 eo...      _    !!/222,,_== ,T5,GGGGGrc|||jr#|r#|j|jdSdSdSr)prepend_to_listrrmaddrirrlrms rrqz_ListenerCollection.insertsW  $ $T4> : : 9 9""9#788888 9 9 9 9rc|||jr#|r#|j|jdSdSdSr)append_to_listrrmrrirs rr#z_ListenerCollection.appendsW  # #D$. 9 9 9 9""9#788888 9 9 9 9rc|j|j|j|jt j||dSr)rr)rirmdiscardrr}rrls rr)z_ListenerCollection.removesM i2333 y3444))T:::::rctj||j|j|jdSr)rrrrmr.rs rr.z_ListenerCollection.clearsDdn---  rN)T) rrrrGrrLrrrqr#r)r.rrrrrPsIHHHH(999 999 ;;; rrcReZdZdZdZedZdZdZdZ dZ dZ d Z d S) r)rr1localrcVd|_||_||_||_|j|_dSr)rrr1rr)rrr1rs rrLz_JoinedListener.__init__s.   $ rc6t|j|jSr)rErr1rs rrz_JoinedListener.listenersst{DI...rc8|j||Sr)rrTrs rrTz_JoinedListener._adjust_fn_specsz))"e444rcR|j|x|_|_|Sr)rrrrs rrz_JoinedListener.for_modifys&-1Z-B-B3-G-GG T* rc<|j||dSr)rrqrs rrqz_JoinedListener.insert  )Y/////rc<|j||dSr)rr#rs rr#z_JoinedListener.appendrrc:|j|dSr)rr)rs rr)z_JoinedListener.removes )$$$$$rctrrrs rr.z_JoinedListener.clears!###rN) rrrrrLpropertyrrTrrqr#r)r.rrrrrs=I+++//X/555000000%%%$$$$$rr)rG __future__rrrt itertoolsrrrrr r r MemoizedSlotsrobjectrr0rrrrrrrrrs+0'&&&&&%%%%%%<<<<