ó CØê[c @sîdZddlZddlmZmZmZmZmZmZm Z ddl m Z m Z ddl mZeefZdddd d d d d ddddg Zdejfd„ƒ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(tgetweakrefcountt getweakrefstreftproxytCallableProxyTypet ProxyTypet ReferenceType(tWeakSett_IterationGuard(tReferenceErrorRRRRtWeakKeyDictionaryR RRRt ProxyTypestWeakValueDictionaryRcBsòeZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z e Z 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/usr/lib/python2.7/weakref.pytremove0s    (Rt_removeRtsetRtUserDictt__init__(RtargstkwR((s/usr/lib/python2.7/weakref.pyR/s    cCs0|j}|j}x|r+||jƒ=qWdS(N(RRtpop(Rtltd((s/usr/lib/python2.7/weakref.pyt_commit_removals=s   cCs0|j|ƒ}|dkr(t|‚n|SdS(N(RR tKeyError(RRto((s/usr/lib/python2.7/weakref.pyt __getitem__Es  cCs$|jr|jƒn|j|=dS(N(RR R(RR((s/usr/lib/python2.7/weakref.pyt __delitem__Ls  cCs3y|j|ƒ}Wntk r(tSX|dk S(N(RR!tFalseR (RRR"((s/usr/lib/python2.7/weakref.pyt __contains__Qs  cCs3y|j|ƒ}Wntk r(tSX|dk S(N(RR!R%R (RRR"((s/usr/lib/python2.7/weakref.pythas_keyXs  cCsdt|ƒS(Ns(tid(R((s/usr/lib/python2.7/weakref.pyt__repr___scCs6|jr|jƒnt||j|ƒ|j|·s    cGst|jr|jƒny|jj|ƒƒ}Wn"tk rS|rM|dS‚nX|dkrlt|‚n|SdS(Ni(RR RRR!R (RRRR"((s/usr/lib/python2.7/weakref.pyRÀs     cCscy|j|}WnDtk rW|jr7|jƒnt||j|ƒ|j|<|SX|ƒSdS(N(RR!RR R*R(RRR5R((s/usr/lib/python2.7/weakref.pyt setdefaultÎs   cKs¨|jr|jƒn|j}|dk rˆt|dƒsOtiƒ|ƒ}nx6|jƒD]%\}}t||j|ƒ||RR?RCRGRF(((s/usr/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/usr/lib/python2.7/weakref.pyRMs cCstt|ƒj||ƒdS(N(tsuperR*R(RRNROR((s/usr/lib/python2.7/weakref.pyR s(skey(RHRIRJt __slots__RMR(((s/usr/lib/python2.7/weakref.pyR*ús cBsìeZdZdd„Zd„Zd„Zd„Zd„Zd„Z d„Z e Z d„Z dd „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/usr/lib/python2.7/weakref.pyRs    (RRRRRRR RC(RRDR((s/usr/lib/python2.7/weakref.pyRs     cCsH|j}|j}x/|rCy||jƒ=Wqtk r?qXqWdS(N(RRRR!(RRR((s/usr/lib/python2.7/weakref.pyR *s    cCs|jt|ƒ=dS(N(RR(RR((s/usr/lib/python2.7/weakref.pyR$7scCs|jt|ƒS(N(RR(RR((s/usr/lib/python2.7/weakref.pyR#:scCsdt|ƒS(Ns(R((R((s/usr/lib/python2.7/weakref.pyR)=scCs||jt||jƒx7|jjƒ\}}|ƒ}|dk r||fSqdS(N(RR>R (RRR+R"((s/usr/lib/python2.7/weakref.pyR>¦s   cGs|jjt|ƒ|ŒS(N(RRR(RRR((s/usr/lib/python2.7/weakref.pyR­scCs|jjt||jƒ|ƒS(N(RR?RR(RRR5((s/usr/lib/python2.7/weakref.pyR?°scKs|j}|dk rot|dƒs9tiƒ|ƒ}nx3|jƒD]"\}}||t||jƒRR?RC(((s/usr/lib/python2.7/weakref.pyR s2                   (RJRt_weakrefRRRRRRRt _weakrefsetRRt exceptionsR R t__all__R R*R (((s/usr/lib/python2.7/weakref.pyts 4    ×