• File: weakref.cpython-37.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/opt/alt/python37/lib64/python3.7/__pycache__/weakref.cpython-37.pyc
  • Date Modified: 10/26/2026 8:08 PM
  • File size: 19.11 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit
B

LjT
@sdZddlmZmZmZmZmZmZmZm	Z	ddl
mZmZddl
Z
ddlZddlZeefZddddd	d
ddd
ddddg
ZGdddeZGddde
jZGdddeZGdd	d	e
jZGdddZdS)z{Weak reference support for Python.

This module is an implementation of PEP 205:

http://www.python.org/dev/peps/pep-0205/
)getweakrefcountgetweakrefsrefproxyCallableProxyType	ProxyType
ReferenceType_remove_dead_weakref)WeakSet_IterationGuardNrrrrWeakKeyDictionaryrrr
ProxyTypesWeakValueDictionaryr

WeakMethodfinalizecsDeZdZdZdZdddZfddZdd	Zd
dZe	j
Z
ZS)
rz
    A custom `weakref.ref` subclass which simulates a weak reference to
    a bound method, working around the lifetime problem of bound methods.
    )	_func_ref
_meth_type_alive__weakref__Ncs~y|j}|j}Wn(tk
r8tdt|dYnXfdd}t|||}t|||_t||_	d|_
t||S)Nz)argument should be a bound method, not {}cs&}|jr"d|_dk	r"|dS)NF)r)argself)callbackself_wr,/opt/alt/python37/lib64/python3.7/weakref.py_cb3s
zWeakMethod.__new__.<locals>._cbT)__self____func__AttributeError	TypeErrorformattyper__new__rrr)clsZmethrobjfuncrrr)rrrr",s

zWeakMethod.__new__cs2t}|}|dks"|dkr&dS|||S)N)super__call__rr)rr$r%)	__class__rrr'Bs

zWeakMethod.__call__cCs:t|tr6|jr|js||kSt||o4|j|jkSdS)NF)
isinstancerrr__eq__r)rotherrrrr*Is

zWeakMethod.__eq__cCs:t|tr6|jr|js||k	St||p4|j|jkSdS)NT)r)rrr__ne__r)rr+rrrr,Ps

zWeakMethod.__ne__)N)__name__
__module____qualname____doc__	__slots__r"r'r*r,r__hash__
__classcell__rr)r(rr$s
c@seZdZdZddZddZddZdd	Zd
dZdd
Z	ddZ
ddZddZeZ
ddZd+ddZddZddZeZddZdd Zd!d"Zd#d$Zd,d%d&Zd'd(Zd)d*ZdS)-rzMapping class that references values weakly.

    Entries in the dictionary will be discarded when no strong
    reference to the value exists anymore
    cOsl|std|^}}t|dkr0tdt|t|tfdd}||_g|_t|_i|_|j	||dS)NzGdescriptor '__init__' of 'WeakValueDictionary' object needs an argumentz$expected at most 1 arguments, got %dcSs6|}|dk	r2|jr$|j|jn||j|jdS)N)
