B ir @sddlmZmZmZmZmZmZmZmZddl m Z m Z ddl Z ddl Z ddlZeefZdddddd d d d d dddg ZGdddeZGdd d e jZGdddeZGddde jZGdddZdS))getweakrefcount getweakrefsrefproxyCallableProxyType ProxyType ReferenceType_remove_dead_weakref)WeakSet_IterationGuardNrrrrWeakKeyDictionaryrrr ProxyTypesWeakValueDictionaryr WeakMethodfinalizecs@eZdZdZd ddZfddZddZd d Zej Z Z S) r) _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/lib/python3.7/weakref.py_cb3s zWeakMethod.__new__.._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__ __slots__r"r'r*r,r__hash__ __classcell__rr)r(rr$s   c@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ e Z ddZ d*ddZddZddZeZddZddZd d!Zd"d#Zd+d$d%Zd&d'Zd(d)ZdS),rcOsl|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__..remove) rlenrr _remover5setr4r8update)argskwrr;rrr__init__fs  zWeakValueDictionary.__init__cCs,|j}|j}x|r&|}t||qWdS)N)r5r8popr )rldr7rrr_commit_removals}s z$WeakValueDictionary._commit_removalscCs4|jr||j|}|dkr,t|n|SdS)N)r5rFr8KeyError)rr7orrr __getitem__s   zWeakValueDictionary.__getitem__cCs|jr||j|=dS)N)r5rFr8)rr7rrr __delitem__szWeakValueDictionary.__delitem__cCs|jr|t|jS)N)r5rFr<r8)rrrr__len__szWeakValueDictionary.__len__cCs<|jr|y|j|}Wntk r2dSX|dk S)NF)r5rFr8rG)rr7rHrrr __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)r5rFKeyedRefr=r8)rr7valuerrr __setitem__szWeakValueDictionary.__setitem__c CsZ|jr|t}t|4x,|jD]\}}|}|dk r*|||<q*WWdQRX|S)N)r5rFrr r8items)rnewr7r9rHrrrcopys zWeakValueDictionary.copyc Csnddlm}|jr||}t|:x2|jD]$\}}|}|dk r8|||||<q8WWdQRX|S)Nr)deepcopy)rTrUr5rFr(r r8rR)rmemorUrSr7r9rHrrr __deepcopy__s  z WeakValueDictionary.__deepcopy__NcCsL|jr|y|j|}Wntk r0|SX|}|dkrD|S|SdS)N)r5rFr8rG)rr7defaultr9rHrrrgetszWeakValueDictionary.getc csV|jr|t|6x.|jD] \}}|}|dk r$||fVq$WWdQRXdS)N)r5rFr r8rR)rkr9vrrrrRs zWeakValueDictionary.itemsc csN|jr|t|.x&|jD]\}}|dk r$|Vq$WWdQRXdS)N)r5rFr r8rR)rrZr9rrrkeyss   zWeakValueDictionary.keysc cs6|jr|t||jEdHWdQRXdS)N)r5rFr r8values)rrrr itervaluerefss  z!WeakValueDictionary.itervaluerefsc csN|jr|t|.x&|jD]}|}|dk r$|Vq$WWdQRXdS)N)r5rFr r8r])rr9r$rrrr]s zWeakValueDictionary.valuescCs<|jr|x(|j\}}|}|dk r||fSqWdS)N)r5rFr8popitem)rr7r9rHrrrr_szWeakValueDictionary.popitemcGs`|jr|y|j|}Wntk r8d}YnX|dkrX|rN|dSt|n|SdS)Nr)r5rFr8rCrG)rr7r@rHrrrrCs  zWeakValueDictionary.popcCs`y|j|}Wntk r(d}YnX|dkrX|jr@|t||j||j|<|S|SdS)N)r8rGr5rFrOr=)rr7rXrHrrr 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 argumentr3z$expected at most 1 arguments, got %drrR) rr<r5rFr8hasattrr!rRrOr=r?)r@kwargsrdictrEr7rHrrrr?"s    zWeakValueDictionary.updatecCs|jr|t|jS)N)r5rFlistr8r])rrrr valuerefs5s zWeakValueDictionary.valuerefs)N)N)r-r.r/rBrFrIrJrKrLrNrQrT__copy__rWrYrRr\__iter__r^r]r_rCr`r?rerrrrrZs,          cs(eZdZdZddZfddZZS)rO)r7cCst|||}||_|S)N)rr"r7)r!obrr7rrrrr"PszKeyedRef.__new__cst||dS)N)r&rB)rrhrr7)r(rrrBUszKeyedRef.__init__)r-r.r/r0r"rBr2rr)r(rrODs rOc@seZdZd*ddZddZddZdd Zd d Zd d ZddZ ddZ ddZ e Z ddZ d+ddZddZddZddZeZddZd d!Zd"d#Zd$d%Zd,d&d'Zd-d(d)ZdS).r NcCsFi|_t|fdd}||_g|_t|_d|_|dk rB||dS)NcSs.|}|dk r*|jr"|j|n|j|=dS)N)r4r5r6r8)rZr:rrrrr;fs z*WeakKeyDictionary.__init__..removeF)r8rr=r5r>r4 _dirty_lenr?)rrcr;rrrrBdszWeakKeyDictionary.__init__cCs>|j}|j}x,|r8y||=Wqtk r4YqXqWdS)N)r5r8rCrG)rrDrErrrrFusz"WeakKeyDictionary._commit_removalscs&|jfdd|jD|_d|_dS)Ncsg|]}|kr|qSrr).0rZ)rErr sz5WeakKeyDictionary._scrub_removals..F)r8r5ri)rr)rEr_scrub_removalssz!WeakKeyDictionary._scrub_removalscCsd|_|jt|=dS)NT)rir8r)rr7rrrrJszWeakKeyDictionary.__delitem__cCs|jt|S)N)r8r)rr7rrrrIszWeakKeyDictionary.__getitem__cCs(|jr|jr|t|jt|jS)N)rir5rlr<r8)rrrrrKs zWeakKeyDictionary.__len__cCsd|jjt|fS)Nz <%s at %#x>)r(r-rM)rrrrrNszWeakKeyDictionary.__repr__cCs||jt||j<dS)N)r8rr=)rr7rPrrrrQszWeakKeyDictionary.__setitem__c CsLt}t|4x,|jD]\}}|}|dk r|||<qWWdQRX|S)N)r r r8rR)rrSr7rPrHrrrrTs zWeakKeyDictionary.copyc Cs`ddlm}|}t|:x2|jD]$\}}|}|dk r*|||||<q*WWdQRX|S)Nr)rU)rTrUr(r r8rR)rrVrUrSr7rPrHrrrrWs  zWeakKeyDictionary.__deepcopy__cCs|jt||S)N)r8rYr)rr7rXrrrrYszWeakKeyDictionary.getcCs,y t|}Wntk r dSX||jkS)NF)rrr8)rr7r9rrrrLs  zWeakKeyDictionary.__contains__c csHt|6x.|jD] \}}|}|dk r||fVqWWdQRXdS)N)r r8rR)rr9rPr7rrrrRs  zWeakKeyDictionary.itemsc cs<t|*x"|jD]}|}|dk r|VqWWdQRXdS)N)r r8)rr9r$rrrr\s   zWeakKeyDictionary.keysc cs@t|.x&|jD]\}}|dk r|VqWWdQRXdS)N)r r8rR)rr9rPrrrr]s  zWeakKeyDictionary.valuescCs t|jS)N)rdr8)rrrrkeyrefss zWeakKeyDictionary.keyrefscCs4d|_x(|j\}}|}|dk r||fSqWdS)NT)rir8r_)rr7rPrHrrrr_s zWeakKeyDictionary.popitemcGsd|_|jjt|f|S)NT)rir8rCr)rr7r@rrrrCszWeakKeyDictionary.popcCs|jt||j|S)N)r8r`rr=)rr7rXrrrr`szWeakKeyDictionary.setdefaultcKs`|j}|dk rJt|ds$ti|}x$|D]\}}||t||j<q.Wt|r\||dS)NrR)r8rar!rRrr=r<r?)rrcrbrEr7rPrrrr?s  zWeakKeyDictionary.update)N)N)N)N)r-r.r/rBrFrlrJrIrKrNrQrTrfrWrYrLrRr\rgr]rmr_rCr`r?rrrrr Ys,      c@seZdZdZiZdZeZdZ dZ GdddZ ddZ ddd Z d d Zd d ZeddZeddZejddZddZeddZeddZdS)rrFc@seZdZdZdS)zfinalize._Info)weakrefr%r@rbatexitindexN)r-r.r/r0rrrr_InfosrqcOs 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) Nzs  zfinalize.detachcCs:|j|}|o|}|dk r6||j|j|jp2ifSdS)N)rzrYrnr%r@rb)rr|r$rrrpeekFs  z finalize.peekcCs ||jkS)N)rz)rrrraliveNszfinalize.alivecCs|j|}t|o|jS)N)rzrYboolro)rr|rrrroSs zfinalize.atexitcCs|j|}|rt||_dS)N)rzrYrro)rrPr|rrrroYs 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>)rzrYrnr!r-rM)rr|r$rrrrN_s   zfinalize.__repr__cCs2dd|jD}|jddddd|DS)NcSsg|]\}}|jr||fqSr)ro)rjfirrrrkksz-finalize._select_for_exit..cSs |djS)Nr3)rp)itemrrrlz+finalize._select_for_exit..)r7cSsg|] \}}|qSrr)rjrrrrrrkms)rzrRsort)r#Lrrr_select_for_exithszfinalize._select_for_exitcCsd}z|jrddl}|r(d}|d}x\|dks s (  6k