AlkantarClanX12

Your IP : 52.15.238.221


Current Path : /opt/alt/python34/lib64/python3.4/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/__pycache__/weakref.cpython-34.pyo

�
h f�K�
@s"dZddlmZmZmZmZmZmZmZddl	m
Z
mZddlZddl
Z
ddlZeefZddddd	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)�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 {}cs;��}|jr7d|_�dk	r7�|�q7ndS)NF)r)�arg�self)�callback�self_wr��,/opt/alt/python34/lib64/python3.4/weakref.py�_cb2s
			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'As
zWeakMethod.__call__cCsSt|t�rO|js#|jr-||kStj||�oN|j|jkSdS)NF)�
isinstancerrr�__eq__r)r�otherrrrr*Hs

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

"zWeakMethod.__ne__)z	_func_refz
_meth_typez_alivez__weakref__)�__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)+r
z�Mapping class that references values weakly.

    Entries in the dictionary will be discarded when no strong
    reference to the value exists anymore
    cOs�|std��n|^}}t|�dkrLtdt|���nt|�dd�}||_g|_t�|_i|_}|j||�dS)NzGdescriptor '__init__' of 'WeakValueDictionary' object needs an argument�z$expected at most 1 arguments, got %dcSsH|�}|dk	rD|jr4|jj|j�qD|j|j=ndS)N)�
_iterating�_pending_removals�append�key�data)�wr�selfrefrrrr�removels
		z,WeakValueDictionary.__init__.<locals>.remove)	r�lenr�_remover5�setr4r8�update)�args�kwrr;�drrr�__init__es		
zWeakValueDictionary.__init__cCs0|j}|j}x|r+||j�=qWdS)N)r5r8�pop)r�lrBrrr�_commit_removalszs			z$WeakValueDictionary._commit_removalscCs3|j|�}|dkr+t|��n|SdS)N)r8�KeyError)rr7�orrr�__getitem__�szWeakValueDictionary.__getitem__cCs$|jr|j�n|j|=dS)N)r5rFr8)rr7rrr�__delitem__�s	
zWeakValueDictionary.__delitem__cCst|j�t|j�S)N)r<r8r5)rrrr�__len__�szWeakValueDictionary.__len__cCs7y|j|�}Wntk
r,dSYnX|dk	S)NF)r8rG)rr7rHrrr�__contains__�s

	z WeakValueDictionary.__contains__cCsdt|�S)Nz<WeakValueDictionary at %s>)�id)rrrr�__repr__�szWeakValueDictionary.__repr__cCs6|jr|j�nt||j|�|j|<dS)N)r5rF�KeyedRefr=r8)rr7�valuerrr�__setitem__�s	
zWeakValueDictionary.__setitem__cCsOt�}x?|jj�D].\}}|�}|dk	r|||<qqW|S)N)r
r8�items)r�newr7r9rHrrr�copy�s		zWeakValueDictionary.copycCskddlm}|j�}xH|jj�D]7\}}|�}|dk	r,|||||�<q,q,W|S)Nr)�deepcopy)rTrUr(r8rR)r�memorUrSr7r9rHrrr�__deepcopy__�s	z WeakValueDictionary.__deepcopy__NcCsKy|j|}Wntk
r)|SYnX|�}|dkrC|S|SdS)N)r8rG)rr7�defaultr9rHrrr�get�s
		zWeakValueDictionary.getc
csZt|��Hx@|jj�D]/\}}|�}|dk	r||fVqqWWdQXdS)N)r
r8rR)r�kr9�vrrrrR�s

	zWeakValueDictionary.itemsc
csNt|��<x4|jj�D]#\}}|�dk	r|VqqWWdQXdS)N)r
r8rR)rrZr9rrr�keys�s
zWeakValueDictionary.keysc	cs)t|��|jj�DdHWdQXdS)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
r8�values)rrrr�
itervaluerefs�s

z!WeakValueDictionary.itervaluerefsc
csNt|��<x4|jj�D]#}|�}|dk	r|VqqWWdQXdS)N)r
r8r])rr9r$rrrr]�s

	zWeakValueDictionary.valuescCsU|jr|j�nx8|jj�\}}|�}|dk	r||fSqWdS)N)r5rFr8�popitem)rr7r9rHrrrr_�s	
	zWeakValueDictionary.popitemcGsx|jr|j�ny|jj|��}Wn#tk