_iterating_pending_removalsappendkeydata)wrselfrefZ_atomic_removalrrrrremovems
z,WeakValueDictionary.__init__.<locals>.remove)
rlenrr	_remover6setr5r9update)argskwrr<rrr__init__fs	zWeakValueDictionary.__init__cCs,|j}|j}x|r&|}t||qWdS)N)r6r9popr	)rldr8rrr_commit_removals}s
z$WeakValueDictionary._commit_removalscCs4|jr||j|}|dkr,t|n|SdS)N)r6rGr9KeyError)rr8orrr__getitem__s
zWeakValueDictionary.__getitem__cCs|jr||j|=dS)N)r6rGr9)rr8rrr__delitem__szWeakValueDictionary.__delitem__cCs|jr|t|jS)N)r6rGr=r9)rrrr__len__szWeakValueDictionary.__len__cCs<|jr|y|j|}Wntk
r2dSX|dk	S)NF)r6rGr9rH)rr8rIrrr__contains__sz WeakValueDictionary.__contains__cCsd|jjt|fS)Nz<%s at %#x>)r(r-id)rrrr__repr__szWeakValueDictionary.__repr__cCs&|jr|t||j||j|<dS)N)r6rGKeyedRefr>r9)rr8valuerrr__setitem__szWeakValueDictionary.__setitem__c	CsZ|jr|t}t|4x,|jD]\}}|}|dk	r*|||<q*WWdQRX|S)N)r6rGrrr9items)rnewr8r:rIrrrcopys
zWeakValueDictionary.copyc	Csnddlm}|jr||}t|:x2|jD]$\}}|}|dk	r8|||||<q8WWdQRX|S)Nr)deepcopy)rUrVr6rGr(rr9rS)rmemorVrTr8r:rIrrr__deepcopy__s
z WeakValueDictionary.__deepcopy__NcCsL|jr|y|j|}Wntk
r0|SX|}|dkrD|S|SdS)N)r6rGr9rH)rr8defaultr:rIrrrgetszWeakValueDictionary.getc	csV|jr|t|6x.|jD] \}}|}|dk	r$||fVq$WWdQRXdS)N)r6rGrr9rS)rkr:vrrrrSs
zWeakValueDictionary.itemsc	csN|jr|t|.x&|jD]\}}|dk	r$|Vq$WWdQRXdS)N)r6rGrr9rS)rr[r:rrrkeyss

zWeakValueDictionary.keysc	cs6|jr|t||jEdHWdQRXdS)aReturn 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)r6rGrr9values)rrrr
itervaluerefss

z!WeakValueDictionary.itervaluerefsc	csN|jr|t|.x&|jD]}|}|dk	r$|Vq$WWdQRXdS)N)r6rGrr9r^)rr:r$rrrr^s
zWeakValueDictionary.valuescCs<|jr|x(|j\}}|}|dk	r||fSqWdS)N)r6rGr9popitem)rr8r:rIrrrr`szWeakValueDictionary.popitemcGs`|jr|y|j|}Wntk
r8d}YnX|dkrX|rN|dSt|n|SdS)Nr)r6rGr9rDrH)rr8rArIrrrrDs

zWeakValueDictionary.popcCs`y|j|}Wntk
r(d}YnX|dkrX|jr@|t||j||j|<|S|SdS)N)r9rHr6rGrPr>)rr8rYrIrrr
setdefaults
zWeakValueDictionary.setdefaultcOs|std|^}}t|dkr0tdt||r<|dnd}|jrN||j}|dk	rt|dsrti|}x&|D]\}}t||j	|||<q|Wt|r|
|dS)NzEdescriptor 'update' of 'WeakValueDictionary' object needs an argumentr4z$expected at most 1 arguments, got %drrS)rr=r6rGr9hasattrr!rSrPr>r@)rAkwargsrdictrFr8rIrrrr@"s 
zWeakValueDictionary.updatecCs|jr|t|jS)a~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.

        )r6rGlistr9r^)rrrr	valuerefs5s
zWeakValueDictionary.valuerefs)N)N)r-r.r/r0rCrGrJrKrLrMrOrRrU__copy__rXrZrSr]__iter__r_r^r`rDrar@rfrrrrrZs.			
			

cs,eZdZdZdZddZfddZZS)rPa[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.

    )r8cCst|||}||_|S)N)rr"r8)r!obrr8rrrrr"PszKeyedRef.__new__cst||dS)N)r&rC)rrirr8)r(rrrCUszKeyedRef.__init__)r-r.r/r0r1r"rCr3rr)r(rrPDsrPc@seZdZdZd+ddZddZddZd	d
