????
Your IP : 3.17.177.21
B
� fT�
@s�dZddlmZmZmZmZmZmZmZm Z ddl
mZmZddl
Z
ddlZddlZeefZddddd d
ddd
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�finalizecsDeZdZdZdZddd�Z�fdd�Zdd �Zd
d�Ze j
Z
�ZS)
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__.<locals>._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�Zdd
�Z dd�Z
dd�Zdd�ZeZ
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|std��|^}}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__.<locals>.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)r6rGrrr9�items)r�newr8r:rIrrr�copy�s
zWeakValueDictionary.copyc Csnddlm}|jr|��|��}t|��:x2|j��D]$\}}|�}|dk r8|||||�<q8WWdQRX|S)Nr)�deepcopy)rUrVr6rGr(rr9rS)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)r6rGrr9rS)r�kr:�vrrrrS�s
zWeakValueDictionary.itemsc csN|jr|��t|��.x&|j��D]\}}|�dk r$|Vq$WWdQRXdS)N)r6rGrr9rS)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)r6rGrr9�values)rrrr�
itervaluerefs�s
z!WeakValueDictionary.itervaluerefsc csN|jr|��t|��.x&|j��D]}|�}|dk r$|Vq$WWdQRXdS)N)r6rGrr9r^)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�|std��|^}}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
�Zdd�Zd
d�Z dd�Z
dd�Zdd�ZeZ
dd�Zd,dd�Zdd�Zdd�Zdd�ZeZdd �Zd!d"�Zd#d$�Zd%d&�Zd-d'd(�Zd.d)d*�ZdS)/ra� 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__.<locals>.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�
<listcomp>�sz5WeakKeyDictionary._scrub_removals.<locals>.<listcomp>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�szWeakKeyDictionary.__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)rrr9rS)rrTr8rQrIrrrrU�s
zWeakKeyDictionary.copyc Cs`ddlm}|��}t|��:x2|j��D]$\}}|�}|dk r*|||�||<q*WWdQRX|S)Nr)rV)rUrVr(rr9rS)rrWrVrTr8rQrIrrrrX�s
zWeakKeyDictionary.__deepcopy__cCs|j�t|�|�S)N)r9rZr)rr8rYrrrrZ�szWeakKeyDictionary.getcCs,yt|�}Wntk
r dSX||jkS)NF)rrr9)rr8r:rrrrM�s
zWeakKeyDictionary.__contains__c csHt|��6x.|j��D] \}}|�}|dk r||fVqWWdQRXdS)N)rr9rS)rr:rQr8rrrrS�s
zWeakKeyDictionary.itemsc cs<t|��*x"|jD]}|�}|dk r|VqWWdQRXdS)N)rr9)rr:r$rrrr]�s
zWeakKeyDictionary.keysc cs@t|��.x&|j��D]\}}|�dk r|VqWWdQRXdS)N)rr9rS)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`�szWeakKeyDictionary.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@rrrrrYs.
c@s�eZdZdZdZiZdZe��Z dZ
dZGdd�d�Zdd�Z
dd d
�Zdd�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�_InfosrrcOst|�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�z<descriptor '__init__' of 'finalize' object needs an argumentr%z9finalize expected at least 2 positional arguments, got %dr4�r$rT)r=rrD�tuple�_registered_with_atexitrp�register� _exitfuncrrrrror%rArc�next�_index_iterrq� _registry�_dirty)rArcrr$r%rp�inforrrrCs:
zfinalize.__init__NcCs0|j�|d�}|r,|js,|j|j|jp(i�SdS)zZIf alive then mark as dead and return func(*args, **kwargs);
otherwise return NoneN)r{rD� _shutdownr%rArc)r�_r}rrrr'7s
zfinalize.__call__cCsH|j�|�}|o|��}|dk rD|j�|d�rD||j|j|jp@ifSdS)z^If alive then mark as dead and return (obj, func, args, kwargs);
otherwise return NoneN)r{rZrorDr%rArc)rr}r$rrr�detach>szfinalize.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�peekFsz
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}rrrrpSszfinalize.atexitcCs|j�|�}|rt|�|_dS)N)r{rZr�rp)rrQr}rrrrpYscCs^|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_szfinalize.__repr__cCs2dd�|j��D�}|jdd�d�dd�|D�S)NcSsg|]\}}|jr||f�qSr)rp)rk�f�irrrrlksz-finalize._select_for_exit.<locals>.<listcomp>cSs
|djS)Nr4)rq)�itemrrr�<lambda>l�z+finalize._select_for_exit.<locals>.<lambda>)r8cSsg|]\}}|�qSrr)rkr�r�rrrrlms)r{rS�sort)r#�Lrrr�_select_for_exithszfinalize._select_for_exitcCs�d}z�|jr�ddl}|��r(d}|��d}xj|dks<tjrJ|��}dt_|sPP|��}y
|�Wn"tk
r�t j
t ���YnX||jks.t�q.WWddt_
|r�|��XdS)NFrT)r{�gcZ isenabledZdisablerr|r�rD� Exception�sys�
excepthook�exc_info�AssertionErrorr~Zenable)r#Zreenable_gcr�Zpendingr�rrrrxos.
zfinalize._exitfunc)N)r-r.r/r0r1r{r~� itertools�countrzr|rvrrrCr'r�r��propertyr�rp�setterrO�classmethodr�rxrrrrr�s$%
)r0�_weakrefrrrrrrrr Z_weakrefsetr
r�_collections_abcr�r�r
�__all__r�MutableMappingrrPrrrrrr�<module>s"(
6k