Viewing File: /opt/alt/python35/lib64/python3.5/__pycache__/weakref.cpython-35.opt-1.pyc



YfO
@s(dZddlmZmZmZmZmZmZmZm	Z	ddl
mZmZddl
Z
ddlZddlZeefZddddd	d
ddd
ddddg
ZGdddeZGddde
jZGdddeZGdd	d	e
jZGdddZdS)z{Weak reference support for Python.

This module is an implementation of PEP 205:

http://www.python.org/dev/peps/pep-0205/
)getweakrefcountgetweakrefsrefproxyCallableProxyType	ProxyType
ReferenceType_remove_dead_weakref)WeakSet_IterationGuardNrrrrWeakKeyDictionaryrrr
ProxyTypesWeakValueDictionaryr

WeakMethodfinalizecs^eZdZdZdZdddZfd	d
ZddZd
dZe	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sy|j}|j}Wn0tk
rHtdjt|dYnXfdd}tj|||}t|||_t||_	d|_
t||S)Nz)argument should be a bound method, not {}cs5}|jr1d|_dk	r1|dS)NF)r)argself)callbackself_wr,/opt/alt/python35/lib64/python3.5/weakref.py_cb3s
			zWeakMethod.__new__.<locals>._cbT)__self____func__AttributeError	TypeErrorformattyper__new__rrr)clsmethrobjfuncrrr)rrrr",s	

		zWeakMethod.__new__csGtj}|j}|dks3|dkr7dS|j||S)N)super__call__rr)rr%r&)	__class__rrr(Bs
zWeakMethod.__call__cCsSt|trO|js#|jr-||kStj||oN|j|jkSdS)NF)
isinstancerrr__eq__r)rotherrrrr+Is

"zWeakMethod.__eq__cCsSt|trO|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@seZdZdZddZddZddZdd	Zd
dZdd
Z	ddZ
ddZddZeZ
ddZdddZddZddZeZddZdd Zd!d"Zd#d$Zdd%d&Zd'd(Zd)d*ZdS)+rzMapping 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|tfdd}||_g|_t|_i|_|j	||dS)NzGdescriptor '__init__' of 'WeakValueDictionary' object needs an argumentz$expected at most 1 arguments, got %dcsH|}|dk	rD|jr4|jj|jn||jdS)N)
_iterating_pending_removalsappendkey)wrselfref_atomic_removalr)drrremovems
		z,WeakValueDictionary.__init__.<locals>.remove)
rlenrr	_remover6setr5dataupdate)argskwrr=r)r<r__init__fs			
zWeakValueDictionary.__init__cCs<|j}|j}x#|r7|j}t||qWdS)N)r6rApopr	)rlr<r8rrr_commit_removals}s
			z$WeakValueDictionary._commit_removalscCsF|jr|j|j|}|dkr>t|n|SdS)N)r6rHrAKeyError)rr8orrr__getitem__s	
zWeakValueDictionary.__getitem__cCs!|jr|j|j|=dS)N)r6rHrA)rr8rrr__delitem__s	
zWeakValueDictionary.__delitem__cCs |jr|jt|jS)N)r6rHr>rA)rrrr__len__s	
zWeakValueDictionary.__len__cCsJ|jr|jy|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|jt||j||j|<dS)N)r6rHKeyedRefr?rA)rr8valuerrr__setitem__s	
zWeakValueDictionary.__setitem__cCs_|jr|jt}x<|jjD]+\}}|}|dk	r,|||<q,W|S)N)r6rHrrAitems)rnewr8r9rJrrrcopys	
		zWeakValueDictionary.copycCs{ddlm}|jr#|j|j}xE|jjD]4\}}|}|dk	r?|||||<q?W|S)Nr)deepcopy)rVrWr6rHr)rArT)rmemorWrUr8r9rJrrr__deepcopy__s	
	z WeakValueDictionary.__deepcopy__NcCs^|jr|jy|j|}Wntk
