�
��c
@s�dZddkZddklZlZlZlZlZlZl Z ddk
lZeefZddddd d
ddd
dg
Z
deifd��YZdefd��YZd eifd��YZdS(s�Weak reference support for Python.
This module is an implementation of PEP 205:
http://python.sourceforge.net/peps/pep-0205.html
i�N(tgetweakrefcounttgetweakrefstreftproxytCallableProxyTypet ProxyTypet
ReferenceType(tReferenceErrorRRRRtWeakKeyDictionaryRRRt
ProxyTypestWeakValueDictionarycBs�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z dd�Zd �Zd
�Z
d�Zd�Zd
�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
cOs5t|�d�}||_tii|||�dS(NcSs+|�}|dj o|i|i=ndS(N(tNonetdatatkey(twrtselfreftself((s/sys/lib/python/weakref.pytremove.s
(Rt_removetUserDictt__init__(RtargstkwR((s/sys/lib/python/weakref.pyR-s cCs2|i|�}|djo
t|�n|SdS(N(RRtKeyError(RR
to((s/sys/lib/python/weakref.pyt__getitem__5s
cCs8y|i|�}Wntj
otSnX|dj S(N(RRtFalseR(RR
R((s/sys/lib/python/weakref.pyt__contains__<s
cCs8y|i|�}Wntj
otSnX|dj S(N(RRRR(RR
R((s/sys/lib/python/weakref.pythas_keyCs
cCsdt|�S(Ns<WeakValueDictionary at %s>(tid(R((s/sys/lib/python/weakref.pyt__repr__JscCs t||i|�|i|<dS(N(tKeyedRefRR(RR
tvalue((s/sys/lib/python/weakref.pyt__setitem__MscCsQt�}xA|ii�D]0\}}|�}|dj o|||<qqW|S(N(R
RtitemsR(RtnewR
RR((s/sys/lib/python/weakref.pytcopyPs
cCsQy|i|}Wntj
o|Sn$X|�}|djo|Sn|SdS(N(RRR(RR
tdefaultRR((s/sys/lib/python/weakref.pytgetXs
cCsWg}xJ|ii�D]9\}}|�}|dj o|i||f�qqW|S(N(RR"Rtappend(RtLR
RR((s/sys/lib/python/weakref.pyR"es
ccsFx?|ii�D].}|�}|dj o|i|fVqqWdS(N(Rt
itervaluesRR
(RRR ((s/sys/lib/python/weakref.pyt iteritemsms
cCs
|ii�S(N(Rtiterkeys(R((s/sys/lib/python/weakref.pyR+sscCs
|ii�S(N(RR+(R((s/sys/lib/python/weakref.pyt__iter__vscCs
|ii�S(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.
(RR)(R((s/sys/lib/python/weakref.pyt
itervaluerefsys
ccs=x6|ii�D]%}|�}|dj o |VqqWdS(N(RR)R(RRtobj((s/sys/lib/python/weakref.pyR)�s
cCsCx<|ii�\}}|�}|dj o||fSqqdS(N(RtpopitemR(RR
RR((s/sys/lib/python/weakref.pyR/�s
cGsgy|ii|��}Wn)tj
o|o|dSn�nX|djo
t|�n|SdS(Ni(RtpopRR(RR
RR((s/sys/lib/python/weakref.pyR0�s
cCsRy|i|}Wn3tj
o't||i|�|i|<|Sn X|�SdS(N(RRRR(RR
R%R((s/sys/lib/python/weakref.pyt
setdefault�s cKs�|i}|dj o`t|d�pth�|�}nx7|i�D]%\}}t||i|�||<qIWnt|�o|i|�ndS(NR"( RRthasattrttypeR"RRtlentupdate(RtdicttkwargstdR
R((s/sys/lib/python/weakref.pyR5�s
!
cCs
|ii�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/python/weakref.pyt valuerefs�s
cCsKg}x>|ii�D]-}|�}|dj o|i|�qqW|S(N(RR9RR'(RR(RR((s/sys/lib/python/weakref.pyR9�s
N(t__name__t
__module__t__doc__RRRRRR!R$RR&R"R*R+R,R-R)R/R0R1R5R:R9(((s/sys/lib/python/weakref.pyR
!s*
RcBs&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.
R
cCs"ti|||�}||_|S(N(Rt__new__R
(R3tobtcallbackR
R((s/sys/lib/python/weakref.pyR>�s cCstt|�i||�dS(N(tsuperRR(RR?R@R
((s/sys/lib/python/weakref.pyR�s(skey(R;R<R=t __slots__R>R(((s/sys/lib/python/weakref.pyR�s cBs�eZdZdd�Zd�Zd�Zd�Zd�Zd�Z dd�Z
d�Zd �Zd
�Z
d�Zd�Zd
�Zd�Zd�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.
cCsFh|_t|�d�}||_|dj o|i|�ndS(NcSs(|�}|dj o|i|=ndS(N(RR(tkRR((s/sys/lib/python/weakref.pyR�s
(RRRRR5(RR6R((s/sys/lib/python/weakref.pyR�s cCs|it|�=dS(N(RR(RR
((s/sys/lib/python/weakref.pyt__delitem__�scCs|it|�S(N(RR(RR
((s/sys/lib/python/weakref.pyR�scCsdt|�S(Ns<WeakKeyDictionary at %s>(R(R((s/sys/lib/python/weakref.pyR�scCs||it||i�<dS(N(RRR(RR
R ((s/sys/lib/python/weakref.pyR!�scCsQt�}xA|ii�D]0\}}|�}|dj o|||<qqW|S(N(RRR"R(RR#R
R R((s/sys/lib/python/weakref.pyR$�s
cCs|iit|�|�S(N(RR&R(RR
R%((s/sys/lib/python/weakref.pyR&scCs7yt|�}Wntj
odSnX||ijS(Ni(Rt TypeErrorR(RR
R((s/sys/lib/python/weakref.pyRs
cCs7yt|�}Wntj
odSnX||ijS(Ni(RRER(RR
R((s/sys/lib/python/weakref.pyR
s
cCsWg}xJ|ii�D]9\}}|�}|dj o|i||f�qqW|S(N(RR"RR'(RR(R
R R((s/sys/lib/python/weakref.pyR"s
ccsIxB|ii�D]1\}}|�}|dj o||fVqqWdS(N(RR*R(RRR R
((s/sys/lib/python/weakref.pyR*s
cCs
|ii�S(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.
(RR+(R((s/sys/lib/python/weakref.pytiterkeyrefs"s
ccs=x6|ii�D]%}|�}|dj o |VqqWdS(N(RR+R(RRR.((s/sys/lib/python/weakref.pyR+.s
cCs
|i�S(N(R+(R((s/sys/lib/python/weakref.pyR,4scCs
|ii�S(N(RR)(R((s/sys/lib/python/weakref.pyR)7scCs
|ii�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/python/weakref.pytkeyrefs:s
cCsKg}x>|ii�D]-}|�}|dj o|i|�qqW|S(N(RRGRR'(RR(RR((s/sys/lib/python/weakref.pyRGFs
cCsCx<|ii�\}}|�}|dj o||fSqqdS(N(RR/R(RR
R R((s/sys/lib/python/weakref.pyR/Ns
cGs|iit|�|�S(N(RR0R(RR
R((s/sys/lib/python/weakref.pyR0UscCs|iit||i�|�S(N(RR1RR(RR
R%((s/sys/lib/python/weakref.pyR1XscKs�|i}|dj o]t|d�pth�|�}nx4|i�D]"\}}||t||i�<qIWnt|�o|i|�ndS(NR"( RRR2R3R"RRR4R5(RR6R7R8R
R ((s/sys/lib/python/weakref.pyR5[s
N(R;R<R=RRRDRRR!R$R&RRR"R*RFR+R,R)RHRGR/R0R1R5(((s/sys/lib/python/weakref.pyR�s, (R=Rt_weakrefRRRRRRRt
exceptionsRR t__all__R
RR(((s/sys/lib/python/weakref.pys<module>s4 �
|