grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a XC?h8Tã@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__Ncs|z|j}|j}Wn&ty6td t|ƒ¡ƒd‚Yn0‡‡fdd„}t |||¡}t||ƒ|_t|ƒ|_ d|_ t|ƒ‰|S)Nz)argument should be a bound method, not {}cs&ˆƒ}|jr"d|_ˆdur"ˆ|ƒdS©NF)r)ÚargÚself©ÚcallbackZself_wr©ú,/opt/alt/python39/lib64/python3.9/weakref.pyÚ_cb6s zWeakMethod.__new__.._cbT) Ú__self__Ú__func__ÚAttributeErrorÚ TypeErrorÚformatÚtyperÚ__new__rrr)ÚclsZmethrÚobjÚfuncrrrrrr#/s   ÿÿ  zWeakMethod.__new__cs2tƒ ¡}| ¡}|dus"|dur&dS| ||¡S©N)ÚsuperÚ__call__rr)rr%r&©Ú __class__rrr)Es  zWeakMethod.__call__cCs:t|tƒr6|jr|js||uSt ||¡o4|j|jkStSr')Ú isinstancerrrÚ__eq__rÚNotImplemented©rÚotherrrrr-Ls   zWeakMethod.__eq__cCs:t|tƒr6|jr|js||uSt ||¡p4|j|jkStSr')r,rrrÚ__ne__rr.r/rrrr1Ss   zWeakMethod.__ne__)N) Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú __slots__r#r)r-r1rÚ__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%„Zd4d&d'„Zd5d(d)„Zd*d+„Zd,d-„Zd.d/„Zd0d1„ZdS)6rz›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)NcSs6|ƒ}|dur2|jr$|j |j¡n||j|jƒdSr')Ú _iteratingÚ_pending_removalsÚappendÚkeyÚdata)ÚwrÚselfrefÚ_atomic_removalrrrrÚremovejs z,WeakValueDictionary.__init__..remove)rr Ú_remover:Úsetr9r=Úupdate)rr0ÚkwrArrrÚ__init__is  zWeakValueDictionary.__init__cCs>|jj}|j}z |ƒ}Wnty,YdS0|||ƒqdSr')r:Úpopr=Ú IndexError)rr@rGÚdr<rrrÚ_commit_removalszs  z$WeakValueDictionary._commit_removalscCs4|jr| ¡|j|ƒ}|dur,t|ƒ‚n|SdSr'©r:rJr=ÚKeyError©rr<ÚorrrÚ __getitem__†s   zWeakValueDictionary.__getitem__cCs|jr| ¡|j|=dSr')r:rJr=©rr<rrrÚ __delitem__�szWeakValueDictionary.__delitem__cCs|jr| ¡t|jƒSr')r:rJÚlenr=©rrrrÚ__len__”szWeakValueDictionary.__len__cCs<|jr| ¡z|j|ƒ}Wnty2YdS0|duSrrKrMrrrÚ __contains__™s z WeakValueDictionary.__contains__cCsd|jjt|ƒfS©Nz <%s at %#x>©r+r2ÚidrSrrrÚ__repr__¢szWeakValueDictionary.__repr__cCs&|jr| ¡t||j|ƒ|j|<dSr')r:rJÚKeyedRefrBr=©rr<ÚvaluerrrÚ __setitem__¥szWeakValueDictionary.__setitem__cCsj|jr| ¡tƒ}t|ƒ�:|j ¡D]\}}|ƒ}|dur(|||<q(Wdƒn1s\0Y|Sr')r:rJrr r=Úitems)rÚnewr<r>rNrrrÚcopyªs (zWeakValueDictionary.copycCs~ddlm}|jr| ¡| ¡}t|ƒ�@|j ¡D]$\}}|ƒ}|dur6|||||ƒ<q6Wdƒn1sp0Y|S©Nr)Údeepcopy)r`rbr:rJr+r r=r^)rÚmemorbr_r<r>rNrrrÚ __deepcopy__·s  .z WeakValueDictionary.__deepcopy__NcCsN|jr| ¡z|j|}Wnty2|YS0|ƒ}|durF|S|SdSr'rK)rr<Údefaultr>rNrrrÚgetÃs  zWeakValueDictionary.getccsf|jr| ¡t|ƒ�<|j ¡D] \}}|ƒ}|dur"||fVq"Wdƒn1sX0YdSr'©r:rJr r=r^)rÚkr>Úvrrrr^Òs zWeakValueDictionary.itemsccs^|jr| ¡t|ƒ�4|j ¡D]\}}|ƒdur"|Vq"Wdƒn1sP0YdSr'rg)rrhr>rrrÚkeysÛs   zWeakValueDictionary.keysccsJ|jr| ¡t|ƒ� |j ¡EdHWdƒn1s<0YdS)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:rJr r=ÚvaluesrSrrrÚ itervaluerefsås  z!WeakValueDictionary.itervaluerefsccs^|jr| ¡t|ƒ�4|j ¡D]}|ƒ}|dur"|Vq"Wdƒn1sP0YdSr'rk©rr>r%rrrrlôs zWeakValueDictionary.valuescCs8|jr| ¡|j ¡\}}|ƒ}|dur||fSqdSr')r:rJr=Úpopitem)rr<r>rNrrrroýs zWeakValueDictionary.popitemcGs^|jr| ¡z|j |¡ƒ}Wnty6d}Yn0|durV|rL|dSt|ƒ‚n|SdS)Nr)r:rJr=rGrL)rr<ÚargsrNrrrrGs   zWeakValueDictionary.popcCs^z|j|ƒ}Wnty&d}Yn0|durV|jr>| ¡t||j|ƒ|j|<|S|SdSr')r=rLr:rJrZrB)rr<rerNrrrÚ setdefaults  zWeakValueDictionary.setdefaultcKsz|jr| ¡|j}|durRt|dƒs.t|ƒ}| ¡D]\}}t||j|ƒ||<q6| ¡D]\}}t||j|ƒ||<qZdS©Nr^)r:rJr=ÚhasattrÚdictr^rZrB)rr0ÚkwargsrIr<rNrrrrD"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:rJÚlistr=rlrSrrrÚ valuerefs.s zWeakValueDictionary.valuerefscCs| |¡|Sr'©rDr/rrrÚ__ior__<s zWeakValueDictionary.__ior__cCs&t|tjƒr"| ¡}| |¡|StSr'©r,Ú_collections_abcÚMappingr`rDr.©rr0ÚcrrrÚ__or__@s   zWeakValueDictionary.__or__cCs0t|tjƒr,| ¡}| |¡| |¡|StSr'©r,r{r|r+rDr.r}rrrÚ__ror__Gs    zWeakValueDictionary.__ror__)r)N)N)N)r2r3r4r5rFr rJrOrQrTrUrYr]r`Ú__copy__rdrfr^rjÚ__iter__rmrlrorGrqrDrwryrr�rrrrr]s4          rcs,eZdZdZdZdd„Z‡fdd„Z‡ZS)rZa[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(rF)rr…rr<r*rrrFaszKeyedRef.__init__)r2r3r4r5r6r#rFr8rrr*rrZPs rZc@sØeZdZdZd1dd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z e Z dd„Zd2dd„Zdd„Zdd„Zdd„ZeZdd „Zd!d"„Zd#d$„Zd%d&„Zd3d'd(„Zd4d)d*„Zd+d,„Zd-d.„Zd/d0„ZdS)5r 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|_|durB| |¡dS)NcSsF|ƒ}|durB|jr"|j |¡n z |j|=Wnty@Yn0dSr')r9r:r;r=rL)rhr?rrrrrArs  z*WeakKeyDictionary.__init__..removeF)r=rrBr:rCr9Ú _dirty_lenrD)rrtrArrrrFps zWeakKeyDictionary.__init__cCsR|jj}|j}z |ƒ}Wnty,YdS0z ||=WqtyJYq0qdSr')r:rGr=rHrL)rrGrIr<rrrrJ„s    z"WeakKeyDictionary._commit_removalscs&|j‰‡fdd„|jDƒ|_d|_dS)Ncsg|]}|ˆvr|‘qSrr)Ú.0rh©rIrrÚ ˜óz5WeakKeyDictionary._scrub_removals..F)r=r:r†rSrrˆrÚ_scrub_removals–sz!WeakKeyDictionary._scrub_removalscCsd|_|jt|ƒ=dS©NT)r†r=rrPrrrrQ›szWeakKeyDictionary.__delitem__cCs|jt|ƒSr')r=rrPrrrrOŸszWeakKeyDictionary.__getitem__cCs(|jr|jr| ¡t|jƒt|jƒSr')r†r:r‹rRr=rSrrrrT¢s zWeakKeyDictionary.__len__cCsd|jjt|ƒfSrVrWrSrrrrY©szWeakKeyDictionary.__repr__cCs||jt||jƒ<dSr')r=rrBr[rrrr]¬szWeakKeyDictionary.__setitem__cCs\tƒ}t|ƒ�:|j ¡D]\}}|ƒ}|dur|||<qWdƒn1sN0Y|Sr')r r r=r^)rr_r<r\rNrrrr`¯s (zWeakKeyDictionary.copycCspddlm}| ¡}t|ƒ�@|j ¡D]$\}}|ƒ}|dur(|||ƒ||<q(Wdƒn1sb0Y|Sra)r`rbr+r r=r^)rrcrbr_r<r\rNrrrrdºs  .zWeakKeyDictionary.__deepcopy__cCs|j t|ƒ|¡Sr')r=rfr©rr<rerrrrfÄszWeakKeyDictionary.getcCs,z t|ƒ}Wnty YdS0||jvSr)rr r=)rr<r>rrrrUÇs   zWeakKeyDictionary.__contains__ccsXt|ƒ�<|j ¡D] \}}|ƒ}|dur||fVqWdƒn1sJ0YdSr'©r r=r^)rr>r\r<rrrr^Îs  zWeakKeyDictionary.itemsccsLt|ƒ�0|jD]}|ƒ}|dur|VqWdƒn1s>0YdSr')r r=rnrrrrjÕs   zWeakKeyDictionary.keysccsPt|ƒ�4|j ¡D]\}}|ƒdur|VqWdƒn1sB0YdSr'rŽ)rr>r\rrrrlÞ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. )rvr=rSrrrÚkeyrefsäs zWeakKeyDictionary.keyrefscCs0d|_|j ¡\}}|ƒ}|dur||fSqdSrŒ)r†r=ro)rr<r\rNrrrroðs zWeakKeyDictionary.popitemcGsd|_|jjt|ƒg|¢RŽSrŒ)r†r=rGr)rr<rprrrrGøszWeakKeyDictionary.popcCs|j t||jƒ|¡Sr')r=rqrrBr�rrrrqüszWeakKeyDictionary.setdefaultcKs\|j}|durFt|dƒs$tiƒ|ƒ}| ¡D]\}}||t||jƒ<q,t|ƒrX| |¡dSrr)r=rsr"r^rrBrRrD)rrtrurIr<r\rrrrDÿs  zWeakKeyDictionary.updatecCs| |¡|Sr'rxr/rrrry s zWeakKeyDictionary.__ior__cCs&t|tjƒr"| ¡}| |¡|StSr'rzr}rrrr s   zWeakKeyDictionary.__or__cCs0t|tjƒr,| ¡}| |¡| |¡|StSr'r€r}rrrr�s    zWeakKeyDictionary.__ror__)N)N)N)N)r2r3r4r5rFrJr‹rQrOrTrYr]r`r‚rdrfrUr^rjrƒrlr�rorGrqrDryrr�rrrrr es4      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&rpruÚatexitÚindexN)r2r3r4r6rrrrÚ_Info6sr“cOsp|js ddl}| |j¡dt_| ¡}t||ƒ|_||_||_ |pFd|_ d|_t |j ƒ|_ ||j|<dt_dS)NrT)Ú_registered_with_atexitr‘ÚregisterÚ _exitfuncrr“rr�r&rpruÚnextÚ _index_iterr’Ú _registryÚ_dirty)rr%r&rprur‘ÚinforrrrF9s     zfinalize.__init__NcCs4|j |d¡}|r0|js0|j|ji|jp*i¤ŽSdS)zZIf alive then mark as dead and return func(*args, **kwargs); otherwise return NoneN)r™rGÚ _shutdownr&rpru)rÚ_r›rrrr)Js zfinalize.__call__cCsH|j |¡}|o| ¡}|durD|j |d¡rD||j|j|jp@ifSdS)z^If alive then mark as dead and return (obj, func, args, kwargs); otherwise return NoneN)r™rfr�rGr&rpru©rr›r%rrrÚdetachQs  zfinalize.detachcCs:|j |¡}|o| ¡}|dur6||j|j|jp2ifSdS)zMIf alive then return (obj, func, args, kwargs); otherwise return NoneN)r™rfr�r&rpruržrrrÚpeekYs  z finalize.peekcCs ||jvS)zWhether finalizer is alive)r™rSrrrÚaliveaszfinalize.alivecCs|j |¡}t|ƒo|jS)z*Whether finalizer should be called at exit©r™rfÚboolr‘)rr›rrrr‘fs zfinalize.atexitcCs|j |¡}|rt|ƒ|_dSr'r¢)rr\r›rrrr‘ls cCs^|j |¡}|o| ¡}|dur6dt|ƒjt|ƒfSdt|ƒjt|ƒt|ƒjt|ƒfSdS)Nz<%s object at %#x; dead>z!<%s object at %#x; for %r at %#x>)r™rfr�r"r2rXržrrrrYrs  ÿzfinalize.__repr__cCs2dd„|j ¡Dƒ}|jdd„d�dd„|DƒS)NcSsg|]\}}|jr||f‘qSr)r‘©r‡ÚfÚirrrr‰~rŠz-finalize._select_for_exit..cSs |djS)Né)r’)ÚitemrrrÚrŠz+finalize._select_for_exit..r„cSsg|] \}}|‘qSrrr¤rrrr‰€rŠ)r™r^Úsort)r$ÚLrrrÚ_select_for_exit{szfinalize._select_for_exitcCsÀd}z¢|jr’ddl}| ¡r(d}| ¡d}|dus:tjrH| ¡}dt_|sNq’| ¡}z |ƒWn ty€t j t   ¡ŽYn0||jvs,J‚q,Wdt_ |r¼|  ¡ndt_ |rº|  ¡0dS)NFrT)r™ÚgcZ isenabledZdisablerršr¬rGÚ ExceptionÚsysÚ excepthookÚexc_inforœZenable)r$Z reenable_gcr­Zpendingr¥rrrr–‚s2   þzfinalize._exitfunc)N)r2r3r4r5r6r™rœÚ itertoolsÚcountr˜ršr”r“rFr)rŸr Úpropertyr¡r‘ÚsetterrYÚ classmethodr¬r–rrrrrs.      r)r5Ú_weakrefrrrrrrrr Z _weakrefsetr r r{r¯r²r Ú__all__ÚSetr•Ú MutableSetrÚMutableMappingrrZr rrrrrÚs  (   6t9