r<|SYnX|}|dkrV|S|SdS)N)r6rHrArI)rr8defaultr9rJrrrgets	

		zWeakValueDictionary.getc
csk|jr|jt|Ex=|jjD],\}}|}|dk	r0||fVq0WWdQRXdS)N)r6rHrrArT)rkr9vrrrrTs	

	zWeakValueDictionary.itemsc
cs_|jr|jt|9x1|jjD] \}}|dk	r0|Vq0WWdQRXdS)N)r6rHrrArT)rr\r9rrrkeyss	

zWeakValueDictionary.keysc	cs=|jr|jt||jjEdHWdQRXdS)aReturn 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)r6rHrrAvalues)rrrr
itervaluerefss
	

z!WeakValueDictionary.itervaluerefsc
cs_|jr|jt|9x1|jjD] }|}|dk	r0|Vq0WWdQRXdS)N)r6rHrrAr_)rr9r%rrrr_s	

	zWeakValueDictionary.valuescCsR|jr|jx8|jj\}}|}|dk	r||fSqWdS)N)r6rHrApopitem)rr8r9rJrrrras	
	zWeakValueDictionary.popitemcGsx|jr|jy|jj|}Wntk
rFd}YnX|dkrp|ra|dSt|n|SdS)Nr)r6rHrArFrI)rr8rCrJrrrrFs	

zWeakValueDictionary.popcCsvy|j|}Wntk
r.d}YnX|dkrn|jrN|jt||j||j|<|S|SdS)N)rArIr6rHrQr?)rr8rZrJrrr
setdefaults
	
zWeakValueDictionary.setdefaultcOs|std|^}}t|dkrFtdt||rV|dnd}|jro|j|j}|dk	rt|dsti|}x3|jD]%\}}t||j	|||<qWt|r|j
|dS)NzEdescriptor 'update' of 'WeakValueDictionary' object needs an argumentr4z$expected at most 1 arguments, got %drrT)rr>r6rHrAhasattrr!rTrQr?rB)rCkwargsrdictr<r8rJrrrrB s 	
	zWeakValueDictionary.updatecCs&|jr|jt|jjS)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.

        )r6rHlistrAr_)rrrr	valuerefs3s
	
