Plan 9 from Bell Labs’s /usr/web/sources/contrib/bichued/root/sys/lib/python/weakref.pyc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�
��c
@s�dZddkZddklZlZlZlZlZlZl	Z	ddk
lZeefZddddd	d
ddd
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	�Zd
�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(RRtKeyError(RR
to((s/sys/lib/python/weakref.pyt__getitem__5s

cCs8y|i|�}Wntj
otSnX|dj	S(N(RRtFalseR(RR
R((s/sys/lib/python/weakref.pyt__contains__<s
	cCs8y|i|�}Wntj
otSnX|dj	S(N(RRRR(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
RtitemsR(RtnewR
RR((s/sys/lib/python/weakref.pytcopyPs		
cCsQy|i|}Wntj
o|Sn$X|�}|djo|Sn|SdS(N(RRR(RR
tdefaultRR((s/sys/lib/python/weakref.pytgetXs		
cCsWg}xJ|ii�D]9\}}|�}|dj	o|i||f�qqW|S(N(RR"Rtappend(RtLR
RR((s/sys/lib/python/weakref.pyR"es	
ccsFx?|ii�D].}|�}|dj	o|i|fVqqWdS(N(Rt
itervaluesRR
(RRR ((s/sys/lib/python/weakref.pyt	iteritemsms
	
cCs
|ii�S(N(Rtiterkeys(R((s/sys/lib/python/weakref.pyR+sscCs
|ii�S(N(RR+(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.

        (RR)(R((s/sys/lib/python/weakref.pyt
itervaluerefsys
ccs=x6|ii�D]%}|�}|dj	o	|VqqWdS(N(RR)R(RRtobj((s/sys/lib/python/weakref.pyR)�s
	
cCsCx<|ii�\}}|�}|dj	o||fSqqdS(N(RtpopitemR(RR
RR((s/sys/lib/python/weakref.pyR/�s
	
cGsgy|ii|��}Wn)tj
o|o|dSn�nX|djo
t|�n|SdS(Ni(RtpopRR(RR
RR((s/sys/lib/python/weakref.pyR0�s

cCsRy|i|}Wn3tj
o't||i|�|i|<|Sn	X|�SdS(N(RRRR(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"(	RRthasattrttypeR"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.

        (Rtvalues(R((s/sys/lib/python/weakref.pyt	valuerefs�s
cCsKg}x>|ii�D]-}|�}|dj	o|i|�qqW|S(N(RR9RR'(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	�Zd
�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	
(RRRRR5(RR6R((s/sys/lib/python/weakref.pyR�s		cCs|it|�=dS(N(RR(RR
((s/sys/lib/python/weakref.pyt__delitem__�scCs|it|�S(N(RR(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(RRR(RR
R ((s/sys/lib/python/weakref.pyR!�scCsQt�}xA|ii�D]0\}}|�}|dj	o|||<qqW|S(N(RRR"R(RR#R
R R((s/sys/lib/python/weakref.pyR$�s		
cCs|iit|�|�S(N(RR&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(RR"RR'(RR(R
R R((s/sys/lib/python/weakref.pyR"s	
ccsIxB|ii�D]1\}}|�}|dj	o||fVqqWdS(N(RR*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.

        (RR+(R((s/sys/lib/python/weakref.pytiterkeyrefs"s
ccs=x6|ii�D]%}|�}|dj	o	|VqqWdS(N(RR+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(RR)(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.

        (Rtkeys(R((s/sys/lib/python/weakref.pytkeyrefs:s
cCsKg}x>|ii�D]-}|�}|dj	o|i|�qqW|S(N(RRGRR'(RR(RR((s/sys/lib/python/weakref.pyRGFs	
cCsCx<|ii�\}}|�}|dj	o||fSqqdS(N(RR/R(RR
R R((s/sys/lib/python/weakref.pyR/Ns
	
cGs|iit|�|�S(N(RR0R(RR
R((s/sys/lib/python/weakref.pyR0UscCs|iit||i�|�S(N(RR1RR(RR
R%((s/sys/lib/python/weakref.pyR1XscKs�|i}|dj	o]t|d�pth�|�}nx4|i�D]"\}}||t||i�<qIWnt|�o|i|�ndS(NR"(	RRR2R3R"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>s4		�

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].