ZddZd
dZ	ddZ
ddZddZeZ
ddZd,ddZddZddZddZeZdd Zd!d"Zd#d$Zd%d&Zd-d'd(Zd.d)d*ZdS)/ra 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.
    NcCsFi|_t|fdd}||_g|_t|_d|_|dk	rB||dS)NcSs.|}|dk	r*|jr"|j|n|j|=dS)N)r5r6r7r9)r[r;rrrrr<fs
z*WeakKeyDictionary.__init__.<locals>.removeF)r9rr>r6r?r5
_dirty_lenr@)rrdr<rrrrCdszWeakKeyDictionary.__init__cCs>|j}|j}x,|r8y||=Wqtk
r4YqXqWdS)N)r6r9rDrH)rrErFrrrrGusz"WeakKeyDictionary._commit_removalscs&|jfdd|jD|_d|_dS)Ncsg|]}|kr|qSrr).0r[)rFrr
<listcomp>sz5WeakKeyDictionary._scrub_removals.<locals>.<listcomp>F)r9r6rj)rr)rFr_scrub_removalssz!WeakKeyDictionary._scrub_removalscCsd|_|jt|=dS)NT)rjr9r)rr8rrrrKszWeakKeyDictionary.__delitem__cCs|jt|S)N)r9r)rr8rrrrJszWeakKeyDictionary.__getitem__cCs(|jr|jr|t|jt|jS)N)rjr6rmr=r9)rrrrrLszWeakKeyDictionary.__len__cCsd|jjt|fS)Nz<%s at %#x>)r(r-rN)rrrrrOszWeakKeyDictionary.__repr__cCs||jt||j<dS)N)r9rr>)rr8rQrrrrRszWeakKeyDictionary.__setitem__c	CsLt}t|4x,|jD]\}}|}|dk	r|||<qWWdQRX|S)N)rrr9rS)rrTr8rQrIrrrrUs
zWeakKeyDictionary.copyc	Cs`ddlm}|}t|:x2|jD]$\}}|}|dk	r*|||||<q*WWdQRX|S)Nr)rV)rUrVr(rr9rS)rrWrVrTr8rQrIrrrrXs
zWeakKeyDictionary.__deepcopy__cCs|jt||S)N)r9rZr)rr8rYrrrrZszWeakKeyDictionary.getcCs,yt|}Wntk
r dSX||jkS)NF)rrr9)rr8r:rrrrMs
zWeakKeyDictionary.__contains__c	csHt|6x.|jD] \}}|}|dk	r||fVqWWdQRXdS)N)rr9rS)rr:rQr8rrrrSs

zWeakKeyDictionary.itemsc	cs<t|*x"|jD]}|}|dk	r|VqWWdQRXdS)N)rr9)rr:r$rrrr]s

zWeakKeyDictionary.keysc	cs@t|.x&|jD]\}}|dk	r|VqWWdQRXdS)N)rr9rS)rr:rQrrrr^s

zWeakKeyDictionary.valuescCs
t|jS)azReturn 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.

        )rer9)rrrrkeyrefss
zWeakKeyDictionary.keyrefscCs4d|_x(|j\}}|}|dk	r||fSqWdS)NT)rjr9r`)rr8rQrIrrrr`szWeakKeyDictionary.popitemcGsd|_|jjt|f|S)NT)rjr9rDr)rr8rArrrrDszWeakKeyDictionary.popcCs|jt||j|S)N)r9rarr>)rr8rYrrrraszWeakKeyDictionary.setdefaultcKs`|j}|dk	rJt|ds$ti|}x$|D]\}}||t||j<q.Wt|r\||dS)NrS)r9rbr!rSrr>r=r@)rrdrcrFr8rQrrrr@s
zWeakKeyDictionary.update)N)N)N)N)r-r.r/r0rCrGrmrKrJrLrOrRrUrgrXrZrMrSr]rhr^rnr`rDrar@rrrrrYs.	

	


c@seZdZdZdZiZdZeZ	dZ
dZGdddZddZ
dd	d
ZddZd
dZeddZeddZejddZddZeddZeddZdS)raClass for finalization of weakrefable objects

    finalize(obj, func, *args, **kwargs) returns a callable finalizer
    object which will be called when obj is garbage collected. The
    first time the finalizer is called it evaluates func(*arg, **kwargs)
    and returns the result. After this the finalizer is dead, and
    calling it just returns None.

    When the program exits any remaining finalizers for which the
    atexit attribute is true will be run in reverse order of creation.
    By default atexit is true.
    rFc@seZdZdZdS)zfinalize._Info)weakrefr%rArcatexitindexN)r-r.r/r1rrrr_InfosrrcOst|dkr|^}}}}nz|s(tdnld|krDtdt|d|d}t|dkrf|^}}}n.d|krtdt|d|d}|^}}t|}|jsddl}||jd	t_|	}t
|||_||_||_
|pd|_d	|_t|j|_||j|<d	t_dS)
Nz<descriptor '__init__' of 'finalize' object needs an argumentr%z9finalize expected at least 2 positional arguments, got %dr4r$rT)r=rrDtuple_registered_with_atexitrpregister	_exitfuncrrrrror%rArcnext_index_iterrq	_registry_dirty)rArcrr$r%rpinforrrrCs:




zfinalize.__init__NcCs0|j|d}|r,|js,|j|j|jp(iSdS)zZIf alive then mark as dead and return func(*args, **kwargs);
        otherwise return NoneN)r{rD	_shutdownr%rArc)r_r}rrrr'7s
zfinalize.__call__cCsH|j|}|o|}|dk	rD|j|drD||j|j|jp@ifSdS)z^If alive then mark as dead and return (obj, func, args, kwargs);
        otherwise return NoneN)r{rZrorDr%rArc)rr}r$rrrdetach>szfinalize.detachcCs:|j|}|o|}|dk	r6||j|j|jp2ifSdS)zMIf alive then return (obj, func, args, kwargs);
        otherwise return NoneN)r{rZror%rArc)rr}r$rrrpeekFsz
finalize.peekcCs
||jkS)zWhether finalizer is alive)r{)rrrraliveNszfinalize.alivecCs|j|}t|o|jS)z*Whether finalizer should be called at exit)r{rZboolrp)rr}rrrrpSszfinalize.atexitcCs|j|}|rt||_dS)N)r{rZrrp)rrQr}rrrrpYscCs^|j|}|o|}|dkr6dt|jt|fSdt|jt|t|jt|fSdS)Nz<%s object at %#x; dead>z!<%s object at %#x; for %r at %#x>)r{rZror!r-rN)rr}r$rrrrO_szfinalize.__repr__cCs2dd|jD}|jddddd|DS)NcSsg|]\}}|jr||fqSr)rp)rkfirrrrlksz-finalize._select_for_exit.<locals>.<listcomp>cSs
|djS)Nr4)rq)itemrrr<lambda>lz+finalize._select_for_exit.<locals>.<lambda>)r8cSsg|]\}}|qSrr)rkrrrrrrlms)r{rSsort)r#Lrrr_select_for_exithszfinalize._select_for_exitcCsd}z|jrddl}|r(d}|d}xj|dks<tjrJ|}dt_|sPP|}y
|Wn"tk
rt	j
t	YnX||jks.tq.WWddt_
|r|XdS)NFrT)r{gcZ	isenabledZdisablerr|rrD	Exceptionsys
excepthookexc_infoAssertionErrorr~Zenable)r#Zreenable_gcrZpendingrrrrrxos.
zfinalize._exitfunc)N)r-r.r/r0r1r{r~	itertoolscountrzr|rvrrrCr'rrpropertyrrpsetterrOclassmethodrrxrrrrrs$%
	)r0_weakrefrrrrrrrr	Z_weakrefsetr
r_collections_abcrrr
__all__rMutableMappingrrPrrrrrr<module>s"(

6k