ó ^ bc @sôdZddlZddlmZmZmZmZmZmZm Z m Z ddl m Z m Z ddlmZeefZdddd 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 ReferenceTypet_remove_dead_weakref(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„Zd„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 cOs¡|stdƒ‚n|d}|d}t|ƒdkrTtdt|ƒƒ‚nt|ƒtd„}||_g|_tƒ|_tjj |||ŽdS(NsGdescriptor '__init__' of 'WeakValueDictionary' object needs an argumentiis$expected at most 1 arguments, got %dcSsN|ƒ}|dk rJ|jr4|jj|jƒqJ||j|jƒndS(N(tNonet _iteratingt_pending_removalstappendtkeytdata(twrtselfreft_atomic_removaltself((s,/opt/alt/python27/lib64/python2.7/weakref.pytremove8s    ( t TypeErrortlenRRt_removeRtsetRtUserDictt__init__(targstkwRR((s,/opt/alt/python27/lib64/python2.7/weakref.pyR0s     cCs<|j}|j}x#|r7|jƒ}t||ƒqWdS(N(RRtpopR(RtltdR((s,/opt/alt/python27/lib64/python2.7/weakref.pyt_commit_removalsGs     cCsF|jr|jƒn|j|ƒ}|dkr>t|‚n|SdS(N(RR$RRtKeyError(RRto((s,/opt/alt/python27/lib64/python2.7/weakref.pyt __getitem__Ps     cCs$|jr|jƒn|j|=dS(N(RR$R(RR((s,/opt/alt/python27/lib64/python2.7/weakref.pyt __delitem__Ys  cCsI|jr|jƒny|j|ƒ}Wntk r>tSX|dk S(N(RR$RR%tFalseR(RRR&((s,/opt/alt/python27/lib64/python2.7/weakref.pyt __contains__^s   cCsI|jr|jƒny|j|ƒ}Wntk r>tSX|dk S(N(RR$RR%R)R(RRR&((s,/opt/alt/python27/lib64/python2.7/weakref.pythas_keygs   cCsdt|ƒS(Ns(tid(R((s,/opt/alt/python27/lib64/python2.7/weakref.pyt__repr__pscCs6|jr|jƒnt||j|ƒ|j|¶s    ccsL|jr|jƒnt|ƒ$x|jjƒD] }|Vq3WWdQXdS(sReturn 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(RR$R RR<(RR((s,/opt/alt/python27/lib64/python2.7/weakref.pyt itervaluerefs¿s   ccsd|jr|jƒnt|ƒ<x4|jjƒD]#}|ƒ}|dk r3|Vq3q3WWdQXdS(N(RR$R RR<R(RRtobj((s,/opt/alt/python27/lib64/python2.7/weakref.pyR<Ïs     cCsU|jr|jƒnx8|jjƒ\}}|ƒ}|dk r||fSqWdS(N(RR$RtpopitemR(RRRR&((s,/opt/alt/python27/lib64/python2.7/weakref.pyRBØs    cGsw|jr|jƒny|jj|ƒƒ}Wntk rHd}nX|dkro|rc|dSt|‚n|SdS(Ni(RR$RR!R%R(RRRR&((s,/opt/alt/python27/lib64/python2.7/weakref.pyR!ás      cCsx|jr|jƒny|j|ƒ}Wntk rCd}nX|dkrpt||j|ƒ|j|<|S|SdS(N(RR$RR%RR.R(RRR9R&((s,/opt/alt/python27/lib64/python2.7/weakref.pyt setdefaultðs     cOs|stdƒ‚n|d}|d}t|ƒdkrTtdt|ƒƒ‚n|rd|dnd}|jr€|jƒn|j}|dk ròt|dƒs¹tiƒ|ƒ}nx6|jƒD]%\}}t ||j |ƒ||t__iter__R@R<RBR!RCRFRJRI(((s,/opt/alt/python27/lib64/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(REtobtcallbackRR((s,/opt/alt/python27/lib64/python2.7/weakref.pyRP6s cCstt|ƒj||ƒdS(N(tsuperR.R(RRQRRR((s,/opt/alt/python27/lib64/python2.7/weakref.pyR;s(R(RKRLRMt __slots__RPR(((s,/opt/alt/python27/lib64/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(RRRRR(R?RR((s,/opt/alt/python27/lib64/python2.7/weakref.pyRLs    (RRRRRRRRF(RRHR((s,/opt/alt/python27/lib64/python2.7/weakref.pyRJs     cCsH|j}|j}x/|rCy||jƒ=Wqtk r?qXqWdS(N(RRR!R%(RR"R#((s,/opt/alt/python27/lib64/python2.7/weakref.pyR$Zs    cCs|jt|ƒ=dS(N(RR(RR((s,/opt/alt/python27/lib64/python2.7/weakref.pyR(gscCs|jt|ƒS(N(RR(RR((s,/opt/alt/python27/lib64/python2.7/weakref.pyR'jscCsdt|ƒS(Ns(R,(R((s,/opt/alt/python27/lib64/python2.7/weakref.pyR-mscCs||jt||jƒ(RR((s,/opt/alt/python27/lib64/python2.7/weakref.pyt iterkeyrefs¦s ccsNt|ƒ<x4|jjƒD]#}|ƒ}|dk r|VqqWWdQXdS(N(R RR>R(RRRA((s,/opt/alt/python27/lib64/python2.7/weakref.pyR>´s    ccs6t|ƒ$x|jjƒD] }|VqWWdQXdS(N(R RR<(RR/((s,/opt/alt/python27/lib64/python2.7/weakref.pyR<½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,/opt/alt/python27/lib64/python2.7/weakref.pytkeyrefsÂs cCsIg}x<|jjƒD]+}|ƒ}|dk r|j|ƒqqW|S(N(RRVRR(RR;RR&((s,/opt/alt/python27/lib64/python2.7/weakref.pyRVÎs   cCs?x8|jjƒ\}}|ƒ}|dk r||fSqWdS(N(RRBR(RRR/R&((s,/opt/alt/python27/lib64/python2.7/weakref.pyRBÖs   cGs|jjt|ƒ|ŒS(N(RR!R(RRR((s,/opt/alt/python27/lib64/python2.7/weakref.pyR!ÝscCs|jjt||jƒ|ƒS(N(RRCRR(RRR9((s,/opt/alt/python27/lib64/python2.7/weakref.pyRCàscKs|j}|dk rot|dƒs9tiƒ|ƒ}nx3|jƒD]"\}}||t||jƒROR<RWRVRBR!RCRF(((s,/opt/alt/python27/lib64/python2.7/weakref.pyR ?s2                   (RMRt_weakrefRRRRRRRRt _weakrefsetRR t exceptionsR R t__all__R R.R (((s,/opt/alt/python27/lib64/python2.7/weakref.pyts :    ÿ