AlkantarClanX12

Your IP : 3.138.170.67


Current Path : /opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/__pycache__/weakref.cpython-35.pyc



��Yf�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�finalizecs^eZdZdZdZddd�Z�fd	d
�Zdd�Zd
d�Ze	j
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__Ncs�y|j}|j}Wn0tk
rHtdjt|���d�YnX��fdd�}tj|||�}t||�|_t|�|_	d|_
t|��|S)Nz)argument should be a bound method, not {}cs5��}|jr1d|_�dk	r1�|�dS)NF)r)�arg�self)�callback�self_wr��,/opt/alt/python35/lib64/python3.5/weakref.py�_cb3s
			zWeakMethod.__new__.<locals>._cbT)�__self__�__func__�AttributeError�	TypeError�format�typer�__new__rrr)�cls�methr�obj�funcrrr)rrrr",s	

		zWeakMethod.__new__csGt�j�}|j�}|dks3|dkr7dS|j||�S)N)�super�__call__rr)rr%r&)�	__class__rrr(Bs
zWeakMethod.__call__cCsSt|t�rO|js#|jr-||kStj||�oN|j|jkSdS)NF)�
isinstancerrr�__eq__r)r�otherrrrr+Is

"zWeakMethod.__eq__cCsSt|t�rO|js#|jr-||k	Stj||�pN|j|jkSdS)NT)r*rrr�__ne__r)rr,rrrr-Ps

"zWeakMethod.__ne__)rrrr)�__name__�
__module__�__qualname__�__doc__�	__slots__r"r(r+r-r�__hash__rr)r)rr$sc@seZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZeZ
dd�Zddd�Zdd�Zdd�ZeZdd�Zdd �Zd!d"�Zd#d$�Zdd%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
    cs�|std��|^}}t|�dkrFtdt|���t|�t�fdd�}||_g|_t�|_i|_�|j	||�dS)NzGdescriptor '__init__' of 'WeakValueDictionary' object needs an argument�z$expected at most 1 arguments, got %dcsH|�}|dk	rD|jr4|jj|j�n|�|j�dS)N)�
_iterating�_pending_removals�append�key)�wr�selfref�_atomic_removalr)�drr�removems
		z,WeakValueDictionary.__init__.<locals>.remove)
r�lenrr	�_remover6�setr5�data�update)�args�kwrr=r)r<r�__init__fs			
zWeakValueDictionary.__init__cCs<|j}|j}x#|r7|j�}t||�qWdS)N)r6rA�popr	)r�lr<r8rrr�_commit_removals}s
			z$WeakValueDictionary._commit_removalscCsF|jr|j�|j|�}|dkr>t|��n|SdS)N)r6rHrA�KeyError)rr8�orrr�__getitem__�s	
zWeakValueDictionary.__getitem__cCs!|jr|j�|j|=dS)N)r6rHrA)rr8rrr�__delitem__�s	
zWeakValueDictionary.__delitem__cCs |jr|j�t|j�S)N)r6rHr>rA)rrrr�__len__�s	
zWeakValueDictionary.__len__cCsJ|jr|j�y|j|�}Wntk
r?dSYnX|dk	S)NF)r6rHrArI)rr8rJrrr�__contains__�s	

	z WeakValueDictionary.__contains__cCsd|jjt|�fS)Nz<%s at %#x>)r)r.�id)rrrr�__repr__�szWeakValueDictionary.__repr__cCs3|jr|j�t||j|�|j|<dS)N)r6rH�KeyedRefr?rA)rr8�valuerrr�__setitem__�s	
zWeakValueDictionary.__setitem__cCs_|jr|j�t�}x<|jj�D]+\}}|�}|dk	r,|||<q,W|S)N)r6rHrrA�items)r�newr8r9rJrrr�copy�s	
		zWeakValueDictionary.copycCs{ddlm}|jr#|j�|j�}xE|jj�D]4\}}|�}|dk	r?|||||�<q?W|S)Nr)�deepcopy)rVrWr6rHr)rArT)r�memorWrUr8r9rJrrr�__deepcopy__�s	
	z WeakValueDictionary.__deepcopy__NcCs^|jr|j�y|j|}Wntk
r<|SYnX|�}|dkrV|S|SdS)N)r6rHrArI)rr8�defaultr9rJrrr�get�s	

		zWeakValueDictionary.getc
csk|jr|j�t|��Ex=|jj�D],\}}|�}|dk	r0||fVq0WWdQRXdS)N)r6rHrrArT)r�kr9�vrrrrT�s	

	zWeakValueDictionary.itemsc
cs_|jr|j�t|��9x1|jj�D] \}}|�dk	r0|Vq0WWdQRXdS)N)r6rHrrArT)rr\r9rrr�keys�s	

