h fK @s"dZddlmZmZmZmZmZmZmZddl m Z m Z ddl Z ddl Z ddlZeefZddddd d d d 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/ )getweakrefcount getweakrefsrefproxyCallableProxyType ProxyType ReferenceType)WeakSet_IterationGuardNrrrrWeakKeyDictionaryrrr ProxyTypesWeakValueDictionaryr WeakMethodfinalizecs^eZdZdZdZdddZfd d Zd d Zd dZe j Z S)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__Nc sy|j}|j}Wn0tk rHtdjt|dYnXfdd}tj|||}t|||_t||_ d|_ t||S)Nz)argument should be a bound method, not {}cs;}|jr7d|_dk r7|q7ndS)NF)r)argself)callbackself_wr,/opt/alt/python34/lib64/python3.4/weakref.py_cb2s     zWeakMethod.__new__.._cbT) __self____func__AttributeError TypeErrorformattyper__new__rrr)clsmethrobjfuncrrr)rrrr!+s      zWeakMethod.__new__csGtj}|j}|dks3|dkr7dS|j||S)N)super__call__rr)rr$r%) __class__rrr'As  zWeakMethod.__call__cCsSt|trO|j s#|j r-||kStj||oN|j|jkSdS)NF) isinstancerrr__eq__r)rotherrrrr*Hs  "zWeakMethod.__eq__cCsSt|trO|j s#|j r-||k Stj||pN|j|jkSdS)NT)r)rrr__ne__r)rr+rrrr,Os  "zWeakMethod.__ne__)z _func_refz _meth_typez_alivez __weakref__) __name__ __module__ __qualname____doc__ __slots__r!r'r*r,r__hash__rr)r(rr#s   c@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ e Z ddZdddZddZddZeZddZdd Zd!d"Zd#d$Zdd%d&Zd'd(Zd)d*ZdS)+r zMapping class that references values weakly. Entries in the dictionary will be discarded when no strong reference to the value exists anymore cOs|stdn|^}}t|dkrLtdt|nt|dd}||_g|_t|_i|_}|j||dS)NzGdescriptor '__init__' of 'WeakValueDictionary' object needs an argumentz$expected at most 1 arguments, got %dcSsH|}|dk rD|jr4|jj|jqD|j|j=ndS)N) _iterating_pending_removalsappendkeydata)wrselfrefrrrrremovels    z,WeakValueDictionary.__init__..remove) rlenr_remover5setr4r8update)argskwrr;drrr__init__es     zWeakValueDictionary.__init__cCs0|j}|j}x|r+||j=qWdS)N)r5r8pop)rlrBrrr_commit_removalszs   z$WeakValueDictionary._commit_removalscCs3|j|}|dkr+t|n|SdS)N)r8KeyError)rr7orrr __getitem__s zWeakValueDictionary.__getitem__cCs$|jr|jn|j|=dS)N)r5rFr8)rr7rrr __delitem__s  zWeakValueDictionary.__delitem__cCst|jt|jS)N)r<r8r5)rrrr__len__szWeakValueDictionary.__len__c Cs7y|j|}Wntk r,dSYnX|dk S)NF)r8rG)rr7rHrrr __contains__s   z WeakValueDictionary.__contains__cCsdt|S)Nz)id)rrrr__repr__szWeakValueDictionary.__repr__cCs6|jr|jnt||j||j||jr1|jj|q>|j|=ndS)N)r4r5r6r8)rZr:rrrrr;Gs    z*WeakKeyDictionary.__init__..removeF)r8rr=r5r>r4 _dirty_lenr?)rrcr;rrrrCEs      zWeakKeyDictionary.__init__c CsI|j}|j}x0|rDy||j=Wqtk r@YqXqWdS)N)r5r8rDrG)rrErBrrrrFVs    z"WeakKeyDictionary._commit_removalscs5|jfdd|jD|_d|_dS)Ncs"g|]}|kr|qSrr).0rZ)rBrr es z5WeakKeyDictionary._scrub_removals..F)r8r5ri)rr)rBr_scrub_removalscs z!WeakKeyDictionary._scrub_removalscCsd|_|jt|=dS)NT)rir8r)rr7rrrrJhs zWeakKeyDictionary.__delitem__cCs|jt|S)N)r8r)rr7rrrrIlszWeakKeyDictionary.__getitem__cCs9|jr|jr|jnt|jt|jS)N)rir5rlr<r8)rrrrrKos zWeakKeyDictionary.__len__cCsdt|S)Nz)rM)rrrrrNvszWeakKeyDictionary.__repr__cCs||jt||jz!<%s object at %#x; for %r at %#x>)rwrYrnr r-rM)rryr$rrrrN*s  zfinalize.__repr__cCsCdd|jjD}|jddddd|DS)NcSs+g|]!\}}|jr||fqSr)ro)rjfirrrrk6s z-finalize._select_for_exit..r7cSs |djS)Nr3)rp)itemrrr7sz+finalize._select_for_exit..cSsg|]\}}|qSrr)rjrrrrrrk8s )rwrRsort)r"Lrrr_select_for_exit3szfinalize._select_for_exitcCsd}z|jrddl}|jr=d}|jnd}x|dks[tjrs|j}dt_n|s}Pn|j}y |Wn%tk rt j t j YnX||jksFt qFWnWddt_ |r|jnXdS)NFrT)rwgc isenableddisablerrxrrD Exceptionsys excepthookexc_infoAssertionErrorrzenable)r" reenable_gcrpendingrrrrrt:s.           zfinalize._exitfunc)r-r.r/r0r1rwrz itertoolscountrvrxrrrqrCr'r|r}propertyr~rosetterrN classmethodrrtrrrrrs$      )r0_weakrefrrrrrrr _weakrefsetr r collectionsrrr __all__rMutableMappingr rOr rrrrrs4        6