Qf T2dZddlmZmZmZmZmZmZmZm Z ddl m Z m Z ddl Z ddlZddlZeefZgdZe j$j'e GddeZGdd e j*ZGd d eZGd d e j*ZGddZy)ztWeak reference support for Python. This module is an implementation of PEP 205: https://peps.python.org/pep-0205/ )getweakrefcount getweakrefsrefproxyCallableProxyType ProxyType ReferenceType_remove_dead_weakref)WeakSet_IterationGuardN) rrrrWeakKeyDictionaryr rr ProxyTypesWeakValueDictionaryr WeakMethodfinalizecReZdZdZdZddZfdZdZdZe jZ xZ S)rz A custom `weakref.ref` subclass which simulates a weak reference to a bound method, working around the lifetime problem of bound methods. ) _func_ref _meth_type_alive __weakref__c> |j}|j}fd}t j|||}t |||_t ||_ d|_ t ||S#t$r%tdj t |dwxYw)Nz)argument should be a bound method, not {}cR}|jrd|_ |yyyNF)r)argselfcallbackself_wrs ./opt/alt/python312/lib64/python3.12/weakref.py_cbzWeakMethod.__new__.._cb5s19D{{# 'TN(T) __self____func__AttributeError TypeErrorformattyper__new__rrr)clsmethrobjfuncrrrs ` @rr'zWeakMethod.__new__.s ;--C==D #{{3S)T3t* d) ! ;G#VDJ/16: ; ;s A...Bcnt|}|j}||y|j||SN)super__call__rr)rr*r+ __class__s rr/zWeakMethod.__call__Ds9g ~~ ;$,tS))r ct|trM|jr |js||uStj||xr|j |j k(St Sr-) isinstancerrr__eq__rNotImplementedrothers rr3zWeakMethod.__eq__KsL eZ (;;ellu}$::dE*Pt~~/P Pr ct|trM|jr |js||uStj||xs|j |j k7St Sr-)r2rrr__ne__rr4r5s rr8zWeakMethod.__ne__RsM eZ (;;ell5((::dE*Odnn.O Or r-) __name__ __module__ __qualname____doc__ __slots__r'r/r3r8r__hash__ __classcell__r0s@rrr&s/ CI,*||Hr rceZdZdZddZefdZdZdZdZ dZ dZ d Z d Z e Zd Zdd ZdZdZeZdZdZdZdZddZddZdZdZdZdZy )rzMapping class that references values weakly. Entries in the dictionary will be discarded when no strong reference to the value exists anymore c t|tfd}||_g|_t |_i|_|j|fi|y)Nc|}|P|jr&|jj|jy||j|jyyr-) _iterating_pending_removalsappendkeydata)wrselfref_atomic_removalrs rremovez,WeakValueDictionary.__init__..removeisG9D??**11"&&9$DIIrvv6  r )rr _removerEsetrDrHupdate)rr6kwrLs r__init__zWeakValueDictionary.__init__hsE"4y:N 7 !#%  E R r c|jj}|j} |}|||#t$rYywxYwr-)rEpoprH IndexError)rrKrSdrGs r_commit_removalsz$WeakValueDictionary._commit_removalsysR$$(( II e As #   s6 AAc|jr|j|j|}| t||Sr-rErVrHKeyErrorrrGos r __getitem__zWeakValueDictionary.__getitem__s=  ! !  ! ! # DIIcN  93- Hr cV|jr|j|j|=yr-)rErVrHrrGs r __delitem__zWeakValueDictionary.__delitem__s"  ! !  ! ! # IIcNr cd|jr|jt|jSr-)rErVlenrHrs r__len__zWeakValueDictionary.__len__s%  ! !  ! ! #499~r c|jr|j |j|}|duS#t$rYywxYwrrXrZs r __contains__z WeakValueDictionary.__contains__sN  ! !  ! ! #  # A}  s6 AAcJd|jjt|fzSNz <%s at %#x>r0r9idrbs r__repr__zWeakValueDictionary.__repr__  7 7DBBBr c|jr|jt||j||j|<yr-)rErVKeyedRefrMrHrrGvalues r __setitem__zWeakValueDictionary.__setitem__s1  ! !  ! ! #!%s; #r c|jr|jt}t|5|jj D]\}}|}||||< ddd|S#1swY|SxYwr-)rErVrr rHitems)rnewrGrIr[s rcopyzWeakValueDictionary.copysn  ! !  ! ! #!# T "99??,RD= CH-#  #  s*A/A//A9cddlm}|jr|j|j }t |5|j jD]\}}|}||||||< ddd|S#1swY|SxYwNr)deepcopy)rtrwrErVr0r rHrr)rmemorwrsrGrIr[s r __deepcopy__z WeakValueDictionary.__deepcopy__s}!  ! !  ! ! #nn T "99??,RD=/0Cd+,-#  #  s*B)BB Nc|jr|j |j|}|}||S|S#t$r|cYSwxYwr-rX)rrGdefaultrIr[s rgetzWeakValueDictionary.getsW  ! !  ! ! # 3BAy N s: AAc#K|jr|jt|5|jj D]\}}|}|||f dddy#1swYyxYwwr-rErVr rHrr)rkrIvs rrrzWeakValueDictionary.itemss\  ! !  ! ! # T "*2D=Q$J+# " "s"(A3*A'A' A3'A0,A3c#K|jr|jt|5|jj D]\}}|| dddy#1swYyxYwwr-r~)rrrIs rkeyszWeakValueDictionary.keyssT  ! !  ! ! # T "*24#G+# " "s"(A/(A#A# A/#A,(A/c#K|jr|jt|5|jj Ed{dddy7 #1swYyxYww)aReturn an iterator that yields the weak references to the values. The references are not guaranteed to be 'live' at the time they are used, so the result of calling the references needs to be checked before being used. This can be used to avoid creating references that will cause the garbage collector to keep the values around longer than needed. NrErVr rHvaluesrbs r itervaluerefsz!WeakValueDictionary.itervaluerefssO  ! !  ! ! # T "yy'') ) )# " )# "s.(A$AA A A$AA!A$c#K|jr|jt|5|jj D]}|}| | dddy#1swYyxYwwr-rrrIr*s rrzWeakValueDictionary.valuessV  ! !  ! ! # T "ii&&(d?I)# " "s"(A.'A"A" A."A+'A.c|jr|j |jj\}}|}|||fS+r-)rErVrHpopitem)rrGrIr[s rrzWeakValueDictionary.popitemsJ  ! !  ! ! #ii'')GCA}Av r c|jr|j |jj|}||r|dSt ||S#t$rd}Y#wxYw)Nr)rErVrHrSrY)rrGargsr[s rrSzWeakValueDictionary.popsk  ! !  ! ! # " c"$A 9Awsm#H A s A A"!A"c |j|}|B|jr|jt ||j ||j|<|S|S#t$rd}YSwxYwr-)rHrYrErVrmrM)rrGr{r[s r setdefaultzWeakValueDictionary.setdefaultso  # A 9%%%%'%gt||SADIIcNNH A sA A*)A*c N|jr|j|j}|It|ds t |}|j D]\}}t ||j|||<!|j D]\}}t ||j|||<!yNrr)rErVrHhasattrdictrrrmrM)rr6kwargsrUrGr[s rrOzWeakValueDictionary.update!s  ! !  ! ! # II  5'*U ++-Q!!T\\37#(llnFCas3AcF%r c|jr|jt|jj S)a~Return a list of weak references to the values. The references are not guaranteed to be 'live' at the time they are used, so the result of calling the references needs to be checked before being used. This can be used to avoid creating references that will cause the garbage collector to keep the values around longer than needed. )rErVlistrHrrbs r valuerefszWeakValueDictionary.valuerefs-s1  ! !  ! ! #DII$$&''r c(|j||Sr-rOr5s r__ior__zWeakValueDictionary.__ior__; E r ct|tjr#|j}|j ||St Sr-r2_collections_abcMappingrtrOr4rr6cs r__or__zWeakValueDictionary.__or__?4 e-55 6 A HHUOHr ct|tjr4|j}|j ||j ||St Sr-r2rrr0rOr4rs r__ror__zWeakValueDictionary.__ror__F@ e-55 6 A HHUO HHTNHr )r-)r9r:r;r<rQr rVr\r_rcrerjrprt__copy__ryr|rrr__iter__rrrrSrrOrrrrrr rrr\s!"0D $  C< H  H *   4 (r rc,eZdZdZdZdZfdZxZS)rma[Specialized reference that includes a key corresponding to the value. This is used in the WeakValueDictionary to avoid having to create a function object for each key stored in the mapping. A shared callback object can use the 'key' attribute of a KeyedRef instead of getting a reference to the key from an enclosing scope. rGcBtj|||}||_|Sr-)rr'rG)r&obrrGrs rr'zKeyedRef.__new__[s {{4X. r c&t|||yr-)r.rQ)rrrrGr0s rrQzKeyedRef.__init__`s X&r )r9r:r;r<r=r'rQr?r@s@rrmrmOsI ''r rmceZdZdZddZdZdZdZdZdZ d Z d Z d Z e Z d Zdd ZdZdZdZeZdZdZdZdZddZddZdZdZdZy)r a Mapping class that references keys weakly. Entries in the dictionary will be discarded when there is no longer a strong reference to the key. This can be used to associate additional data with an object owned by other parts of an application without adding attributes to those objects. This can be especially useful with objects that override attribute accesses. Nci|_t|fd}||_g|_t |_d|_||j|yy)Nc|}|7|jr|jj|y |j|=yy#t$rYywxYwr-)rDrErFrHrY)rrJrs rrLz*WeakKeyDictionary.__init__..removeqsS9D??**11!4 IIaL  $s A A AF)rHrrMrErNrD _dirty_lenrO)rrrLs rrQzWeakKeyDictionary.__init__osM !$i  !#%   KK  r c|jj}|j} |} ||= #t$rYywxYw#t$rYwxYwr-)rErSrHrTrY)rrSrUrGs rrVz"WeakKeyDictionary._commit_removalsse $$(( II e cF     s1A == A  A c||j}|jDcgc] }||vs| c}|_d|_ycc}wr)rHrEr)rrUrs r_scrub_removalsz!WeakKeyDictionary._scrub_removalss= II-1-C-C!N-CqAv!-C!N"Os 99c>d|_|jt|=yNT)rrHrr^s rr_zWeakKeyDictionary.__delitem__s IIc#h r c2|jt|Sr-)rHrr^s rr\zWeakKeyDictionary.__getitem__syyS""r c|jr|jr|jt|jt|jz Sr-)rrErrarHrbs rrczWeakKeyDictionary.__len__s= ??t55  "499~D$:$: ;;;r cJd|jjt|fzSrgrhrbs rrjzWeakKeyDictionary.__repr__rkr cJ||jt||j<yr-)rHrrMrns rrpzWeakKeyDictionary.__setitem__s,1 #c4<<()r ct}t|5|jjD]\}}|}||||< ddd|S#1swY|SxYwr-)r r rHrr)rrsrGror[s rrtzWeakKeyDictionary.copysY! T ""iioo/ UE="CF0#  #  s*AAAcddlm}|j}t|5|jj D]\}}|}||||||< ddd|S#1swY|SxYwrv)rtrwr0r rHrr)rrxrwrsrGror[s rryzWeakKeyDictionary.__deepcopy__sg!nn T ""iioo/ UE=%eT2CF0#  #  s*A& A&&A0cL|jjt||Sr-)rHr|rrrGr{s rr|zWeakKeyDictionary.getsyy}}SXg..r cT t|}||jvS#t$rYywxYwr)rr$rH)rrGrIs rrezWeakKeyDictionary.__contains__s4 SBTYY  s  ''c#Kt|5|jjD]\}}|}|||f dddy#1swYyxYwwr-r rHrr)rrIrorGs rrrzWeakKeyDictionary.itemssH T "!YY__. Ed?u*$/# " "s! A*A A  A AAc#Kt|5|jD]}|}| | dddy#1swYyxYwwr-)r rHrs rrzWeakKeyDictionary.keyss8 T "iid?I # " "s A88 AAAc#Kt|5|jjD]\}}|| dddy#1swYyxYwwr-r)rrIros rrzWeakKeyDictionary.valuess? T "!YY__. E4#K/# " "s A(AA AA Ac,t|jS)azReturn a list of weak references to the keys. The references are not guaranteed to be 'live' at the time they are used, so the result of calling the references needs to be checked before being used. This can be used to avoid creating references that will cause the garbage collector to keep the keys around longer than needed. )rrHrbs rkeyrefszWeakKeyDictionary.keyrefssDIIr chd|_ |jj\}}|}|||fS+r)rrHr)rrGror[s rrzWeakKeyDictionary.popitems<**,JCA}%x r c\d|_|jjt|g|Sr)rrHrSr)rrGrs rrSzWeakKeyDictionary.pops'tyy}}SX---r cb|jjt||j|Sr-)rHrrrMrs rrzWeakKeyDictionary.setdefaults$yy##CT\\$:7CCr c |j}|Nt|dsti|}|jD]\}}||t ||j < t |r|j|yyr)rHrr&rrrrMrarO)rrrrUrGros rrOzWeakKeyDictionary.updatesk II  4)tBx~"jjl U,1#c4<<()+ v; KK  r c(|j||Sr-rr5s rrzWeakKeyDictionary.__ior__rr ct|tjr#|j}|j ||St Sr-rrs rrzWeakKeyDictionary.__or__ rr ct|tjr4|j}|j ||j ||St Sr-rrs rrzWeakKeyDictionary.__ror__rr r-)r9r:r;r<rQrVrr_r\rcrjrprtrryr|rerrrrrrrrSrrOrrrrr rr r ds($  #<C2H/%H  .D r r ceZdZdZdZiZdZejZ dZ dZ GddZ dZ ddZd Zd Zed Zed Zej(d ZdZedZedZy)raClass for finalization of weakrefable objects finalize(obj, func, *args, **kwargs) returns a callable finalizer object which will be called when obj is garbage collected. The first time the finalizer is called it evaluates func(*arg, **kwargs) and returns the result. After this the finalizer is dead, and calling it just returns None. When the program exits any remaining finalizers for which the atexit attribute is true will be run in reverse order of creation. By default atexit is true. rFceZdZdZy)finalize._Info)weakrefr+rratexitindexN)r9r:r;r=rr r_Infor5sL r rcZ|js*ddl}|j|jdt_|j }t |||_||_||_ |xsd|_ d|_t|j|_ ||j|<dt_y)NrT)_registered_with_atexitrregister _exitfuncrrrrr+rrnext _index_iterr _registry_dirty)rr*r+rrrinfos rrQzfinalize.__init__8s++  OODNN +/3H ,zz|3~   n  $**+ #tr Nc|jj|d}|r7|js*|j|ji|j xsiSyy)zZIf alive then mark as dead and return func(*args, **kwargs); otherwise return NoneN)rrS _shutdownr+rr)r_rs rr/zfinalize.__call__IsM~~!!$- 499dii?DKK,=2? ?'4r c|jj|}|xr|j}|E|jj|dr(||j|j |j xsifSyy)z^If alive then mark as dead and return (obj, func, args, kwargs); otherwise return NoneN)rr|rrSr+rrrrr*s rdetachzfinalize.detachPsg~~!!$'%t||~ ?t~~11$=DIIt{{/@bA A >?r c|jj|}|xr|j}|(||j|j|j xsifSy)zMIf alive then return (obj, func, args, kwargs); otherwise return NoneN)rr|rr+rrrs rpeekz finalize.peekXsR~~!!$'%t||~ ?DIIt{{/@bA A r c||jvS)zWhether finalizer is alive)rrbs ralivezfinalize.alive`st~~%%r cj|jj|}t|xr |jS)z*Whether finalizer should be called at exitrr|boolr)rrs rrzfinalize.atexites+~~!!$'Dz)dkk)r c`|jj|}|rt||_yyr-r)rrors rrzfinalize.atexitks)~~!!$' u+DK r c,|jj|}|xr|j}|#dt|jt |fzSdt|jt |t|jt |fzS)Nz<%s object at %#x; dead>z!<%s object at %#x; for %r at %#x>)rr|rr&r9rirs rrjzfinalize.__repr__qs~~!!$'%t||~ ;-d1D1Dbh0OO O6d$$bhS 0B0BBsGLM Mr c|jjDcgc]\}}|js||f}}}|jd|Dcgc]\}}| c}}Scc}}wcc}}w)Nc |djS)N)r)items rz+finalize._select_for_exit..~s tAw}}r r)rrrrsort)r(fiLs r_select_for_exitzfinalize._select_for_exitzsf!$ 3 3 5 B 5u!aU 5 B ,- !qeqq!! C!sA$A$ A*cd} |jrrddl}|jrd}|jd} |tj r|j }dt_|sn|j} |Idt_ |rjyy#t$r'tjtjYOwxYw#dt_ |rjwwxYw)NFrT)rgc isenableddisablerrrrS Exceptionsys excepthookexc_inforenable)r( reenable_gcrpendingrs rrzfinalize._exitfuncs   }}<<>"&KJJL(//"%"6"6"8*/" A8 $"&H   %8 78 "&H  s0A5C:B!C!-CCCC C4r-)r9r:r;r<r=rr itertoolscountrrrrrQr/rrpropertyrrsetterrj classmethodrrrr rrrs "III!)//#K F#MM"@BB&&**  ]]&& M""   r r)r<_weakrefrrrrrrr r _weakrefsetr r rrrr__all__ MutableSetrrMutableMappingrrmr rrr rr s1 * +  0 $$W-33lp*99pf's'*u(77upFFr