�`^c@s�dZddlZddlmZmZmZmZmZmZm Z ddl
mZmZddl
mZeefZdddd d
ddd
ddddgZdejfd��YZdefd��YZd
ejfd��YZdS(s{Weak reference support for Python.
This module is an implementation of PEP 205:
http://www.python.org/dev/peps/pep-0205/
i�N(tgetweakrefcounttgetweakrefstreftproxytCallableProxyTypet ProxyTypet
ReferenceType(tWeakSett_IterationGuard(tReferenceErrorRRRRtWeakKeyDictionaryR RRRt
ProxyTypestWeakValueDictionaryRcBs�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z
d �Zd
�ZeZ
d�Zdd�Zd
�Zd�Zd�ZeZd�Zd�Zd�Zd�Zdd�Zdd�Zd�Zd�ZRS(s�Mapping class that references values weakly.
Entries in the dictionary will be discarded when no strong
reference to the value exists anymore
cOsJt|�d�}||_g|_t�|_tjj|||�dS(NcSsH|�}|dk rD|jr4|jj|j�qD|j|j=ndS(N(tNonet
_iteratingt_pending_removalstappendtkeytdata(twrtselfreftself((s/sys/lib/python2.7/weakref.pytremove0s
(Rt_removeRtsetRtUserDictt__init__(RtargstkwR((s/sys/lib/python2.7/weakref.pyR/s
cCs0|j}|j}x|r+||j�=qWdS(N(RRtpop(Rtltd((s/sys/lib/python2.7/weakref.pyt_commit_removals=s cCs0|j|�}|dkr(t|�n|SdS(N(RR
tKeyError(RRto((s/sys/lib/python2.7/weakref.pyt__getitem__EscCs$|jr|j�n|j|=dS(N(RR R(RR((s/sys/lib/python2.7/weakref.pyt__delitem__Ls
cCs3y|j|�}Wntk
r(tSX|dk S(N(RR!tFalseR
(RRR"((s/sys/lib/python2.7/weakref.pyt__contains__Qs
cCs3y|j|�}Wntk
r(tSX|dk S(N(RR!R%R
(RRR"((s/sys/lib/python2.7/weakref.pythas_keyXs
cCsdt|�S(Ns<WeakValueDictionary at %s>(tid(R((s/sys/lib/python2.7/weakref.pyt__repr___scCs6|jr|j�nt||j|�|j|<dS(N(RR tKeyedRefRR(RRtvalue((s/sys/lib/python2.7/weakref.pyt__setitem__bs
cCs'|jr|j�n|jj�dS(N(RR Rtclear(R((s/sys/lib/python2.7/weakref.pyR-gs
cCsOt�}x?|jj�D].\}}|�}|dk r|||<qqW|S(N(RRtitemsR
(RtnewRRR"((s/sys/lib/python2.7/weakref.pytcopyls cCskddlm}|j�}xH|jj�D]7\}}|�}|dk r,|||||�<q,q,W|S(Ni�(tdeepcopy(R0R1t __class__RR.R
(RtmemoR1R/RRR"((s/sys/lib/python2.7/weakref.pyt__deepcopy__vs cCsGy|j|}Wntk
r%|SX|�}|dkr?|S|SdS(N(RR!R
(RRtdefaultRR"((s/sys/lib/python2.7/weakref.pytgets
cCsUg}xH|jj�D]7\}}|�}|dk r|j||f�qqW|S(N(RR.R
R(RtLRRR"((s/sys/lib/python2.7/weakref.pyR.�s ccsWt|��x=|jj�D],}|�}|dk r|j|fVqqWWdQXdS(N(RRt
itervaluesR
R(RRR+((s/sys/lib/python2.7/weakref.pyt iteritems�s
ccs6t|��x|jj�D]}|VqWWdQXdS(N(RRtiterkeys(Rtk((s/sys/lib/python2.7/weakref.pyR:�s
ccs6t|��x|jj�D]}|VqWWdQXdS(s�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(RRR8(RR((s/sys/lib/python2.7/weakref.pyt
itervaluerefs�s
ccsNt|��x4|jj�D]#}|�}|dk r|VqqWWdQXdS(N(RRR8R
(RRtobj((s/sys/lib/python2.7/weakref.pyR8�s
cCsT|jr|j�nx7|jj�\}}|�}|dk r||fSqdS(N(RR RtpopitemR
(RRRR"((s/sys/lib/python2.7/weakref.pyR>�s
cGst|jr|j�ny|jj|��}Wn"tk
rS|rM|dS�nX|dkrlt|�n|SdS(Ni(RR RRR!R
(RRRR"((s/sys/lib/python2.7/weakref.pyR�s
cCscy|j|}WnDtk
rW|jr7|j�nt||j|�|j|<|SX|�SdS(N(RR!RR R*R(RRR5R((s/sys/lib/python2.7/weakref.pyt
setdefault�s
cKs�|jr|j�n|j}|dk r�t|d�sOti�|�}nx6|j�D]%\}}t||j|�||<q\Wnt |�r�|j
|�ndS(NR.(RR RR
thasattrttypeR.R*Rtlentupdate(RtdicttkwargsRRR"((s/sys/lib/python2.7/weakref.pyRC�s
cCs
|jj�S(s~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.
(Rtvalues(R((s/sys/lib/python2.7/weakref.pyt valuerefs�s
cCsIg}x<|jj�D]+}|�}|dk r|j|�qqW|S(N(RRFR
R(RR7RR"((s/sys/lib/python2.7/weakref.pyRF�s N(t__name__t
__module__t__doc__RR R#R$R&R'R)R,R-R0t__copy__R4R
R6R.R9R:t__iter__R<R8R>RR?RCRGRF(((s/sys/lib/python2.7/weakref.pyR#s4
R*cBs&eZdZdZd�Zd�ZRS(s[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.
RcCs"tj|||�}||_|S(N(Rt__new__R(RAtobtcallbackRR((s/sys/lib/python2.7/weakref.pyRMs cCstt|�j||�dS(N(tsuperR*R(RRNROR((s/sys/lib/python2.7/weakref.pyRs(skey(RHRIRJt __slots__RMR(((s/sys/lib/python2.7/weakref.pyR*�s cBs�eZdZdd�Zd�Zd�Zd�Zd�Zd�Z d�Z
e
Zd�Zdd �Z
d
�Zd�Zd�Zd
�Zd�Zd�ZeZd�Zd�Zd�Zd�Zd�Zdd�Zdd�ZRS(s� 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.
cCsYi|_t|�d�}||_g|_t�|_|dk rU|j|�ndS(NcSsB|�}|dk r>|jr1|jj|�q>|j|=ndS(N(R
RRRR(R;RR((s/sys/lib/python2.7/weakref.pyRs
(RRRRRRR
RC(RRDR((s/sys/lib/python2.7/weakref.pyRs cCsH|j}|j}x/|rCy||j�=Wqtk
r?qXqWdS(N(RRRR!(RRR((s/sys/lib/python2.7/weakref.pyR *s
cCs|jt|�=dS(N(RR(RR((s/sys/lib/python2.7/weakref.pyR$7scCs|jt|�S(N(RR(RR((s/sys/lib/python2.7/weakref.pyR#:scCsdt|�S(Ns<WeakKeyDictionary at %s>(R((R((s/sys/lib/python2.7/weakref.pyR)=scCs||jt||j�<dS(N(RRR(RRR+((s/sys/lib/python2.7/weakref.pyR,@scCsOt�}x?|jj�D].\}}|�}|dk r|||<qqW|S(N(R
RR.R
(RR/RR+R"((s/sys/lib/python2.7/weakref.pyR0Cs cCskddlm}|j�}xH|jj�D]7\}}|�}|dk r,|||�||<q,q,W|S(Ni�(R1(R0R1R2RR.R
(RR3R1R/RR+R"((s/sys/lib/python2.7/weakref.pyR4Ms cCs|jjt|�|�S(N(RR6R(RRR5((s/sys/lib/python2.7/weakref.pyR6VscCs2yt|�}Wntk
r$dSX||jkS(Ni(Rt TypeErrorR(RRR((s/sys/lib/python2.7/weakref.pyR'Ys
cCs2yt|�}Wntk
r$dSX||jkS(Ni(RRRR(RRR((s/sys/lib/python2.7/weakref.pyR&`s
cCsUg}xH|jj�D]7\}}|�}|dk r|j||f�qqW|S(N(RR.R
R(RR7RR+R"((s/sys/lib/python2.7/weakref.pyR.gs ccsZt|��x@|jj�D]/\}}|�}|dk r||fVqqWWdQXdS(N(RRR9R
(RRR+R((s/sys/lib/python2.7/weakref.pyR9os
ccs6t|��x|jj�D]}|VqWWdQXdS(s�Return an iterator that yields the 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.
N(RRR:(RR((s/sys/lib/python2.7/weakref.pytiterkeyrefsvs
ccsNt|��x4|jj�D]#}|�}|dk r|VqqWWdQXdS(N(RRR:R
(RRR=((s/sys/lib/python2.7/weakref.pyR:�s
ccs6t|��x|jj�D]}|VqWWdQXdS(N(RRR8(RR+((s/sys/lib/python2.7/weakref.pyR8�s
cCs
|jj�S(szReturn 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.
(Rtkeys(R((s/sys/lib/python2.7/weakref.pytkeyrefs�s
cCsIg}x<|jj�D]+}|�}|dk r|j|�qqW|S(N(RRTR
R(RR7RR"((s/sys/lib/python2.7/weakref.pyRT�s cCs>x7|jj�\}}|�}|dk r||fSqdS(N(RR>R
(RRR+R"((s/sys/lib/python2.7/weakref.pyR>�s
cGs|jjt|�|�S(N(RRR(RRR((s/sys/lib/python2.7/weakref.pyR�scCs|jjt||j�|�S(N(RR?RR(RRR5((s/sys/lib/python2.7/weakref.pyR?�scKs�|j}|dk rot|d�s9ti�|�}nx3|j�D]"\}}||t||j�<qFWnt|�r�|j|�ndS(NR.( RR
[email protected]RRBRC(RRDRERRR+((s/sys/lib/python2.7/weakref.pyRC�s N(RHRIRJR
RR R$R#R)R,R0RKR4R6R'R&R.R9RSR:RLR8RURTR>RR?RC(((s/sys/lib/python2.7/weakref.pyR
s2
(RJRt_weakrefRRRRRRRt_weakrefsetRRt
exceptionsR Rt__all__RR*R
(((s/sys/lib/python2.7/weakref.pyt<module>s4 �
|