Your IP : 3.147.52.243


Current Path : /lib64/python3.6/__pycache__/
Upload File :
Current File : //lib64/python3.6/__pycache__/weakref.cpython-36.pyc

3


 \�O�
@s�dZddlmZmZmZmZmZmZmZm	Z	ddl
mZmZddl
Z
ddlZddlZeefZddddd	d
ddd
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�fd	d
�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__Ncs~y|j}|j}Wn(tk
r8tdjt|���d�YnX��fdd�}tj|||�}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��/usr/lib64/python3.6/weakref.py�_cb3s
zWeakMethod.__new__.<locals>._cbT)�__self__�__func__�AttributeError�	TypeError�format�typer�__new__rrr)�cls�methr�obj�funcrrr)rrrr",s

zWeakMethod.__new__cs2t�j�}|j�}|dks"|dkr&dS|j||�S)N)�super�__call__rr)rr%r&)�	__class__rrr(Bs

zWeakMethod.__call__cCs>t|t�r:|js|jr"||kStj||�o8|j|jkSdS)NF)�
isinstancerrr�__eq__r)r�otherrrrr+Is

zWeakMethod.__eq__cCs>t|t�r:|js|jr"||k	Stj||�p8|j|jkSdS)NT)r*rrr�__ne__r)rr,rrrr-Ps

zWeakMethod.__ne__)rrrr)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�Zdd
�Z	dd�Z
dd�Zdd�ZeZ
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
    cst|std��|^}}t|�dkr0tdt|���t|�tf�fdd�	}||_g|_t�|_i|_�|j	||�dS)NzGdescriptor '__init__' of 'WeakValueDictionary' object needs an argument�z$expected at most 1 arguments, got %dcs4|�}|dk	r0|jr$|jj|j�n|�|j�dS)N)�
_iterating�_pending_removals�append�key)�wr�selfref�_atomic_removalr)�drr�removems
z,WeakValueDictionary.__init__.<locals>.remove)
r�lenrr	�_remover7�setr6�data�update)�args�kwrr>r)r=r�__init__fs	
zWeakValueDictionary.__init__cCs,|j}|j}x|r&|j�}t||�qWdS)N)r7rB�popr	)r�lr=r9rrr�_commit_removals}s
z$WeakValueDictionary._commit_removalscCs4|jr|j�|j|�}|dkr,t|��n|SdS)N)r7rIrB�KeyError)rr9�orrr�__getitem__�s
zWeakValueDictionary.__getitem__cCs|jr|j�|j|=dS)N)r7rIrB)rr9rrr�__delitem__�szWeakValueDictionary.__delitem__cCs|jr|j�t|j�S)N)r7rIr?rB)rrrr�__len__�szWeakValueDictionary.__len__cCs<|jr|j�y|j|�}Wntk
r2dSX|dk	S)NF)r7rIrBrJ)rr9rKrrr�__contains__�sz WeakValueDictionary.__contains__cCsd|jjt|�fS)Nz<%s at %#x>)r)r.�id)rrrr�__repr__�szWeakValueDictionary.__repr__cCs&|jr|j�t||j|�|j|<dS)N)r7rI�KeyedRefr@rB)rr9�valuerrr�__setitem__�szWeakValueDictionary.__setitem__cCsF|jr|j�t�}x,|jj�D]\}}|�}|dk	r |||<q W|S)N)r7rIrrB�items)r�newr9r:rKrrr�copy�szWeakValueDictionary.copycCsZddlm}|jr|j�|j�}x2|jj�D]$\}}|�}|dk	r.|||||�<q.W|S)Nr)�deepcopy)rWrXr7rIr)rBrU)r�memorXrVr9r:rKrrr�__deepcopy__�sz WeakValueDictionary.__deepcopy__NcCsL|jr|j�y|j|}Wntk
r0|SX|�}|dkrD|S|SdS)N)r7rIrBrJ)rr9�defaultr:rKrrr�get�szWeakValueDictionary.getc
csV|jr|j�t|��6x.|jj�D] \}}|�}|dk	r$||fVq$WWdQRXdS)N)r7rIrrBrU)r�kr:�vrrrrU�s
zWeakValueDictionary.itemsc
csN|jr|j�t|��.x&|jj�D]\}}|�dk	r$|Vq$WWdQRXdS)N)r7rIrrBrU)rr]r:rrr�keys�s

zWeakValueDictionary.keysc	cs6|jr|j�t|��|jj�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)r7rIrrB�values)rrrr�
itervaluerefs�s