zWeakValueDictionary.keysc	cs=|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)r6rHrrA�values)rrrr�
itervaluerefs�s
	

z!WeakValueDictionary.itervaluerefsc
cs_|jr|j�t|��9x1|jj�D] }|�}|dk	r0|Vq0WWdQRXdS)N)r6rHrrAr_)rr9r%rrrr_�s	

	zWeakValueDictionary.valuescCsR|jr|j�x8|jj�\}}|�}|dk	r||fSqWdS)N)r6rHrA�popitem)rr8r9rJrrrra�s	
	zWeakValueDictionary.popitemcGsx|jr|j�y|jj|��}Wntk
rFd}YnX|dkrp|ra|dSt|��n|SdS)Nr)r6rHrArFrI)rr8rCrJrrrrFs	

zWeakValueDictionary.popcCsvy|j|�}Wntk
r.d}YnX|dkrn|jrN|j�t||j|�|j|<|S|SdS)N)rArIr6rHrQr?)rr8rZrJrrr�
setdefaults
	
zWeakValueDictionary.setdefaultcOs�|std��|^}}t|�dkrFtdt|���|rV|dnd}|jro|j�|j}|dk	r�t|d�s�ti�|�}x3|j�D]%\}}t||j	|�||<q�Wt|�r�|j
|�dS)NzEdescriptor 'update' of 'WeakValueDictionary' object needs an argumentr4z$expected at most 1 arguments, got %drrT)rr>r6rHrA�hasattrr!rTrQr?rB)rC�kwargsr�dictr<r8rJrrrrB 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.

        )r6rH�listrAr_)rrrr�	valuerefs3s
	