zWeakValueDictionary.valuerefs)r.r/r0r1rErHrKrLrMrNrPrSrV__copy__rYr[rTr^__iter__r`r_rarFrbrBrgrrrrrZs.			
			
cs:eZdZdZdZddZfddZS)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__cstj||dS)N)r'rE)rrjrr8)r)rrrESszKeyedRef.__init__)r8)r.r/r0r1r2r"rErr)r)rrQBsrQc@seZdZdZdddZddZddZd	d
ZddZd
dZ	ddZ
ddZddZeZ
ddZdddZddZddZddZeZdd 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|jfdd|jD|_d|_dS)Ncs"g|]}|kr|qSrr).0r\)r<rr
<listcomp>s	z5WeakKeyDictionary._scrub_removals.<locals>.<listcomp>F)rAr6rk)rr)r<r_scrub_removalss	z!WeakKeyDictionary._scrub_removalscCsd|_|jt|=dS)NT)rkrAr)rr8rrrrLs	zWeakKeyDictionary.__delitem__cCs|jt|S)N)rAr)rr8rrrrKszWeakKeyDictionary.__getitem__cCs6|jr|jr|jt|jt|jS)N)rkr6rnr>rA)rrrrrMs
zWeakKeyDictionary.__len__cCsd|jjt|fS)Nz<%s at %#x>)r)r.rO)rrrrrPszWeakKeyDictionary.__repr__cCs||jt||j<dS)N)rArr?)rr8rRrrrrSszWeakKeyDictionary.__setitem__cCsLt}x<|jjD]+\}}|}|dk	r|||<qW|S)N)rrArT)rrUr8rRrJrrrrVs		zWeakKeyDictionary.copycCshddlm}|j}xE|jjD]4\}}|}|dk	r,|||||<q,W|S)Nr)rW)rVrWr)rArT)rrXrWrUr8rRrJrrrrYs	zWeakKeyDictionary.__deepcopy__cCs|jjt||S)N)rAr[r)rr8rZrrrr[szWeakKeyDictionary.getcCs6yt|}Wntk
r(dSYnX||jkS)NF)rrrA)rr8r9rrrrNs

	zWeakKeyDictionary.__contains__c
csXt|Ex=|jjD],\}}|}|dk	r||fVqWWdQRXdS)N)rrArT)rr9rRr8rrrrTs

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

	zWeakKeyDictionary.keysc
csLt|9x1|jjD] \}}|dk	r|VqWWdQRXdS)N)rrArT)rr9rRrrrr_s
zWeakKeyDictionary.valuescCs
t|jS)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)rrrrkeyrefss
zWeakKeyDictionary.keyrefscCsHd|_x8|jj\}}|}|dk	r||fSqWdS)NT)rkrAra)rr8rRrJrrrras		zWeakKeyDictionary.popitemcGs"d|_|jjt||S)NT)rkrArFr)rr8rCrrrrFs	zWeakKeyDictionary.popcCs|jjt||j|S)N)rArbrr?)rr8rZrrrrbszWeakKeyDictionary.setdefaultcKs|j}|dk	rit|ds6ti|}x0|jD]"\}}||t||j<qCWt|r|j|dS)NrT)rArcr!rTrr?r>rB)rrerdr<r8rRrrrrBs	zWeakKeyDictionary.update)r.r/r0r1rErHrnrLrKrMrPrSrVrhrYr[rNrTr^rir_rorarFrbrBrrrrrWs.	
	c@seZdZdZfZiZdZejZ	dZ
dZGdddZddZ
ddd	Zd
dZdd
ZeddZeddZejddZddZeddZeddZdS)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._Infoweakrefr&rCrdatexitindexN)rpr&rCrdrqrr)r.r/r0r2rrrr_InfosrscOs|js.ddl}|j|jdt_|j}t|||_||_||_	|pgd|_
d|_t|j|_
||j|<dt_dS)NrT)_registered_with_atexitrqregister	_exitfuncrrsrrpr&rCrdnext_index_iterrr	_registry_dirty)rr%r&rCrdrqinforrrrEs					
zfinalize.__init__NcCsE|jj|d}|rA|jrA|j|j|jp=iSdS)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|drd||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%rrrdetach&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%rrrpeek.sz
finalize.peekcCs
||jkS)zWhether finalizer is alive)ry)rrrralive6szfinalize.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[rrq)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|jjD}|jddddd|DS)NcSs+g|]!\}}|jr||fqSr)rq)rlfirrrrmSs	z-finalize._select_for_exit.<locals>.<listcomp>r8cSs|djS)Nr4)rr)itemrrr<lambda>Tsz+finalize._select_for_exit.<locals>.<lambda>cSsg|]\}}|qSrr)rlrrrrrrmUs	)ryrTsort)r#Lrrr_select_for_exitPszfinalize._select_for_exitcCsd}z|jrddl}|jr:d}|jd}xt|dksXtjrm|j}dt_|stP|j}y|WqCtk
rt	j
t	jYqCXqCWWddt_|r|j
XdS)NFrT)rygc	isenableddisablerrzrrF	Exceptionsys
excepthookexc_infor|enable)r#reenable_gcrpendingrrrrrvWs.	
	
	zfinalize._exitfunc)r.r/r0r1r2ryr|	itertoolscountrxrzrtrsrEr(r~rpropertyrrqsetterrPclassmethodrrvrrrrrs$	)r1_weakrefrrrrrrrr	_weakrefsetr
rcollectionsrrr
__all__rMutableMappingrrQrrrrrr<module>s:
		6
Back to Directory File Manager