grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a ´i8Tã@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©ÚcallbackÚself_wr©ú/usr/lib64/python3.9/weakref.pyÚ_cb6s zWeakMethod.__new__.._cbT) Ú__self__Ú__func__ÚAttributeErrorÚ TypeErrorÚformatÚtyperÚ__new__rrr)ÚclsÚmethrÚ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__rr0r1rrrr3Ss   zWeakMethod.__ne__)N) Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú __slots__r$r+r/r3rÚ__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<Úsetr;r?Úupdate)rr2ÚkwrCrrrÚ__init__is  zWeakValueDictionary.__init__cCs>|jj}|j}z |ƒ}Wnty,YdS0|||ƒqdSr))r<Úpopr?Ú IndexError)rrBrIÚdr>rrrÚ_commit_removalszs  z$WeakValueDictionary._commit_removalscCs4|jr| ¡|j|ƒ}|dur,t|ƒ‚n|SdSr)©r<rLr?ÚKeyError©rr>ÚorrrÚ __getitem__†s   zWeakValueDictionary.__getitem__cCs|jr| ¡|j|=dSr))r<rLr?©rr>rrrÚ __delitem__�szWeakValueDictionary.__delitem__cCs|jr| ¡t|jƒSr))r<rLÚlenr?©rrrrÚ__len__”szWeakValueDictionary.__len__cCs<|jr| ¡z|j|ƒ}Wnty2YdS0|duSrrMrOrrrÚ __contains__™s z WeakValueDictionary.__contains__cCsd|jjt|ƒfS©Nz <%s at %#x>©r-r4ÚidrUrrrÚ__repr__¢szWeakValueDictionary.__repr__cCs&|jr| ¡t||j|ƒ|j|<dSr))r<rLÚKeyedRefrDr?©rr>ÚvaluerrrÚ __setitem__¥szWeakValueDictionary.__setitem__cCsj|jr| ¡tƒ}t|ƒ�:|j ¡D]\}}|ƒ}|dur(|||<q(Wdƒn1s\0Y|Sr))r<rLrr r?Úitems)rÚnewr>r@rPrrrÚcopyªs (zWeakValueDictionary.copycCs~ddlm}|jr| ¡| ¡}t|ƒ�@|j ¡D]$\}}|ƒ}|dur6|||||ƒ<q6Wdƒn1sp0Y|S©Nr)Údeepcopy)rbrdr<rLr-r r?r`)rÚmemordrar>r@rPrrrÚ __deepcopy__·s  .z WeakValueDictionary.__deepcopy__NcCsN|jr| ¡z|j|}Wnty2|YS0|ƒ}|durF|S|SdSr)rM)rr>Údefaultr@rPrrrÚgetÃs  zWeakValueDictionary.getccsf|jr| ¡t|ƒ�<|j ¡D] \}}|ƒ}|dur"||fVq"Wdƒn1sX0YdSr)©r<rLr r?r`)rÚkr@Úvrrrr`Òs zWeakValueDictionary.itemsccs^|jr| ¡t|ƒ�4|j ¡D]\}}|ƒdur"|Vq"Wdƒn1sP0YdSr)ri)rrjr@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<rLr r?ÚvaluesrUrrrÚ itervaluerefsås  z!WeakValueDictionary.itervaluerefsccs^|jr| ¡t|ƒ�4|j ¡D]}|ƒ}|dur"|Vq"Wdƒn1sP0YdSr)rm©rr@r'rrrrnôs zWeakValueDictionary.valuescCs8|jr| ¡|j ¡\}}|ƒ}|dur||fSqdSr))r<rLr?Úpopitem)rr>r@rPrrrrqýs zWeakValueDictionary.popitemcGs^|jr| ¡z|j |¡ƒ}Wnty6d}Yn0|durV|rL|dSt|ƒ‚n|SdS)Nr)r<rLr?rIrN)rr>ÚargsrPrrrrIs   zWeakValueDictionary.popcCs^z|j|ƒ}Wnty&d}Yn0|durV|jr>| ¡t||j|ƒ|j|<|S|SdSr))r?rNr<rLr\rD)rr>rgrPrrrÚ setdefaults  zWeakValueDictionary.setdefaultcKsz|jr| ¡|j}|durRt|dƒs.t|ƒ}| ¡D]\}}t||j|ƒ||<q6| ¡D]\}}t||j|ƒ||<qZdS©Nr`)r<rLr?ÚhasattrÚdictr`r\rD)rr2ÚkwargsrKr>rPrrrrF"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<rLÚlistr?rnrUrrrÚ valuerefs.s zWeakValueDictionary.valuerefscCs| |¡|Sr)©rFr1rrrÚ__ior__<s zWeakValueDictionary.__ior__cCs&t|tjƒr"| ¡}| |¡|StSr)©r.Ú_collections_abcÚMappingrbrFr0©rr2ÚcrrrÚ__or__@s   zWeakValueDictionary.__or__cCs0t|tjƒr,| ¡}| |¡| |¡|StSr)©r.r}r~r-rFr0rrrrÚ__ror__Gs    zWeakValueDictionary.__ror__)r)N)N)N)r4r5r6r7rHr rLrQrSrVrWr[r_rbÚ__copy__rfrhr`rlÚ__iter__rornrqrIrsrFryr{r�rƒrrrrr]s4          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*rH)rr‡rr>r,rrrHaszKeyedRef.__init__)r4r5r6r7r8r$rHr:rrr,rr\Ps r\c@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))r;r<r=r?rN)rjrArrrrrCrs  z*WeakKeyDictionary.__init__..removeF)r?rrDr<rEr;Ú _dirty_lenrF)rrvrCrrrrHps zWeakKeyDictionary.__init__cCsR|jj}|j}z |ƒ}Wnty,YdS0z ||=WqtyJYq0qdSr))r<rIr?rJrN)rrIrKr>rrrrL„s    z"WeakKeyDictionary._commit_removalscs&|j‰‡fdd„|jDƒ|_d|_dS)Ncsg|]}|ˆvr|‘qSrr)Ú.0rj©rKrrÚ ˜óz5WeakKeyDictionary._scrub_removals..F)r?r<rˆrUrrŠrÚ_scrub_removals–sz!WeakKeyDictionary._scrub_removalscCsd|_|jt|ƒ=dS©NT)rˆr?rrRrrrrS›szWeakKeyDictionary.__delitem__cCs|jt|ƒSr))r?rrRrrrrQŸszWeakKeyDictionary.__getitem__cCs(|jr|jr| ¡t|jƒt|jƒSr))rˆr<r�rTr?rUrrrrV¢s zWeakKeyDictionary.__len__cCsd|jjt|ƒfSrXrYrUrrrr[©szWeakKeyDictionary.__repr__cCs||jt||jƒ<dSr))r?rrDr]rrrr_¬szWeakKeyDictionary.__setitem__cCs\tƒ}t|ƒ�:|j ¡D]\}}|ƒ}|dur|||<qWdƒn1sN0Y|Sr))r r r?r`)rrar>r^rPrrrrb¯s (zWeakKeyDictionary.copycCspddlm}| ¡}t|ƒ�@|j ¡D]$\}}|ƒ}|dur(|||ƒ||<q(Wdƒn1sb0Y|Src)rbrdr-r r?r`)rrerdrar>r^rPrrrrfºs  .zWeakKeyDictionary.__deepcopy__cCs|j t|ƒ|¡Sr))r?rhr©rr>rgrrrrhÄszWeakKeyDictionary.getcCs,z t|ƒ}Wnty YdS0||jvSr)rr!r?)rr>r@rrrrWÇ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?rprrrrlÕs   zWeakKeyDictionary.keysccsPt|ƒ�4|j ¡D]\}}|ƒdur|VqWdƒn1sB0YdSr)r�)rr@r^rrrrnÞ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. )rxr?rUrrrÚkeyrefsäs zWeakKeyDictionary.keyrefscCs0d|_|j ¡\}}|ƒ}|dur||fSqdSrŽ)rˆr?rq)rr>r^rPrrrrqðs zWeakKeyDictionary.popitemcGsd|_|jjt|ƒg|¢RŽSrŽ)rˆr?rIr)rr>rrrrrrIøszWeakKeyDictionary.popcCs|j t||jƒ|¡Sr))r?rsrrDr�rrrrsüszWeakKeyDictionary.setdefaultcKs\|j}|durFt|dƒs$tiƒ|ƒ}| ¡D]\}}||t||jƒ<q,t|ƒrX| |¡dSrt)r?rur#r`rrDrTrF)rrvrwrKr>r^rrrrFÿs  zWeakKeyDictionary.updatecCs| |¡|Sr)rzr1rrrr{ s zWeakKeyDictionary.__ior__cCs&t|tjƒr"| ¡}| |¡|StSr)r|rrrrr� s   zWeakKeyDictionary.__or__cCs0t|tjƒr,| ¡}| |¡| |¡|StSr)r‚rrrrrƒs    zWeakKeyDictionary.__ror__)N)N)N)N)r4r5r6r7rHrLr�rSrQrVr[r_rbr„rfrhrWr`rlr…rnr‘rqrIrsrFr{r�rƒ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(rrrwÚatexitÚindexN)r4r5r6r8rrrrÚ_Info6sr•cOsp|js ddl}| |j¡dt_| ¡}t||ƒ|_||_||_ |pFd|_ d|_t |j ƒ|_ ||j|<dt_dS)NrT)Ú_registered_with_atexitr“ÚregisterÚ _exitfuncrr•rr’r(rrrwÚnextÚ _index_iterr”Ú _registryÚ_dirty)rr'r(rrrwr“ÚinforrrrH9s     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›rIÚ _shutdownr(rrrw)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›rhr’rIr(rrrw©rr�r'rrrÚdetachQs  zfinalize.detachcCs:|j |¡}|o| ¡}|dur6||j|j|jp2ifSdS)zMIf alive then return (obj, func, args, kwargs); otherwise return NoneN)r›rhr’r(rrrwr rrrÚpeekYs  z finalize.peekcCs ||jvS)zWhether finalizer is alive)r›rUrrrÚaliveaszfinalize.alivecCs|j |¡}t|ƒo|jS)z*Whether finalizer should be called at exit©r›rhÚ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›rhr’r#r4rZr rrrr[rs  ÿ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›ÚgcÚ isenabledÚdisablerrœr®rIÚ ExceptionÚsysÚ excepthookÚexc_inforžÚenable)r%Ú reenable_gcr¯Úpendingr§rrrr˜‚s2   þzfinalize._exitfunc)N)r4r5r6r7r8r›ržÚ itertoolsÚcountršrœr–r•rHr+r¡r¢Úpropertyr£r“Úsetterr[Ú classmethodr®r˜rrrrrs.      r)r7Ú_weakrefrrrrrrrr Ú _weakrefsetr r r}r³r¹r Ú__all__ÚSetr—Ú MutableSetrÚMutableMappingrr\r rrrrrÚs  (   6t9