a �DOg8T�@s�ddlmZmZmZmZmZmZmZmZddl m Z m Z ddl Z ddl Z ddlZeefZgd�Ze j�e �e j�e �Gdd�de�ZGdd�de j�ZGd d �d e�ZGd d �d e j�ZGd d�d�ZdS)�)�getweakrefcount� getweakrefs�ref�proxy�CallableProxyType� ProxyType� ReferenceType�_remove_dead_weakref)�WeakSet�_IterationGuardN) rrrr�WeakKeyDictionaryrrr� ProxyTypes�WeakValueDictionaryr � WeakMethod�finalizecs@eZdZdZd dd�Z�fdd�Zdd�Zd d �Zej Z �Z S) r)� _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__� __slots__r$r+r/r3r�__hash__� __classcell__rrr,rr's   rc@s�eZdZd1dd�Zefdd�Zdd�Zdd �Zd d �Zd d �Z dd�Z dd�Z dd�Z e Z dd�Zd2dd�Zdd�Zdd�ZeZdd�Zdd �Zd!d"�Zd#d$�Zd3d%d&�Zd4d'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�ZdS)5rrcKsBt|�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�kwrBrrr�__init__is  zWeakValueDictionary.__init__cCs>|jj}|j}z |�}Wnty,YdS0|||�qdSr))r;�popr>� IndexError)rrArH�dr=rrr�_commit_removalszs  z$WeakValueDictionary._commit_removalscCs4|jr|��|j|�}|dur,t|��n|SdSr)�r;rKr>�KeyError�rr=�orrr� __getitem__�s   zWeakValueDictionary.__getitem__cCs|jr|��|j|=dSr))r;rKr>�rr=rrr� __delitem__�szWeakValueDictionary.__delitem__cCs|jr|��t|j�Sr))r;rK�lenr>�rrrr�__len__�szWeakValueDictionary.__len__cCs<|jr|��z|j|�}Wnty2YdS0|duSrrLrNrrr� __contains__�s z WeakValueDictionary.__contains__cCsd|jjt|�fS�Nz <%s at %#x>�r-r4�idrTrrr�__repr__�szWeakValueDictionary.__repr__cCs&|jr|��t||j|�|j|<dSr))r;rK�KeyedRefrCr>�rr=�valuerrr� __setitem__�szWeakValueDictionary.__setitem__cCsj|jr|��t�}t|��:|j��D]\}}|�}|dur(|||<q(Wd�n1s\0Y|Sr))r;rKrr r>�items)r�newr=r?rOrrr�copy�s (zWeakValueDictionary.copycCs~ddlm}|jr|��|��}t|��@|j��D]$\}}|�}|dur6|||||�<q6Wd�n1sp0Y|S�Nr)�deepcopy)rarcr;rKr-r r>r_)r�memorcr`r=r?rOrrr� __deepcopy__�s  .z WeakValueDictionary.__deepcopy__NcCsN|jr|��z|j|}Wnty2|YS0|�}|durF|S|SdSr)rL)rr=�defaultr?rOrrr�get�s  zWeakValueDictionary.getccsf|jr|��t|��<|j��D] \}}|�}|dur"||fVq"Wd�n1sX0YdSr)�r;rKr r>r_)r�kr?�vrrrr_�s zWeakValueDictionary.itemsccs^|jr|��t|��4|j��D]\}}|�dur"|Vq"Wd�n1sP0YdSr)rh)rrir?rrr�keys�s   zWeakValueDictionary.keysccsJ|jr|��t|�� |j��EdHWd�n1s<0YdSr)�r;rKr r>�valuesrTrrr� itervaluerefs�s  z!WeakValueDictionary.itervaluerefsccs^|jr|��t|��4|j��D]}|�}|dur"|Vq"Wd�n1sP0YdSr)rl�rr?r'rrrrm�s zWeakValueDictionary.valuescCs8|jr|��|j��\}}|�}|dur||fSqdSr))r;rKr>�popitem)rr=r?rOrrrrp�s zWeakValueDictionary.popitemcGs^|jr|��z|j�|��}Wnty6d}Yn0|durV|rL|dSt|��n|SdS)Nr)r;rKr>rHrM)rr=�argsrOrrrrHs   zWeakValueDictionary.popcCs^z|j|�}Wnty&d}Yn0|durV|jr>|��t||j|�|j|<|S|SdSr))r>rMr;rKr[rC)rr=rfrOrrr� setdefaults  zWeakValueDictionary.setdefaultcKsz|jr|��|j}|durRt|d�s.t|�}|��D]\}}t||j|�||<q6|��D]\}}t||j|�||<qZdS�Nr_)r;rKr>�hasattr�dictr_r[rC)rr2�kwargsrJr=rOrrrrE"s zWeakValueDictionary.updatecCs|jr|��t|j���Sr))r;rK�listr>rmrTrrr� valuerefs.s zWeakValueDictionary.valuerefscCs|�|�|Sr)�rEr1rrr�__ior__<s zWeakValueDictionary.__ior__cCs&t|tj�r"|��}|�|�|StSr)�r.�_collections_abc�MappingrarEr0�rr2�crrr�__or__@s   zWeakValueDictionary.__or__cCs0t|tj�r,|��}|�|�|�|�|StSr)�r.r|r}r-rEr0r~rrr�__ror__Gs    zWeakValueDictionary.__ror__)r)N)N)N)r4r5r6rGr rKrPrRrUrVrZr^ra�__copy__rergr_rk�__iter__rnrmrprHrrrErxrzr�r�rrrrr]s2          rcs(eZdZdZdd�Z�fdd�Z�ZS)r[�r=cCst�|||�}||_|Sr))rr$r=)r#�obrr=rrrrr$\szKeyedRef.__new__cst��||�dSr))r*rG)rr�rr=r,rrrGaszKeyedRef.__init__)r4r5r6r7r$rGr9rrr,rr[Ps r[c@s�eZdZd0dd�Zdd�Zdd�Zdd �Zd d �Zd d �Zdd�Z dd�Z dd�Z e Z dd�Z d1dd�Zdd�Zdd�Zdd�ZeZdd�Zd d!�Zd"d#�Zd$d%�Zd2d&d'�Zd3d(d)�Zd*d+�Zd,d-�Zd.d/�ZdS)4r NcCsFi|_t|�fdd�}||_g|_t�|_d|_|durB|�|�dS)NcSsF|�}|durB|jr"|j�|�n z |j|=Wnty@Yn0dSr))r:r;r<r>rM)rir@rrrrrBrs  z*WeakKeyDictionary.__init__..removeF)r>rrCr;rDr:� _dirty_lenrE)rrurBrrrrGps zWeakKeyDictionary.__init__cCsR|jj}|j}z |�}Wnty,YdS0z ||=WqtyJYq0qdSr))r;rHr>rIrM)rrHrJr=rrrrK�s    z"WeakKeyDictionary._commit_removalscs&|j��fdd�|jD�|_d|_dS)Ncsg|]}|�vr|�qSrr)�.0ri�rJrr� ��z5WeakKeyDictionary._scrub_removals..F)r>r;r�rTrr�r�_scrub_removals�sz!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__cCsd|jjt|�fSrWrXrTrrrrZ�szWeakKeyDictionary.__repr__cCs||jt||j�<dSr))r>rrCr\rrrr^�szWeakKeyDictionary.__setitem__cCs\t�}t|��:|j��D]\}}|�}|dur|||<qWd�n1sN0Y|Sr))r r r>r_)rr`r=r]rOrrrra�s (zWeakKeyDictionary.copycCspddlm}|��}t|��@|j��D]$\}}|�}|dur(|||�||<q(Wd�n1sb0Y|Srb)rarcr-r r>r_)rrdrcr`r=r]rOrrrre�s  .zWeakKeyDictionary.__deepcopy__cCs|j�t|�|�Sr))r>rgr�rr=rfrrrrg�szWeakKeyDictionary.getcCs,z t|�}Wnty YdS0||jvSr)rr!r>)rr=r?rrrrV�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>rorrrrk�s   zWeakKeyDictionary.keysccsPt|��4|j��D]\}}|�dur|VqWd�n1sB0YdSr)r�)rr?r]rrrrm�s  zWeakKeyDictionary.valuescCs t|j�Sr))rwr>rTrrr�keyrefs�s zWeakKeyDictionary.keyrefscCs0d|_|j��\}}|�}|dur||fSqdSr�)r�r>rp)rr=r]rOrrrrp�s zWeakKeyDictionary.popitemcGsd|_|jjt|�g|�R�Sr�)r�r>rHr)rr=rqrrrrH�szWeakKeyDictionary.popcCs|j�t||j�|�Sr))r>rrrrCr�rrrrr�szWeakKeyDictionary.setdefaultcKs\|j}|durFt|d�s$ti�|�}|��D]\}}||t||j�<q,t|�rX|�|�dSrs)r>rtr#r_rrCrSrE)rrurvrJr=r]rrrrE�s  zWeakKeyDictionary.updatecCs|�|�|Sr)ryr1rrrrz s zWeakKeyDictionary.__ior__cCs&t|tj�r"|��}|�|�|StSr)r{r~rrrr� s   zWeakKeyDictionary.__or__cCs0t|tj�r,|��}|�|�|�|�|StSr)r�r~rrrr�s    zWeakKeyDictionary.__ror__)N)N)N)N)r4r5r6rGrKr�rRrPrUrZr^rar�rergrVr_rkr�rmr�rprHrrrErzr�r�rrrrr es2      r c@s�eZdZdZiZdZe��ZdZ dZ Gdd�d�Z dd�Z ddd �Z d d �Zd d �Zedd��Zedd��Zejdd��Zdd�Zedd��Zedd��ZdS)rrFc@seZdZdZdS)zfinalize._Info)�weakrefr(rqrv�atexit�indexN)r4r5r6r7rrrr�_Info6sr�cOsp|js ddl}|�|j�dt_|��}t||�|_||_||_ |pFd|_ d|_t |j �|_ ||j|<dt_dS)NrT)�_registered_with_atexitr��register� _exitfuncrr�rr�r(rqrv�next� _index_iterr�� _registry�_dirty)rr'r(rqrvr��inforrrrG9s     zfinalize.__init__NcCs4|j�|d�}|r0|js0|j|ji|jp*i��SdSr))r�rH� _shutdownr(rqrv)r�_r�rrrr+Js zfinalize.__call__cCsH|j�|�}|o|��}|durD|j�|d�rD||j|j|jp@ifSdSr))r�rgr�rHr(rqrv�rr�r'rrr�detachQs  zfinalize.detachcCs:|j�|�}|o|��}|dur6||j|j|jp2ifSdSr))r�rgr�r(rqrvr�rrr�peekYs  z finalize.peekcCs ||jvSr))r�rTrrr�aliveaszfinalize.alivecCs|j�|�}t|�o|jSr)�r�rg�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�rgr�r#r4rYr�rrrrZrs  �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 |�Wq,ty�t j t � ��Yq,0q,Wdt_ |r�|� �ndt_ |r�|� �0dS)NFrT)r��gc� isenabled�disablerr�r�rH� Exception�sys� excepthook�exc_infor��enable)r%� reenable_gcr��pendingr�rrrr��s2   �zfinalize._exitfunc)N)r4r5r6r7r�r�� itertools�countr�r�r�r�rGr+r�r��propertyr�r��setterrZ� classmethodr�r�rrrrrs,      r)�_weakrefrrrrrrrr � _weakrefsetr r r|r�r�r �__all__�Setr�� MutableSetr�MutableMappingrr[r rrrrr� s(   6t9