zWeakValueDictionary.valuerefs)r.r/r0r1rErHrKrLrMrNrPrSrV�__copy__rYr[rTr^�__iter__r`r_rarFrbrBrgrrrrrZs.			
			
cs:eZdZdZdZdd�Z�fdd�Z�S)rQa[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.

    r8cCs"tj|||�}||_|S)N)rr"r8)r!�obrr8rrrrr"Ns	zKeyedRef.__new__cst�j||�dS)N)r'rE)rrjrr8)r)rrrESszKeyedRef.__init__)r8)r.r/r0r1r2r"rErr)r)rrQBsrQc@seZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZeZ
dd�Zddd�Zdd�Zdd�Zdd�ZeZdd �Zd!d"�Zd#d$�Zd%d&�Zdd'd(�Zdd)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.
    NcCsbi|_t|�dd�}||_g|_t�|_d|_|dk	r^|j|�dS)NcSs?|�}|dk	r;|jr1|jj|�n
|j|=dS)N)r5r6r7rA)r\r:rrrrr=ds
		z*WeakKeyDictionary.__init__.<locals>.removeF)rArr?r6r@r5�
_dirty_lenrB)rrer=rrrrEbs				zWeakKeyDictionary.__init__cCsI|j}|j}x0|rDy||j�=Wqtk
r@YqXqWdS)N)r6rArFrI)rrGr<rrrrHss			
z"WeakKeyDictionary._commit_removalscs5|j��fdd�|jD�|_d|_dS)Ncs"g|]}|�kr|�qSrr)�.0r\)r<rr�
<listcomp>�s	z5WeakKeyDictionary._scrub_removals.<locals>.<listcomp>F)rAr6rk)rr)r<r�_scrub_removals�s	z!WeakKeyDictionary._scrub_removalscCsd|_|jt|�=dS)NT)rkrAr)rr8rrrrL�s	zWeakKeyDictionary.__delitem__cCs|jt|�S)N)rAr)rr8rrrrK�szWeakKeyDictionary.__getitem__cCs6|jr|jr|j�t|j�t|j�S)N)rkr6rnr>rA)rrrrrM�s
zWeakKeyDictionary.__len__cCsd|jjt|�fS)Nz<%s at %#x>)r)r.rO)rrrrrP�szWeakKeyDictionary.__repr__cCs||jt||j�<dS)N)rArr?)rr8rRrrrrS�szWeakKeyDictionary.__setitem__cCsLt�}x<|jj�D]+\}}|�}|dk	r|||<qW|S)N)rrArT)rrUr8rRrJrrrrV�s		zWeakKeyDictionary.copycCshddlm}|j�}xE|jj�D]4\}}|�}|dk	r,|||�||<q,W|S)Nr)rW)rVrWr)rArT)rrXrWrUr8rRrJrrrrY�s	zWeakKeyDictionary.__deepcopy__cCs|jjt|�|�S)N)rAr[r)rr8rZrrrr[�szWeakKeyDictionary.getcCs6yt|�}Wntk
r(dSYnX||jkS)NF)rrrA)rr8r9rrrrN�s

	zWeakKeyDictionary.__contains__c
csXt|��Ex=|jj�D],\}}|�}|dk	r||fVqWWdQRXdS)N)rrArT)rr9rRr8rrrrT�s

	zWeakKeyDictionary.itemsc
csFt|��3x+|jD] }|�}|dk	r|VqWWdQRXdS)N)rrA)rr9r%rrrr^�s

	zWeakKeyDictionary.keysc
csLt|��9x1|jj�D] \}}|�dk	r|VqWWdQRXdS)N)rrArT)rr9rRrrrr_�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.

        )rfrA)rrrr�keyrefs�s
zWeakKeyDictionary.keyrefscCsHd|_x8|jj�\}}|�}|dk	r||fSqWdS)NT)rkrAra)rr8rRrJrrrra�s		zWeakKeyDictionary.popitemcGs"d|_|jjt|�|�S)NT)rkrArFr)rr8rCrrrrF�s	zWeakKeyDictionary.popcCs|jjt||j�|�S)N)rArbrr?)rr8rZrrrrb�szWeakKeyDictionary.setdefaultcKs�|j}|dk	rit|d�s6ti�|�}x0|j�D]"\}}||t||j�<qCWt|�r�|j|�dS)NrT)rArcr!rTrr?r>rB)rrerdr<r8rRrrrrB�s	zWeakKeyDictionary.update)r.r/r0r1rErHrnrLrKrMrPrSrVrhrYr[rNrTr^rir_rorarFrbrBrrrrr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&rCrd�atexit�indexN)rpr&rCrdrqrr)r.r/r0r2rrrr�_InfosrscOs�|js.ddl}|j|j�dt_|j�}t||�|_||_||_	|pgd|_
d|_t|j�|_
||j|<dt_dS)NrT)�_registered_with_atexitrq�register�	_exitfuncrrsrrpr&rCrd�next�_index_iterrr�	_registry�_dirty)rr%r&rCrdrq�inforrrrEs					
zfinalize.__init__NcCsE|jj|d�}|rA|jrA|j|j|jp=i�SdS)zZIf alive then mark as dead and return func(*args, **kwargs);
        otherwise return NoneN)ryrF�	_shutdownr&rCrd)r�_r{rrrr(szfinalize.__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)ryr[rprFr&rCrd)rr{r%rrr�detach&s!zfinalize.detachcCsS|jj|�}|o!|j�}|dk	rO||j|j|jpKifSdS)zMIf alive then return (obj, func, args, kwargs);
        otherwise return NoneN)ryr[rpr&rCrd)rr{r%rrr�peek.sz
finalize.peekcCs
||jkS)zWhether finalizer is alive)ry)rrrr�alive6szfinalize.alivecCs%|jj|�}t|�o$|jS)z*Whether finalizer should be called at exit)ryr[�boolrq)rr{rrrrq;szfinalize.atexitcCs+|jj|�}|r't|�|_dS)N)ryr[r�rq)rrRr{rrrrqAscCs�|jj|�}|o!|j�}|dkrMdt|�jt|�fSdt|�jt|�t|�jt|�fSdS)Nz<%s object at %#x; dead>z!<%s object at %#x; for %r at %#x>)ryr[rpr!r.rO)rr{r%rrrrPGszfinalize.__repr__cCsCdd�|jj�D�}|jddd��dd�|D�S)NcSs+g|]!\}}|jr||f�qSr)rq)rl�f�irrrrmSs	z-finalize._select_for_exit.<locals>.<listcomp>r8cSs|djS)Nr4)rr)�itemrrr�<lambda>Tsz+finalize._select_for_exit.<locals>.<lambda>cSsg|]\}}|�qSrr)rlr�r�rrrrmUs	)ryrT�sort)r#�Lrrr�_select_for_exitPszfinalize._select_for_exitcCs�d}z�|jr�ddl}|j�r:d}|j�d}x�|dksXtjrm|j�}dt_|stP|j�}y|�Wn%tk
r�t	j
t	j��YnX||jksCt�qCWWddt_
|r�|j�XdS)NFrT)ry�gc�	isenabled�disablerrzr�rF�	Exception�sys�
excepthook�exc_info�AssertionErrorr|�enable)r#�reenable_gcr��pendingr�rrrrvWs.	
	
	zfinalize._exitfunc)r.r/r0r1r2ryr|�	itertools�countrxrzrtrsrEr(r~r�propertyr�rq�setterrP�classmethodr�rvrrrrr�s$	)r1�_weakrefrrrrrrrr	�_weakrefsetr
r�collectionsr�r�r
�__all__r�MutableMappingrrQrrrrrr�<module>s:
		6��