z!WeakValueDictionary.itervaluerefsc
csN|jr|j�t|��.x&|jj�D]}|�}|dk	r$|Vq$WWdQRXdS)N)r7rIrrBr`)rr:r%rrrr`�s
zWeakValueDictionary.valuescCs<|jr|j�x(|jj�\}}|�}|dk	r||fSqWdS)N)r7rIrB�popitem)rr9r:rKrrrrb�szWeakValueDictionary.popitemcGs`|jr|j�y|jj|��}Wntk
r8d}YnX|dkrX|rN|dSt|��n|SdS)Nr)r7rIrBrGrJ)rr9rDrKrrrrGs

zWeakValueDictionary.popcCs`y|j|�}Wntk
r(d}YnX|dkrX|jr@|j�t||j|�|j|<|S|SdS)N)rBrJr7rIrRr@)rr9r[rKrrr�
setdefaults
zWeakValueDictionary.setdefaultcOs�|std��|^}}t|�dkr0tdt|���|r<|dnd}|jrN|j�|j}|dk	r�t|d�srti�|�}x&|j�D]\}}t||j	|�||<q|Wt|�r�|j
|�dS)NzEdescriptor 'update' of 'WeakValueDictionary' object needs an argumentr5z$expected at most 1 arguments, got %drrU)rr?r7rIrB�hasattrr!rUrRr@rC)rD�kwargsr�dictr=r9rKrrrrC s 
zWeakValueDictionary.updatecCs|jr|j�t|jj��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.

        )r7rI�listrBr`)rrrr�	valuerefs3s
zWeakValueDictionary.valuerefs)N)N)r.r/r0r1rFrIrLrMrNrOrQrTrW�__copy__rZr\rUr_�__iter__rar`rbrGrcrCrhrrrrrZs.			

			

cs,eZdZdZdZdd�Z�fdd�Z�ZS)rRa[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.

    r9cCstj|||�}||_|S)N)rr"r9)r!�obrr9rrrrr"NszKeyedRef.__new__cst�j||�dS)N)r'rF)rrkrr9)r)rrrFSszKeyedRef.__init__)r9)r.r/r0r1r2r"rFr4rr)r)rrRBsrRc@s�eZdZdZd+dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZeZ
dd�Zd,dd�Zdd�Zdd�Zdd�ZeZdd �Zd!d"�Zd#d$�Zd%d&�Zd-d'd(�Zd.d)d*�ZdS)/r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|_|dk	rB|j|�dS)NcSs.|�}|dk	r*|jr"|jj|�n|j|=dS)N)r6r7r8rB)r]r;rrrrr>ds
z*WeakKeyDictionary.__init__.<locals>.removeF)rBrr@r7rAr6�
_dirty_lenrC)rrfr>rrrrFbszWeakKeyDictionary.__init__cCs>|j}|j}x,|r8y||j�=Wqtk
r4YqXqWdS)N)r7rBrGrJ)rrHr=rrrrIssz"WeakKeyDictionary._commit_removalscs&|j��fdd�|jD�|_d|_dS)Ncsg|]}|�kr|�qSrr)�.0r])r=rr�
<listcomp>�sz5WeakKeyDictionary._scrub_removals.<locals>.<listcomp>F)rBr7rl)rr)r=r�_scrub_removals�sz!WeakKeyDictionary._scrub_removalscCsd|_|jt|�=dS)NT)rlrBr)rr9rrrrM�szWeakKeyDictionary.__delitem__cCs|jt|�S)N)rBr)rr9rrrrL�szWeakKeyDictionary.__getitem__cCs(|jr|jr|j�t|j�t|j�S)N)rlr7ror?rB)rrrrrN�szWeakKeyDictionary.__len__cCsd|jjt|�fS)Nz<%s at %#x>)r)r.rP)rrrrrQ�szWeakKeyDictionary.__repr__cCs||jt||j�<dS)N)rBrr@)rr9rSrrrrT�szWeakKeyDictionary.__setitem__cCs8t�}x,|jj�D]\}}|�}|dk	r|||<qW|S)N)rrBrU)rrVr9rSrKrrrrW�szWeakKeyDictionary.copycCsLddlm}|j�}x2|jj�D]$\}}|�}|dk	r |||�||<q W|S)Nr)rX)rWrXr)rBrU)rrYrXrVr9rSrKrrrrZ�szWeakKeyDictionary.__deepcopy__cCs|jjt|�|�S)N)rBr\r)rr9r[rrrr\�szWeakKeyDictionary.getcCs,yt|�}Wntk
r dSX||jkS)NF)rrrB)rr9r:rrrrO�s
zWeakKeyDictionary.__contains__c
csHt|��6x.|jj�D] \}}|�}|dk	r||fVqWWdQRXdS)N)rrBrU)rr:rSr9rrrrU�s

zWeakKeyDictionary.itemsc
cs<t|��*x"|jD]}|�}|dk	r|VqWWdQRXdS)N)rrB)rr:r%rrrr_�s