rT|rM|dS�YnX|dkrpt|��n|SdS)Nr)r5rFr8rDrG)rr7r@rHrrrrD�s	

zWeakValueDictionary.popcCsgy|j|}WnHtk
r[|jr7|j�nt||j|�|j|<|SYnX|�SdS)N)r8rGr5rFrOr=)rr7rXr9rrr�
setdefault�s
	
	zWeakValueDictionary.setdefaultcOs
|std��n|^}}t|�dkrLtdt|���n|r\|dnd}|jrx|j�n|j}|dk	r�t|d�s�ti�|�}nx6|j�D]%\}}t||j	|�||<q�Wnt|�r|j
|�ndS)NzEdescriptor 'update' of 'WeakValueDictionary' object needs an argumentr3z$expected at most 1 arguments, got %drrR)rr<r5rFr8�hasattrr rRrOr=r?)r@�kwargsr�dictrBr7rHrrrr?s 	
	 zWeakValueDictionary.updatecCst|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.

        )�listr8r])rrrr�	valuerefss
zWeakValueDictionary.valuerefs)r-r.r/r0rCrFrIrJrKrLrNrQrT�__copy__rWrYrRr\�__iter__r^r]r_rDr`r?rerrrrr
Ys.	

	cs:eZdZdZdZdd�Z�fdd�Z�S)rOa[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.

    r7cCs"tj|||�}||_|S)N)rr!r7)r �obrr7rrrrr!1s	zKeyedRef.__new__cst�j||�dS)N)r&rC)rrhrr7)r(rrrC6szKeyedRef.__init__)zkey)r-r.r/r0r1r!rCrr)r(rrO%srOc@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)+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.
    NcCsei|_t|�dd�}||_g|_t�|_d|_|dk	ra|j|�ndS)NcSsB|�}|dk	r>|jr1|jj|�q>|j|=ndS)N)r4r5r6r8)rZr:rrrrr;Gs
		z*WeakKeyDictionary.__init__.<locals>.removeF)r8rr=r5r>r4�
_dirty_lenr?)rrcr;rrrrCEs				zWeakKeyDictionary.__init__cCsI|j}|j}x0|rDy||j�=Wqtk
r@YqXqWdS)N)r5r8rDrG)rrErBrrrrFVs			
z"WeakKeyDictionary._commit_removalscs5|j��fdd�|jD�|_d|_dS)Ncs"g|]}|�kr|�qSrr)�.0rZ)rBrr�
<listcomp>es	z5WeakKeyDictionary._scrub_removals.<locals>.<listcomp>F)r8r5ri)rr)rBr�_scrub_removalscs	z!WeakKeyDictionary._scrub_removalscCsd|_|jt|�=dS)NT)rir8r)rr7rrrrJhs	zWeakKeyDictionary.__delitem__cCs|jt|�S)N)r8r)rr7rrrrIlszWeakKeyDictionary.__getitem__cCs9|jr|jr|j�nt|j�t|j�S)N)rir5rlr<r8)rrrrrKos
zWeakKeyDictionary.__len__cCsdt|�S)Nz<WeakKeyDictionary at %s>)rM)rrrrrNvszWeakKeyDictionary.__repr__cCs||jt||j�<dS)N)r8rr=)rr7rPrrrrQyszWeakKeyDictionary.__setitem__cCsOt�}x?|jj�D].\}}|�}|dk	r|||<qqW|S)N)rr8rR)rrSr7rPrHrrrrT|s		zWeakKeyDictionary.copycCskddlm}|j�}xH|jj�D]7\}}|�}|dk	r,|||�||<q,q,W|S)Nr)rU)rTrUr(r8rR)rrVrUrSr7rPrHrrrrW�s	zWeakKeyDictionary.__deepcopy__cCs|jjt|�|�S)N)r8rYr)rr7rXrrrrY�szWeakKeyDictionary.getcCs6yt|�}Wntk
r(dSYnX||jkS)NF)rrr8)rr7r9rrrrL�s

	zWeakKeyDictionary.__contains__c
csZt|��Hx@|jj�D]/\}}|�}|dk	r||fVqqWWdQXdS)N)r
r8rR)rr9rPr7rrrrR�s

	zWeakKeyDictionary.itemsc
csHt|��6x.|jD]#}|�}|dk	r|VqqWWdQXdS)N)r
r8)rr9r$rrrr\�s

	zWeakKeyDictionary.keysc
csNt|��<x4|jj�D]#\}}|�dk	r|VqqWWdQXdS)N)r
r8rR)rr9rPrrrr]�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.

        )rdr8)rrrr�keyrefs�s
zWeakKeyDictionary.keyrefscCsHd|_x8|jj�\}}|�}|dk	r||fSqWdS)NT)rir8r_)rr7rPrHrrrr_�s		zWeakKeyDictionary.popitemcGs"d|_|jjt|�|�S)NT)rir8rDr)rr7r@rrrrD�s	zWeakKeyDictionary.popcCs|jjt||j�|�S)N)r8r`rr=)rr7rXrrrr`�szWeakKeyDictionary.setdefaultcKs�|j}|dk	rot|d�s9ti�|�}nx3|j�D]"\}}||t||j�<qFWnt|�r�|j|�ndS)NrR)r8rar rRrr=r<r?)rrcrbrBr7rPrrrr?�s	zWeakKeyDictionary.update)r-r.r/r0rCrFrlrJrIrKrNrQrTrfrWrYrLrRr\rgr]rmr_rDr`r?rrrrr:s.	
	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%r@rb�atexit�indexN)zweakrefzfunczargszkwargszatexitzindex)r-r.r/r1rrrr�_Info�srqcOs�|js1ddl}|j|j�dt_n|j�}t||�|_||_||_	|pjd|_
