grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026B i�ržè¹çã @sÐdZddlmZmZmZmZmZmZmZm Z ddl m Z m Z ddl Z ddlZddlZeefZddddd d d d d ddddg ZGdd„deƒZGdd„de jƒZGdd„deƒZGdd „d e jƒZGdd„dƒZdS)z{Weak reference support for Python. This module is an implementation of PEP 205: http://www.python.org/dev/peps/pep-0205/ é)ÚgetweakrefcountÚ getweakrefsÚrefÚproxyÚCallableProxyTypeÚ ProxyTypeÚ ReferenceTypeÚ_remove_dead_weakref)ÚWeakSetÚ_IterationGuardNrrrrÚWeakKeyDictionaryrrrÚ ProxyTypesÚWeakValueDictionaryr Ú WeakMethodÚfinalizecsDeZdZdZdZd dd„Z‡fdd„Zdd „Zd d „Ze j Z ‡Z 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__Ncs~y|j}|j}Wn(tk r8td t|ƒ¡ƒd‚YnX‡‡fdd„}t |||¡}t||ƒ|_t|ƒ|_ d|_ t|ƒ‰|S)Nz)argument should be a bound method, not {}cs&ˆƒ}|jr"d|_ˆdk r"ˆ|ƒdS)NF)r)ÚargÚself)ÚcallbackÚself_wr©ú,/opt/alt/python37/lib64/python3.7/weakref.pyÚ_cb3s zWeakMethod.__new__.._cbT) Ú__self__Ú__func__ÚAttributeErrorÚ TypeErrorÚformatÚtyperÚ__new__rrr)ÚclsZmethrÚobjÚfuncrrr)rrrr",s   zWeakMethod.__new__cs2tƒ ¡}| ¡}|dks"|dkr&dS| ||¡S)N)ÚsuperÚ__call__rr)rr$r%)Ú __class__rrr'Bs  zWeakMethod.__call__cCs:t|tƒr6|jr|js||kSt ||¡o4|j|jkSdS)NF)Ú isinstancerrrÚ__eq__r)rÚotherrrrr*Is   zWeakMethod.__eq__cCs:t|tƒr6|jr|js||k St ||¡p4|j|jkSdS)NT)r)rrrÚ__ne__r)rr+rrrr,Ps   zWeakMethod.__ne__)N) Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú __slots__r"r'r*r,rÚ__hash__Ú __classcell__rr)r(rr$s  c@s¼eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z e Z dd„Zd+dd„Zdd„Zdd„ZeZdd„Zdd „Zd!d"„Zd#d$„Zd,d%d&„Zd'd(„Zd)d*„ZdS)-rz›Mapping class that references values weakly. Entries in the dictionary will be discarded when no strong reference to the value exists anymore cOsl|s tdƒ‚|^}}t|ƒdkr0tdt|ƒƒ‚t|ƒtfdd„}||_g|_tƒ|_i|_|j ||ŽdS)NzGdescriptor '__init__' of 'WeakValueDictionary' object needs an argumentéz$expected at most 1 arguments, got %dcSs6|ƒ}|dk r2|jr$|j |j¡n||j|jƒdS)N)Ú _iteratingÚ_pending_removalsÚappendÚkeyÚdata)ÚwrÚselfrefZ_atomic_removalrrrrÚremovems z,WeakValueDictionary.__init__..remove) rÚlenrr Ú_remover6Úsetr5r9Úupdate)ÚargsÚkwrr<rrrÚ__init__fs  zWeakValueDictionary.__init__cCs,|j}|j}x|r&| ¡}t||ƒqWdS)N)r6r9Úpopr )rÚlÚdr8rrrÚ_commit_removals}s z$WeakValueDictionary._commit_removalscCs4|jr| ¡|j|ƒ}|dkr,t|ƒ‚n|SdS)N)r6rGr9ÚKeyError)rr8ÚorrrÚ __getitem__†s   zWeakValueDictionary.__getitem__cCs|jr| ¡|j|=dS)N)r6rGr9)rr8rrrÚ __delitem__�szWeakValueDictionary.__delitem__cCs|jr| ¡t|jƒS)N)r6rGr=r9)rrrrÚ__len__”szWeakValueDictionary.__len__cCs<|jr| ¡y|j|ƒ}Wntk r2dSX|dk S)NF)r6rGr9rH)rr8rIrrrÚ __contains__™sz WeakValueDictionary.__contains__cCsd|jjt|ƒfS)Nz <%s at %#x>)r(r-Úid)rrrrÚ__repr__¢szWeakValueDictionary.__repr__cCs&|jr| ¡t||j|ƒ|j|<dS)N)r6rGÚKeyedRefr>r9)rr8ÚvaluerrrÚ __setitem__¥szWeakValueDictionary.__setitem__c CsZ|jr| ¡tƒ}t|ƒ�4x,|j ¡D]\}}|ƒ}|dk r*|||<q*WWdQRX|S)N)r6rGrr r9Úitems)rÚnewr8r:rIrrrÚcopyªs zWeakValueDictionary.copyc Csnddlm}|jr| ¡| ¡}t|ƒ�:x2|j ¡D]$\}}|ƒ}|dk r8|||||ƒ<q8WWdQRX|S)Nr)Údeepcopy)rUrVr6rGr(r r9rS)rÚmemorVrTr8r:rIrrrÚ __deepcopy__·s  z WeakValueDictionary.__deepcopy__NcCsL|jr| ¡y|j|}Wntk r0|SX|ƒ}|dkrD|S|SdS)N)r6rGr9rH)rr8Údefaultr:rIrrrÚgetÃszWeakValueDictionary.getc csV|jr| ¡t|ƒ�6x.|j ¡D] \}}|ƒ}|dk r$||fVq$WWdQRXdS)N)r6rGr r9rS)rÚkr:ÚvrrrrSÒs zWeakValueDictionary.itemsc csN|jr| ¡t|ƒ�.x&|j ¡D]\}}|ƒdk r$|Vq$WWdQRXdS)N)r6rGr r9rS)rr[r:rrrÚkeysÛs   zWeakValueDictionary.keysc cs6|jr| ¡t|ƒ�|j ¡EdHWdQRXdS)a�Return 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. N)r6rGr r9Úvalues)rrrrÚ itervaluerefsås  z!WeakValueDictionary.itervaluerefsc csN|jr| ¡t|ƒ�.x&|j ¡D]}|ƒ}|dk r$|Vq$WWdQRXdS)N)r6rGr r9r^)rr:r$rrrr^ôs zWeakValueDictionary.valuescCs<|jr| ¡x(|j ¡\}}|ƒ}|dk r||fSqWdS)N)r6rGr9Úpopitem)rr8r:rIrrrr`ýszWeakValueDictionary.popitemcGs`|jr| ¡y|j |¡ƒ}Wntk r8d}YnX|dkrX|rN|dSt|ƒ‚n|SdS)Nr)r6rGr9rDrH)rr8rArIrrrrDs  zWeakValueDictionary.popcCs`y|j|ƒ}Wntk r(d}YnX|dkrX|jr@| ¡t||j|ƒ|j|<|S|SdS)N)r9rHr6rGrPr>)rr8rYrIrrrÚ setdefaults zWeakValueDictionary.setdefaultcOs°|s tdƒ‚|^}}t|ƒdkr0tdt|ƒƒ‚|r<|dnd}|jrN| ¡|j}|dk ršt|dƒsrtiƒ|ƒ}x&| ¡D]\}}t||j |ƒ||<q|Wt|ƒr¬|  |¡dS)NzEdescriptor 'update' of 'WeakValueDictionary' object needs an argumentr4z$expected at most 1 arguments, got %drrS) rr=r6rGr9Úhasattrr!rSrPr>r@)rAÚkwargsrÚdictrFr8rIrrrr@"s    zWeakValueDictionary.updatecCs|jr| ¡t|j ¡ƒ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. )r6rGÚlistr9r^)rrrrÚ valuerefs5s zWeakValueDictionary.valuerefs)N)N)r-r.r/r0rCrGrJrKrLrMrOrRrUÚ__copy__rXrZrSr]Ú__iter__r_r^r`rDrar@rfrrrrrZs.         cs,eZdZdZdZdd„Z‡fdd„Z‡ZS)rPa[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. )r8cCst |||¡}||_|S)N)rr"r8)r!Úobrr8rrrrr"PszKeyedRef.__new__cstƒ ||¡dS)N)r&rC)rrirr8)r(rrrCUszKeyedRef.__init__)r-r.r/r0r1r"rCr3rr)r(rrPDsrPc@sÀeZdZdZd+dd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z e Z dd„Zd,dd„Zdd„Zdd„Zdd„ZeZdd „Zd!d"„Zd#d$„Zd%d&„Zd-d'd(„Zd.d)d*„ZdS)/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. NcCsFi|_t|ƒfdd„}||_g|_tƒ|_d|_|dk rB| |¡dS)NcSs.|ƒ}|dk r*|jr"|j |¡n|j|=dS)N)r5r6r7r9)r[r;rrrrr<fs z*WeakKeyDictionary.__init__..removeF)r9rr>r6r?r5Ú _dirty_lenr@)rrdr<rrrrCdszWeakKeyDictionary.__init__cCs>|j}|j}x,|r8y|| ¡=Wqtk r4YqXqWdS)N)r6r9rDrH)rrErFrrrrGusz"WeakKeyDictionary._commit_removalscs&|j‰‡fdd„|jDƒ|_d|_dS)Ncsg|]}|ˆkr|‘qSrr)Ú.0r[)rFrrú „sz5WeakKeyDictionary._scrub_removals..F)r9r6rj)rr)rFrÚ_scrub_removals‚sz!WeakKeyDictionary._scrub_removalscCsd|_|jt|ƒ=dS)NT)rjr9r)rr8rrrrK‡szWeakKeyDictionary.__delitem__cCs|jt|ƒS)N)r9r)rr8rrrrJ‹szWeakKeyDictionary.__getitem__cCs(|jr|jr| ¡t|jƒt|jƒS)N)rjr6rmr=r9)rrrrrLŽs zWeakKeyDictionary.__len__cCsd|jjt|ƒfS)Nz <%s at %#x>)r(r-rN)rrrrrO•szWeakKeyDictionary.__repr__cCs||jt||jƒ<dS)N)r9rr>)rr8rQrrrrR˜szWeakKeyDictionary.__setitem__c CsLtƒ}t|ƒ�4x,|j ¡D]\}}|ƒ}|dk r|||<qWWdQRX|S)N)r r r9rS)rrTr8rQrIrrrrU›s zWeakKeyDictionary.copyc Cs`ddlm}| ¡}t|ƒ�:x2|j ¡D]$\}}|ƒ}|dk r*|||ƒ||<q*WWdQRX|S)Nr)rV)rUrVr(r r9rS)rrWrVrTr8rQrIrrrrX¦s  zWeakKeyDictionary.__deepcopy__cCs|j t|ƒ|¡S)N)r9rZr)rr8rYrrrrZ°szWeakKeyDictionary.getcCs,y t|ƒ}Wntk r dSX||jkS)NF)rrr9)rr8r:rrrrM³s  zWeakKeyDictionary.__contains__c csHt|ƒ�6x.|j ¡D] \}}|ƒ}|dk r||fVqWWdQRXdS)N)r r9rS)rr:rQr8rrrrSºs  zWeakKeyDictionary.itemsc cs<t|ƒ�*x"|jD]}|ƒ}|dk r|VqWWdQRXdS)N)r r9)rr:r$rrrr]Ás   zWeakKeyDictionary.keysc cs@t|ƒ�.x&|j ¡D]\}}|ƒdk r|VqWWdQRXdS)N)r r9rS)rr:rQrrrr^Ês  zWeakKeyDictionary.valuescCs t|jƒS)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. )rer9)rrrrÚkeyrefsÐs zWeakKeyDictionary.keyrefscCs4d|_x(|j ¡\}}|ƒ}|dk r||fSqWdS)NT)rjr9r`)rr8rQrIrrrr`Üs zWeakKeyDictionary.popitemcGsd|_|jjt|ƒf|žŽS)NT)rjr9rDr)rr8rArrrrDäszWeakKeyDictionary.popcCs|j t||jƒ|¡S)N)r9rarr>)rr8rYrrrraèszWeakKeyDictionary.setdefaultcKs`|j}|dk rJt|dƒs$tiƒ|ƒ}x$| ¡D]\}}||t||jƒ<q.Wt|ƒr\| |¡dS)NrS)r9rbr!rSrr>r=r@)rrdrcrFr8rQrrrr@ës  zWeakKeyDictionary.update)N)N)N)N)r-r.r/r0rCrGrmrKrJrLrOrRrUrgrXrZrMrSr]rhr^rnr`rDrar@rrrrr Ys.       c@s¢eZdZdZdZiZdZe ¡Z dZ dZ Gdd„dƒZ dd„Z dd d „Zd d „Zd d„Zedd„ƒZedd„ƒZejdd„ƒZdd„Zedd„ƒZedd„ƒZdS)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. rFc@seZdZdZdS)zfinalize._Info)Úweakrefr%rArcÚatexitÚindexN)r-r.r/r1rrrrÚ_InfosrrcOs t|ƒdkr|^}}}}nz|s(tdƒ‚nld|krDtdt|ƒdƒ‚| d¡}t|ƒdkrf|^}}}n.d|kr‚tdt|ƒdƒ‚| d¡}|^}}t|ƒ}|js¼ddl}| |j¡d t_|  ¡}t ||ƒ|_ ||_ ||_ |pâd|_d |_t|jƒ|_||j|<d t_dS) Nézs  zfinalize.detachcCs:|j |¡}|o| ¡}|dk r6||j|j|jp2ifSdS)zMIf alive then return (obj, func, args, kwargs); otherwise return NoneN)r{rZror%rArc)rr}r$rrrÚpeekFs  z finalize.peekcCs ||jkS)zWhether finalizer is alive)r{)rrrrÚaliveNszfinalize.alivecCs|j |¡}t|ƒo|jS)z*Whether finalizer should be called at exit)r{rZÚboolrp)rr}rrrrpSs zfinalize.atexitcCs|j |¡}|rt|ƒ|_dS)N)r{rZrƒrp)rrQr}rrrrpYs cCs^|j |¡}|o| ¡}|dkr6dt|ƒjt|ƒfSdt|ƒjt|ƒt|ƒjt|ƒfSdS)Nz<%s object at %#x; dead>z!<%s object at %#x; for %r at %#x>)r{rZror!r-rN)rr}r$rrrrO_s   zfinalize.__repr__cCs2dd„|j ¡Dƒ}|jdd„d�dd„|DƒS)NcSsg|]\}}|jr||f‘qSr)rp)rkÚfÚirrrrlksz-finalize._select_for_exit..cSs |djS)Nr4)rq)ÚitemrrrÚlóz+finalize._select_for_exit..)r8cSsg|] \}}|‘qSrr)rkr„r…rrrrlms)r{rSÚsort)r#ÚLrrrÚ_select_for_exithszfinalize._select_for_exitcCs¦d}zˆ|jrŠddl}| ¡r(d}| ¡d}x\|dkss"(  6k