]ue#dZddlZddlZddlZddlZej dZej dZddZGddZ y) z-Refactored 'safe reference from dispatcher.pyN__self____func__c t|}|2t|dst|ds Jd|dt||}|Sy#t$r;t |rt j ||cYSt j |cYSwxYw)aReturn a *safe* weak reference to a callable target. - ``target``: The object to be weakly referenced, if it's a bound method reference, will create a BoundMethodWeakref, otherwise creates a simple weakref. - ``on_delete``: If provided, will have a hard reference stored to the callable to be called after the safe reference goes out of scope with the reference object, (either a weakref or a BoundMethodWeakref) as argument. Nim_funcrzsafe_ref target z@ has im_self, but no im_func, don't know how to create reference)target on_delete)get_selfhasattrBoundMethodWeakrefAttributeErrorcallableweakrefref)rrim_self references 2/usr/lib/python3/dist-packages/blinker/_saferef.pysafe_refr.s6"  69-1L "6*-55 L+&INI   ' I ;;vy1 1;;v& & 's A*B.BBceZdZdZej Zd fd Zd dZe dZ dZ e Z dZ dZdZd ZxZS) r a'Safe' and reusable weak references to instance methods. BoundMethodWeakref objects provide a mechanism for referencing a bound method without requiring that the method object itself (which is normally a transient object) is kept alive. Instead, the BoundMethodWeakref object keeps weak references to both the object and the function which together define the instance method. Attributes: - ``key``: The identity key for the reference, calculated by the class's calculate_key method applied to the target instance method. - ``deletion_methods``: Sequence of callable objects taking single argument, a reference to this object which will be called when *either* the target object or target function is garbage collected (i.e. when this object becomes invalid). These are specified as the on_delete parameters of safe_ref calls. - ``weak_self``: Weak reference to the target object. - ``weak_func``: Weak reference to the target function. Class Attributes: - ``_all_instances``: Class attribute pointing to all live BoundMethodWeakref objects indexed by the class's calculate_key(target) method applied to the target objects. This weak value dictionary is used to short-circuit creation so that multiple references to the same (object, function) pair produce the same BoundMethodWeakref instance. c|j|}|jj|}||jj ||St ||}||j|<|j||g|i||S)aCreate new instance or return current instance. Basically this method of construction allows us to short-circuit creation of references to already-referenced instance methods. The key corresponding to the target is calculated, and if there is already an existing reference, that is returned, with its deletion_methods attribute updated. Otherwise the new instance is created and registered in the table of already-referenced methods. ) calculate_key_all_instancesgetdeletion_methodsappendsuper__new____init__) clsrr argumentsnamedkeycurrentbase __class__s rrzBoundMethodWeakref.__new__qs'$$((-    $ $ + +I 6N7?3'D&*C  s # DMM&) Ai A5 AKc6|fd}|g|_|j||_t|}t |}t j |||_t j |||_t||_ t|j|_ y)aReturn a weak-reference-like instance for a bound method. - ``target``: The instance-method target for the weak reference, must have im_self and im_func attributes and be reconstructable via the following, which is true of built-in instance methods:: target.im_func.__get__( target.im_self ) - ``on_delete``: Optional callback which will be called when this weak reference ceases to be valid (i.e. either the object or the function is garbage collected). Should take a single argument, which will be passed a pointer to this object. c |jdd}|jdd= |jj|j=|D]} t |r||y#t$rY'wxYw#t $rS tjn:#t$r.tjd}td|d|d|YnwxYwYwxYw)z=Set self.isDead to True when method or instance is destroyed.NzException during saferef z cleanup function z: ) rr$rr!KeyErrorr Exception traceback print_excr sysexc_infoprint)weakselfmethodsfunctiones rremovez+BoundMethodWeakref.__init__..removes++A.G%%a( NN11$((;$  )     !!++-)LLN1-7v>008zA3@sG!AA, A)(A), C6B  C 4C?CCCCN) rrr!r get_funcrr weak_self weak_funcstr self_name__name__ func_name)r1rrr5rrs rrzBoundMethodWeakref.__init__s"# ,"+ %%f-6"6" Wf5 Wf5WW--.r%cRtt|tt|fS)zCalculate the reference key for this reference. Currently this is a two-tuple of the id()'s of the target object and the target function respectively. )idr r6)rrs rrz BoundMethodWeakref.calculate_keys#8F#$b&)9&:;;r%cxdj|jj|j|jS)z-Give a friendly representation of the object.z {}({}.{}))formatr$r;r:r<r1s r__str__zBoundMethodWeakref.__str__s0!! NN # # NN NN  r%cDt|j|jfSN)hashr:r!rAs r__hash__zBoundMethodWeakref.__hash__sT^^TXX.//r%c|duS)z'Whether we are still a valid reference.NrAs r __nonzero__zBoundMethodWeakref.__nonzero__svT!!r%ct||js)tj|jt |Stj|j |j S)zCompare with another reference.) isinstancer$operatoreqtyper!)r1others r__eq__zBoundMethodWeakref.__eq__sB%0;;t~~tE{; ;{{488UYY//r%cn|j}|#|j}||j|Sy)a?Return a strong reference to the bound method. If the target cannot be retrieved, then will return None, otherwise returns a bound instance method for our object and function. Note: You may call this method any number of times, as it does not invalidate the reference. N)r7r8__get__)r1rr3s r__call__zBoundMethodWeakref.__call__s<!  ~~'H#''//r%rD)r; __module__ __qualname____doc__rWeakValueDictionaryrrr classmethodrrB__repr__rFrIrPrS __classcell__)r$s@rr r MsZB1W002N,./`<< H0"0 r%r rD) rVrLr-r+r attrgetterr r6rr rHr%rr\sNF4  8  z * 8  z *>YYr%