zWeakKeyDictionary.keysc
cs@t|��.x&|jj�D]\}}|�dk	r|VqWWdQRXdS)N)rrBrU)rr:rSrrrr`�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.

        )rgrB)rrrr�keyrefs�s
zWeakKeyDictionary.keyrefscCs4d|_x(|jj�\}}|�}|dk	r||fSqWdS)NT)rlrBrb)rr9rSrKrrrrb�szWeakKeyDictionary.popitemcGsd|_|jjt|�f|��S)NT)rlrBrGr)rr9rDrrrrG�szWeakKeyDictionary.popcCs|jjt||j�|�S)N)rBrcrr@)rr9r[rrrrc�szWeakKeyDictionary.setdefaultcKs`|j}|dk	rJt|d�s$ti�|�}x$|j�D]\}}||t||j�<q.Wt|�r\|j|�dS)NrU)rBrdr!rUrr@r?rC)rrfrer=r9rSrrrrC�s
zWeakKeyDictionary.update)N)N)N)N)r.r/r0r1rFrIrorMrLrNrQrTrWrirZr\rOrUr_rjr`rprbrGrcrCrrrrrWs.	

	

c@s�eZdZdZfZiZdZej�Z	dZ
dZGdd�d�Zdd�Z
ddd	�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.
    Fc@seZdZdZdS)	zfinalize._Info�weakrefr&rDre�atexit�indexN)rqr&rDrerrrs)r.r/r0r2rrrr�_InfosrtcOsp|js ddl}|j|j�dt_|j�}t||�|_||_||_	|pFd|_
d|_t|j�|_
||j|<dt_dS)NrT)�_registered_with_atexitrr�register�	_exitfuncrrtrrqr&rDre�next�_index_iterrs�	_registry�_dirty)rr%r&rDrerr�inforrrrFs

zfinalize.__init__NcCs2|jj|d�}|r.|jr.|j|j|jp*i�SdS)zZIf alive then mark as dead and return func(*args, **kwargs);
        otherwise return NoneN)rzrG�	_shutdownr&rDre)r�_r|rrrr(szfinalize.__call__cCsH|jj|�}|o|j�}|dk	rD|jj|d�rD||j|j|jp@ifSdS)z^If alive then mark as dead and return (obj, func, args, kwargs);
        otherwise return NoneN)rzr\rqrGr&rDre)rr|r%rrr�detach&szfinalize.detachcCs:|jj|�}|o|j�}|dk	r6||j|j|jp2ifSdS)zMIf alive then return (obj, func, args, kwargs);
        otherwise return NoneN)rzr\rqr&rDre)rr|r%rrr�peek.sz
finalize.peekcCs
||jkS)zWhether finalizer is alive)rz)rrrr�alive6szfinalize.alivecCs|jj|�}t|�o|jS)z*Whether finalizer should be called at exit)rzr\�boolrr)rr|rrrrr;szfinalize.atexitcCs|jj|�}|rt|�|_dS)N)rzr\r�rr)rrSr|rrrrrAscCs^|jj|�}|o|j�}|dkr6dt|�jt|�fSdt|�jt|�t|�jt|�fSdS)Nz<%s object at %#x; dead>z!<%s object at %#x; for %r at %#x>)rzr\rqr!r.rP)rr|r%rrrrQGszfinalize.__repr__cCs2dd�|jj�D�}|jdd�d�dd�|D�S)NcSsg|]\}}|jr||f�qSr)rr)rm�f�irrrrnSsz-finalize._select_for_exit.<locals>.<listcomp>cSs
|djS)Nr5)rs)�itemrrr�<lambda>Tsz+finalize._select_for_exit.<locals>.<lambda>)r9cSsg|]\}}|�qSrr)rmr�r�rrrrnUs)rzrU�sort)r#�Lrrr�_select_for_exitPszfinalize._select_for_exitcCs�d}z�|jr�ddl}|j�r(d}|j�d}xj|dks<tjrJ|j�}dt_|sPP|j�}y
|�Wn"tk
r�t	j
t	j��YnX||jks.t�q.WWddt_
|r�|j�XdS)NFrT)rz�gc�	isenabled�disablerr{r�rG�	Exception�sys�
excepthook�exc_info�AssertionErrorr}�enable)r#�reenable_gcr��pendingr�rrrrwWs.
zfinalize._exitfunc)N)r.r/r0r1r2rzr}�	itertools�countryr{rurtrFr(rr��propertyr�rr�setterrQ�classmethodr�rwrrrrr�s$
	)r1�_weakrefrrrrrrrr	�_weakrefsetr
r�collectionsr�r�r
�__all__r�MutableMappingrrRrrrrrr�<module>s"(

6i

?>