
    vKg#                         S r SSKrSSKrSSKrSSKr\R
                  " S5      r\R
                  " S5      rSS jr " S S5      r	g)	z-Refactored 'safe reference from dispatcher.py    N__self____func__c                 0    [        U 5      nUb9  [        U S5      (       d  [        U S5      (       d   SU < S35       e[        XS9nU$ g! [         aA    [	        U5      (       a  [
        R                  " X5      s $ [
        R                  " U 5      s $ f = f)a  Return 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.
Nim_funcr   zsafe_ref target z@ has im_self, but no im_func, don't know how to create reference)target	on_delete)get_selfhasattrBoundMethodWeakrefAttributeErrorcallableweakrefref)r   r   im_self	references       P/var/www/highfloat_scraper/venv/lib/python3.13/site-packages/blinker/_saferef.pysafe_refr   .   s    6"  69--1L1L "6* -5 5L +&NI   'I;;v11;;v&&	's   A
 
0B<BBc                      ^  \ rS rSrSr\R                  " 5       rSU 4S jjrSS jr	\
S 5       rS r\rS rS rS	 rS
 rSrU =r$ )r   M   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                   > U R                  U5      nU R                  R                  U5      nUb  UR                  R	                  U5        U$ [
        TU ]  U 5      nXpR                  U'   UR                  " X/UQ70 UD6  U$ )a  Create 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_instancesgetdeletion_methodsappendsuper__new____init__)	clsr   r   	argumentsnamedkeycurrentbase	__class__s	           r   r   BoundMethodWeakref.__new__q   s     '$$((-$$++I6N7?3'D&*s#MM&AiA5AK    c                 8   U 4S jnU/U l         U R                  U5      U l        [        U5      n[	        U5      n[
        R                  " XC5      U l        [
        R                  " XS5      U l        [        U5      U l
        [        UR                  5      U l        g)a+  Return 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                    UR                   SS nUR                   SS2	  UR                  R                  UR                  	 U H  n [        U5      (       a
  U" U5        M  M      g! [         a     N1f = f! [         aX     [        R                  " 5          MV  ! [         a1    [        R                  " 5       S   n[        SU SU SU 35          M  f = ff = f)z=Set self.isDead to True when method or instance is destroyed.N   zException during saferef z cleanup function z: )r   r%   r   r"   KeyErrorr   	Exception	traceback	print_excr   sysexc_infoprint)weakselfmethodsfunctiones        r   remove+BoundMethodWeakref.__init__.<locals>.remove   s    ++A.G%%a(NN11$((; $))  * $   ! !++-) LLN1-7v >008zA3@ s;   !A& A6&
A32A36
CB6CCCCN)r   r   r"   r	   get_funcr   r   	weak_self	weak_funcstr	self_name__name__	func_name)r3   r   r   r7   r   r   s         r   r   BoundMethodWeakref.__init__   s{    " # 	, "+%%f-6"6" W5 W5WW--.r'   c                 R    [        [        U5      5      [        [        U5      5      4$ )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	   r9   )r   r   s     r   r    BoundMethodWeakref.calculate_key   s#     8F#$b&)9&:;;r'   c                 x    SR                  U R                  R                  U R                  U R                  5      $ )z-Give a friendly representation of the object.z	{}({}.{}))formatr%   r>   r=   r?   r3   s    r   __str__BoundMethodWeakref.__str__   s0    !!NN##NNNN
 	
r'   c                 D    [        U R                  U R                  45      $ N)hashr=   r"   rF   s    r   __hash__BoundMethodWeakref.__hash__   s    T^^TXX.//r'   c                     U " 5       SL$ )z'Whether we are still a valid reference.N rF   s    r   __nonzero__BoundMethodWeakref.__nonzero__   s    vT!!r'   c                     [        XR                  5      (       d*  [        R                  " U R                  [	        U5      5      $ [        R                  " U R
                  UR
                  5      $ )zCompare with another reference.)
isinstancer%   operatoreqtyper"   )r3   others     r   __eq__BoundMethodWeakref.__eq__   sC    %00;;t~~tE{;;{{488UYY//r'   c                 r    U R                  5       nUb$  U R                  5       nUb  UR                  U5      $ g)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)r:   r;   __get__)r3   r   r5   s      r   __call__BoundMethodWeakref.__call__   s<     !~~'H#''//r'   )r   r?   r"   r=   r;   r:   rJ   )r>   
__module____qualname____firstlineno____doc__r   WeakValueDictionaryr   r   r   classmethodr   rG   __repr__rL   rP   rX   r\   __static_attributes____classcell__)r%   s   @r   r   r   M   s]    B 002N,./` < <
 H0"0 r'   r   rJ   )
ra   rT   r/   r-   r   
attrgetterr	   r9   r   r   rO   r'   r   <module>rh      sJ   F 4  
   z*z*>Y Yr'   