grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026o ®û|j8Tã@sÒdZddlmZmZmZmZmZmZmZm Z ddl m Z m Z ddl Z ddlZddlZeefZgd¢Ze j e ¡e j e ¡Gdd„deƒZGdd „d e jƒZGd d „d eƒZGd d „d e jƒZGdd„dƒZdS)z|Weak reference support for Python. This module is an implementation of PEP 205: https://www.python.org/dev/peps/pep-0205/ é)ÚgetweakrefcountÚ getweakrefsÚrefÚproxyÚCallableProxyTypeÚ ProxyTypeÚ ReferenceTypeÚ_remove_dead_weakref)ÚWeakSetÚ_IterationGuardN) rrrrÚ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__Ncsxz|j}|j}Wntytd t|ƒ¡ƒd‚w‡‡fdd„}t |||¡}t||ƒ|_t|ƒ|_ d|_ t|ƒ‰|S)Nz)argument should be a bound method, not {}cs.ˆƒ}|jrd|_ˆdurˆ|ƒdSdSdS©NF)r)ÚargÚself©ÚcallbackZself_wr©ú./opt/alt/python310/lib64/python3.10/weakref.pyÚ_cb6s ýzWeakMethod.__new__.._cbT) Ú__self__Ú__func__ÚAttributeErrorÚ TypeErrorÚformatÚtyperÚ__new__rrr)ÚclsZmethrÚobjÚfuncrrrrrr#/s"   ÿÿÿ  zWeakMethod.__new__cs2tƒ ¡}| ¡}|dus|durdS| ||¡S©N)ÚsuperÚ__call__rr)rr%r&©Ú __class__rrr)Es  zWeakMethod.__call__cCs:t|tƒr|jr |js||uSt ||¡o|j|jkStSr')Ú isinstancerrrÚ__eq__rÚNotImplemented©rÚotherrrrr-Ló  zWeakMethod.__eq__cCs:t|tƒr|jr |js||uSt ||¡p|j|jkStSr')r,rrrÚ__ne__rr.r/rrrr2Sr1zWeakMethod.__ne__r') Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú __slots__r#r)r-r2rÚ__hash__Ú __classcell__rrr*rr's  rc@sÜeZdZdZd2dd„Zefdd„Zdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dd„Z e Zdd„Zd3dd„Zdd„Zdd„ZeZdd„Zd d!„Zd"d#„Zd$d%„Zd3d&d'„Zd3d(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„ZdS)4rz›Mapping class that references values weakly. Entries in the dictionary will be discarded when no strong reference to the value exists anymore rcKsBt|ƒtfdd„}||_g|_tƒ|_i|_|j|fi|¤ŽdS)NcSs<|ƒ}|dur|jr|j |j¡dS||j|jƒdSdSr')Ú _iteratingÚ_pending_removalsÚappendÚkeyÚdata)ÚwrÚselfrefÚ_atomic_removalrrrrÚremovejs úz,WeakValueDictionary.__init__..remove)rr Ú_remover;Úsetr:r>Úupdate)rr0ÚkwrBrrrÚ__init__is  zWeakValueDictionary.__init__cCs<|jj}|j} z|ƒ}Wn tyYdSw|||ƒqr')r;Úpopr>Ú IndexError)rrArHÚdr=rrrÚ_commit_removalszs  ÿ ûz$WeakValueDictionary._commit_removalscCs.|jr| ¡|j|ƒ}|durt|ƒ‚|Sr'©r;rKr>ÚKeyError©rr=ÚorrrÚ __getitem__†s  zWeakValueDictionary.__getitem__cCs|jr| ¡|j|=dSr')r;rKr>©rr=rrrÚ __delitem__�s zWeakValueDictionary.__delitem__cCs|jr| ¡t|jƒSr')r;rKÚlenr>©rrrrÚ__len__”s zWeakValueDictionary.__len__cCs:|jr| ¡z |j|ƒ}W|duStyYdSwrrLrNrrrÚ __contains__™s þÿz WeakValueDictionary.__contains__cCód|jjt|ƒfS©Nz <%s at %#x>©r+r3ÚidrTrrrÚ__repr__¢ózWeakValueDictionary.__repr__cCs&|jr| ¡t||j|ƒ|j|<dSr')r;rKÚKeyedRefrCr>©rr=ÚvaluerrrÚ __setitem__¥szWeakValueDictionary.__setitem__cCsl|jr| ¡tƒ}t|ƒ�|j ¡D]\}}|ƒ}|dur#|||<qWdƒ|S1s/wY|Sr')r;rKrr r>Úitems)rÚnewr=r?rOrrrÚcopyªs €ý ÿûzWeakValueDictionary.copycCs€ddlm}|jr | ¡| ¡}t|ƒ�!|j ¡D]\}}|ƒ}|dur-|||||ƒ<qWdƒ|S1s9wY|S©Nr)Údeepcopy)rcrer;rKr+r r>ra)rÚmemorerbr=r?rOrrrÚ __deepcopy__·s  €ý ÿûz WeakValueDictionary.__deepcopy__NcCsJ|jr| ¡z|j|}Wn ty|YSw|ƒ}|dur#|S|Sr'rL)rr=Údefaultr?rOrrrÚgetÃs ÿzWeakValueDictionary.getccsj�|jr| ¡t|ƒ�|j ¡D]\}}|ƒ}|dur"||fVqWdƒdS1s.wYdSr'©r;rKr r>ra)rÚkr?ÚvrrrraÒs€  €ý"ÿzWeakValueDictionary.itemsccsb�|jr| ¡t|ƒ�|j ¡D] \}}|ƒdur|VqWdƒdS1s*wYdSr'rj)rrkr?rrrÚkeysÛs€  €þ"ÿzWeakValueDictionary.keysccsN�|jr| ¡t|ƒ�|j ¡EdHWdƒdS1s wYdS)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©r;rKr r>ÚvaluesrTrrrÚ itervaluerefsås €  "ÿz!WeakValueDictionary.itervaluerefsccsb�|jr| ¡t|ƒ�|j ¡D] }|ƒ}|dur|VqWdƒdS1s*wYdSr'rn©rr?r%rrrroôs€ €ý"ÿzWeakValueDictionary.valuescCs6|jr| ¡ |j ¡\}}|ƒ}|dur||fSqr')r;rKr>Úpopitem)rr=r?rOrrrrrýsüzWeakValueDictionary.popitemcGsX|jr| ¡z |j |¡ƒ}Wn tyd}Ynw|dur*|r&|dSt|ƒ‚|S)Nr)r;rKr>rHrM)rr=ÚargsrOrrrrHs ÿzWeakValueDictionary.popcCsZz|j|ƒ}Wn tyd}Ynw|dur+|jr| ¡t||j|ƒ|j|<|S|Sr')r>rMr;rKr]rC)rr=rhrOrrrÚ setdefaults ÿzWeakValueDictionary.setdefaultcKsz|jr| ¡|j}|dur)t|dƒst|ƒ}| ¡D] \}}t||j|ƒ||<q| ¡D] \}}t||j|ƒ||<q-dS©Nra)r;rKr>ÚhasattrÚdictrar]rC)rr0ÚkwargsrJr=rOrrrrE"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. )r;rKÚlistr>rorTrrrÚ valuerefs.s zWeakValueDictionary.valuerefscCó| |¡|Sr'©rEr/rrrÚ__ior__<ó zWeakValueDictionary.__ior__cCó&t|tjƒr| ¡}| |¡|StSr'©r,Ú_collections_abcÚMappingrcrEr.©rr0ÚcrrrÚ__or__@ó  zWeakValueDictionary.__or__cCó0t|tjƒr| ¡}| |¡| |¡|StSr'©r,r�r‚r+rEr.rƒrrrÚ__ror__Gó   zWeakValueDictionary.__ror__)rr')r3r4r5r6rGr rKrPrRrUrVr[r`rcÚ__copy__rgrirarmÚ__iter__rprorrrHrtrErzr}r…r‰rrrrr]s6            rcs,eZdZdZdZdd„Z‡fdd„Z‡ZS)r]a[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. ©r=cCst |||¡}||_|Sr')rr#r=)r"Úobrr=rrrrr#\szKeyedRef.__new__cstƒ ||¡dSr')r(rG)rrŽrr=r*rrrGaózKeyedRef.__init__)r3r4r5r6r7r#rGr9rrr*rr]Ps  r]c@sØeZdZdZd1dd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z e Z dd„Zd1dd„Zdd„Zdd„Zdd„ZeZdd „Zd!d"„Zd#d$„Zd%d&„Zd1d'd(„Zd1d)d*„Zd+d,„Zd-d.„Zd/d0„ZdS)2r 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. NcCsJi|_t|ƒfdd„}||_g|_tƒ|_d|_|dur#| |¡dSdS)NcSsL|ƒ}|dur$|jr|j |¡dSz|j|=WdSty#YdSwdSr')r:r;r<r>rM)rkr@rrrrrBrs ÿúz*WeakKeyDictionary.__init__..removeF)r>rrCr;rDr:Ú _dirty_lenrE)rrwrBrrrrGps ÿzWeakKeyDictionary.__init__cCsP|jj}|j} z|ƒ}Wn tyYdSwz||=Wn ty&Ynwqr')r;rHr>rIrM)rrHrJr=rrrrK„s  ÿ  ÿøz"WeakKeyDictionary._commit_removalscs&|j‰‡fdd„|jDƒ|_d|_dS)Ncsg|]}|ˆvr|‘qSrr)Ú.0rk©rJrrÚ ˜sz5WeakKeyDictionary._scrub_removals..F)r>r;r�rTrr’rÚ_scrub_removals–s z!WeakKeyDictionary._scrub_removalscCsd|_|jt|ƒ=dS©NT)r�r>rrQrrrrR›szWeakKeyDictionary.__delitem__cCs|jt|ƒSr')r>rrQrrrrPŸszWeakKeyDictionary.__getitem__cCs(|jr |jr | ¡t|jƒt|jƒSr')r�r;r”rSr>rTrrrrU¢s zWeakKeyDictionary.__len__cCrWrXrYrTrrrr[©r\zWeakKeyDictionary.__repr__cCs||jt||jƒ<dSr')r>rrCr^rrrr`¬ózWeakKeyDictionary.__setitem__cCs^tƒ}t|ƒ�|j ¡D]\}}|ƒ}|dur|||<q Wdƒ|S1s(wY|Sr')r r r>ra)rrbr=r_rOrrrrc¯s €ý ÿûzWeakKeyDictionary.copycCsrddlm}| ¡}t|ƒ�!|j ¡D]\}}|ƒ}|dur&|||ƒ||<qWdƒ|S1s2wY|Srd)rcrer+r r>ra)rrfrerbr=r_rOrrrrgºs  €ý ÿûzWeakKeyDictionary.__deepcopy__cCs|j t|ƒ|¡Sr')r>rir©rr=rhrrrriÄr�zWeakKeyDictionary.getcCs,zt|ƒ}Wn tyYdSw||jvSr)rr r>)rr=r?rrrrVÇs   ÿ zWeakKeyDictionary.__contains__ccs\�t|ƒ�|j ¡D]\}}|ƒ}|dur||fVq WdƒdS1s'wYdSr'©r r>ra)rr?r_r=rrrraÎs€  €ý"ÿzWeakKeyDictionary.itemsccsP�t|ƒ�|jD] }|ƒ}|dur|Vq WdƒdS1s!wYdSr')r r>rqrrrrmÕs€  €ý"ÿzWeakKeyDictionary.keysccsT�t|ƒ�|j ¡D] \}}|ƒdur|Vq WdƒdS1s#wYdSr'r˜)rr?r_rrrroÞ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. )ryr>rTrrrÚkeyrefsäs zWeakKeyDictionary.keyrefscCs.d|_ |j ¡\}}|ƒ}|dur||fSqr•)r�r>rr)rr=r_rOrrrrrðsüzWeakKeyDictionary.popitemcGsd|_|jjt|ƒg|¢RŽSr•)r�r>rHr)rr=rsrrrrHøszWeakKeyDictionary.popcCs|j t||jƒ|¡Sr')r>rtrrCr—rrrrtür–zWeakKeyDictionary.setdefaultcKs`|j}|dur#t|dƒstiƒ|ƒ}| ¡D] \}}||t||jƒ<qt|ƒr.| |¡dSdSru)r>rvr"rarrCrSrE)rrwrxrJr=r_rrrrEÿs  ÿzWeakKeyDictionary.updatecCr{r'r|r/rrrr} r~zWeakKeyDictionary.__ior__cCrr'r€rƒrrrr… r†zWeakKeyDictionary.__or__cCr‡r'rˆrƒrrrr‰rŠzWeakKeyDictionary.__ror__r')r3r4r5r6rGrKr”rRrPrUr[r`rcr‹rgrirVrarmrŒror™rrrHrtrEr}r…r‰rrrrr es6        r 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&rsrxÚatexitÚindexN)r3r4r5r7rrrrÚ_Info6sr�cOsp|jsddl}| |j¡dt_| ¡}t||ƒ|_||_||_ |p#d|_ d|_t |j ƒ|_ ||j|<dt_dS)NrT)Ú_registered_with_atexitr›ÚregisterÚ _exitfuncrr�rršr&rsrxÚnextÚ _index_iterrœÚ _registryÚ_dirty)rr%r&rsrxr›ÚinforrrrG9s      zfinalize.__init__NcCs8|j |d¡}|r|js|j|ji|jpi¤ŽSdSdS)zZIf alive then mark as dead and return func(*args, **kwargs); otherwise return NoneN)r£rHÚ _shutdownr&rsrx)rÚ_r¥rrrr)Js ÿzfinalize.__call__cCsL|j |¡}|o | ¡}|dur"|j |d¡r$||j|j|jp ifSdSdS)z^If alive then mark as dead and return (obj, func, args, kwargs); otherwise return NoneN)r£riršrHr&rsrx©rr¥r%rrrÚdetachQs  ÿzfinalize.detachcCs:|j |¡}|o | ¡}|dur||j|j|jpifSdS)zMIf alive then return (obj, func, args, kwargs); otherwise return NoneN)r£riršr&rsrxr¨rrrÚpeekYs  ÿz finalize.peekcCs ||jvS)zWhether finalizer is alive)r£rTrrrÚaliveas zfinalize.alivecCs|j |¡}t|ƒo |jS)z*Whether finalizer should be called at exit©r£riÚboolr›)rr¥rrrr›fs zfinalize.atexitcCs"|j |¡}|rt|ƒ|_dSdSr'r¬)rr_r¥rrrr›ls ÿcCsZ|j |¡}|o | ¡}|durdt|ƒjt|ƒfSdt|ƒjt|ƒt|ƒjt|ƒfS)Nz<%s object at %#x; dead>z!<%s object at %#x; for %r at %#x>)r£riršr"r3rZr¨rrrr[rs  ÿzfinalize.__repr__cCs2dd„|j ¡Dƒ}|jdd„d�dd„|DƒS)NcSsg|] \}}|jr||f‘qSr)r›©r‘ÚfÚirrrr“~sz-finalize._select_for_exit..cSs |djS)Né)rœ)ÚitemrrrÚs z+finalize._select_for_exit..r�cSsg|]\}}|‘qSrrr®rrrr“€s)r£raÚsort)r$ÚLrrrÚ_select_for_exit{szfinalize._select_for_exitcCs¸d}zN|jrCddl}| ¡rd}| ¡d} |dustjr%| ¡}dt_|s(n| ¡}z|ƒWntyAt j t   ¡ŽYnwqWdt_ |rO|  ¡dSdSdt_ |r[|  ¡ww)NFrT)r£ÚgcZ isenabledZdisablerr¤r¶rHÚ ExceptionÚsysÚ excepthookÚexc_infor¦Zenable)r$Z reenable_gcr·Zpendingr¯rrrr ‚s<  ÿó€ ÿÿ ÿzfinalize._exitfuncr')r3r4r5r6r7r£r¦Ú itertoolsÚcountr¢r¤ržr�rGr)r©rªÚpropertyr«r›Úsetterr[Ú classmethodr¶r rrrrrs0     r)r6Ú_weakrefrrrrrrrr Z _weakrefsetr r r�r¹r¼r Ú__all__ÚSetrŸÚ MutableSetrÚMutableMappingrr]r rrrrrÚs"(    6t9