
    'h$                        d Z ddlZddlZddlZddlZ	 e ej                  dk  r% ej                  d      Z	 ej                  d      Z
n$ ej                  d      Z	 ej                  d      Z
dd	Z G d
 de      Zy# e$ r d ZY rw xY w)z-Refactored 'safe reference from dispatcher.py    Nc                     t        | d      S )N__call__)hasattr)objects    P/var/www/html/scrapers/gsc/venv/lib/python3.12/site-packages/blinker/_saferef.pycallabler   .   s    vz**    )   im_selfim_func__self____func__c                    	 t        |       }|1t        | d      st        | d      s
J d| z         t        | |      }|S y# t        $ r; t	        |      rt        j                  | |      cY S t        j                  |       cY S w xY w)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.
    Nr   r   zRsafe_ref target %r has im_self, but no im_func, don't know how to create reference)target	on_delete)get_selfr   BoundMethodWeakrefAttributeErrorr   weakrefref)r   r   r   	references       r   safe_refr   :   s    6"  69-1L ?57=>?L +&INI   'I;;vy11;;v&&	's   A *B-BBc                        e Zd ZdZ ej
                         Zd	 fd	Zd	dZd Z	 e
e	      Z	d ZeZd Zd Zd Z xZS )
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                  |      }| j                  j                  |      }||j                  j	                  |       |S t
        t        |   |       }|| j                  |<    |j                  ||g|i | |S )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superr   __new____init__)	clsr   r   	argumentsnamedkeycurrentbase	__class__s	           r   r!   zBoundMethodWeakref.__new__|   s     '$$((-$$++I6N+S9#>D&*Cs#DMM&)AiA5AKr	   c                 6   | fd}|g| _         | j                  |      | _        t        |      }t	        |      }t        j                  ||      | _        t        j                  ||      | _        t        |      | _
        t        |j                        | _        y)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                    |j                   dd }|j                   dd= 	 |j                  j                  |j                  = |D ]  }	 t        |      r ||        y# t        $ r Y 'w xY w# t        $ rS 	 t        j                          n:# t        $ r. t        j                         d   }t        d|d|d|       Y nw xY wY w xY w)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   removez+BoundMethodWeakref.__init__.<locals>.remove   s    ++A.G%%a(NN11$((; $ 
P	P) 
P   ! PP!++-) PLLN1-<@(A O PPPsG   !A A,	A)(A),	C6B
C4C?CCCCN)r   r   r&   r   get_funcr   r   	weak_self	weak_funcstr	self_name__name__	func_name)r5   r   r   r9   r   r   s         r   r"   zBoundMethodWeakref.__init__   s      # 	P& "+%%f-6"6" Wf5 Wf5WW--.r	   c                 R    t        t        |            t        t        |            fS )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   r:   )r#   r   s     r   r   z BoundMethodWeakref.calculate_key   s#     8F#$b&)9&:;;r	   c                 x    dj                  | j                  j                  | j                  | j                        S )z-Give a friendly representation of the object.z	{}({}.{}))formatr)   r?   r>   r@   r5   s    r   __str__zBoundMethodWeakref.__str__   s0    !!NN##NNNN 	r	   c                      |        duS )z'Whether we are still a valid reference.N rE   s    r   __nonzero__zBoundMethodWeakref.__nonzero__   s    vT!!r	   c                     t        || j                        st        | j                  t        |            S t        | j                  |j                        S )zCompare with another reference.)
isinstancer)   cmptyper&   )r5   others     r   __cmp__zBoundMethodWeakref.__cmp__   s:    %0t~~tE{33488UYY''r	   c                 n    | j                         }|#| j                         }||j                  |      S y)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__)r5   r   r7   s      r   r   zBoundMethodWeakref.__call__   s<     !~~'H#''//r	   N)r?   
__module____qualname____doc__r   WeakValueDictionaryr   r!   r"   r   classmethodrF   __repr__rI   rO   r   __classcell__)r)   s   @r   r   r   X   sR    B 1W002N,*/X<  .M H"(r	   r   rR   )rU   operatorr1   r/   r   r   	NameErrorversion_info
attrgetterr   r:   r   r   r   rH   r	   r   <module>r^      s   F 4  
  + d"x""9-H"x""9-H"x"":.H"x"":.H<R RW  +++s   A> >B	B	