d|_t|j�|_
||j|<dt_dS)NrT)�_registered_with_atexitro�register�	_exitfuncrrqrrnr%r@rb�next�_index_iterrp�	_registry�_dirty)rr$r%r@rbro�inforrrrC�s				
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)rwrD�	_shutdownr%r@rb)r�_ryrrrr'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)rwrYrnrDr%r@rb)rryr$rrr�detach	s!zfinalize.detachcCsS|jj|�}|o!|j�}|dk	rO||j|j|jpKifSdS)zMIf alive then return (obj, func, args, kwargs);
        otherwise return NoneN)rwrYrnr%r@rb)rryr$rrr�peeksz
finalize.peekcCs
||jkS)zWhether finalizer is alive)rw)rrrr�aliveszfinalize.alivecCs%|jj|�}t|�o$|jS)z*Whether finalizer should be called at exit)rwrY�boolro)rryrrrroszfinalize.atexitcCs.|jj|�}|r*t|�|_ndS)N)rwrYrro)rrPryrrrro$scCs�|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>)rwrYrnr r-rM)rryr$rrrrN*szfinalize.__repr__cCsCdd�|jj�D�}|jddd��dd�|D�S)NcSs+g|]!\}}|jr||f�qSr)ro)rj�f�irrrrk6s	z-finalize._select_for_exit.<locals>.<listcomp>r7cSs|djS)Nr3)rp)�itemrrr�<lambda>7sz+finalize._select_for_exit.<locals>.<lambda>cSsg|]\}}|�qSrr)rjr�r�rrrrk8s	)rwrR�sort)r"�Lrrr�_select_for_exit3szfinalize._select_for_exitcCs�d}z�|jr�ddl}|j�r=d}|j�nd}x}|dks[tjrs|j�}dt_n|s}Pn|j�}y|�WqFtk
r�t	j
t	j��YqFXqFWnWddt_|r�|j
�nXdS)NFrT)rw�gc�	isenabled�disablerrxr�rD�	Exception�sys�
excepthook�exc_inforz�enable)r"�reenable_gcr��pendingr�rrrrt:s.	

	zfinalize._exitfunc)r-r.r/r0r1rwrz�	itertools�countrvrxrrrqrCr'r|r}�propertyr~ro�setterrN�classmethodr�rtrrrrr�s$	)r0�_weakrefrrrrrrr�_weakrefsetr	r
�collectionsr�r�r�__all__r�MutableMappingr
rOrrrrrr�<module>s4			6��