
    uYfc                         d dl mZ d dl mZ d dl mZ d dl mZ d dlZddlmZ ddlm	Z	  ee
      Zd	Zd
ez   Z G d de      Zy)    )TYPE_CHECKING)Any)Dict)OptionalN   )
get_logger)wrapt_datadog_pin_self_c                        e Zd ZdZg dZ	 	 	 	 ddZed        Z fdZd Z	e
d        Ze
d        Ze	 	 	 dd	       Zd
 ZddZd Z	 	 	 ddZ xZS )Pina  Pin (a.k.a Patch INfo) is a small class which is used to
    set tracing metadata on a particular traced connection.
    This is useful if you wanted to, say, trace two different
    database clusters.

        >>> conn = sqlite.connect('/tmp/user.db')
        >>> # Override a pin for a specific connection
        >>> pin = Pin.override(conn, service='user-db')
        >>> conn = sqlite.connect('/tmp/image.db')
    )tagstracer_target_config_initializedc                     |xs t         j                  }|| _        || _        d | _        |xs i | _        || j                  d<   d| _        y )Nservice_nameT)ddtracer   r   r   r   r   )selfservicer   r   r   s        K/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/ddtrace/pin.py__init__zPin.__init__#   sJ     )7>>	 }"'.^$     c                      | j                   d   S )zoBackward compatibility: accessing to `pin.service` returns the underlying
        configuration value.
        r   )r   r   s    r   r   zPin.service6   s     ||N++r   c                 h    t        | dd      r|dk7  rt        d      t        t        |   ||       y )Nr   Fr   z5can't mutate a pin, use override() or clone() instead)getattrAttributeErrorsuperr   __setattr__)r   namevalue	__class__s      r   r!   zPin.__setattr__>   s3    4/DI4E !XYYc4$T51r   c                 V    d| j                   d| j                  d| j                  dS )NzPin(service=z, tags=z	, tracer=)r   r   r   r   s    r   __repr__zPin.__repr__C   s    8<diiQUQ\Q\]]r   c                  H    | D ]  }t         j                  |      }|s|c S  y)a  
        Return the first :class:`ddtrace.pin.Pin` found on any of the provided objects or `None` if none were found


            >>> pin = Pin._find(wrapper, instance, conn)

        :param objs: The objects to search for a :class:`ddtrace.pin.Pin` on
        :type objs: List of objects
        :rtype: :class:`ddtrace.pin.Pin`, None
        :returns: The first found :class:`ddtrace.pin.Pin` or `None` is none was found
        N)r   get_from)objsobjpins      r   _findz	Pin._findF   s.      	C,,s#C
	 r   c                    t        | d      r| j                         S t        | t        j                        rt
        nt        }t        | |d      }|9|j                  t        |       k7  r!|j                         }|j                  |        |S )ak  Return the pin associated with the given object. If a pin is attached to
        `obj` but the instance is not the owner of the pin, a new pin is cloned and
        attached. This ensures that a pin inherited from a class is a copy for the new
        instance, avoiding that a specific instance overrides other pins values.

            >>> pin = Pin.get_from(conn)

        :param obj: The object to look for a :class:`ddtrace.pin.Pin` on
        :type obj: object
        :rtype: :class:`ddtrace.pin.Pin`, None
        :returns: :class:`ddtrace.pin.Pin` associated with the object, or None if none was found
        __getddpin__N)hasattrr0   
isinstancer	   ObjectProxy_DD_PIN_PROXY_NAME_DD_PIN_NAMEr   r   idcloneonto)r,   pin_namer-   s      r   r*   zPin.get_fromZ   sr     3'##%%)3C9J9J)K%Q]c8T*?s{{bg5))+CHHSM
r   c                     |sy| j                  |      }|t        |||      j                  |       y|j                  |||      j                  |       y)a[  Override an object with the given attributes.

        That's the recommended way to customize an already instrumented client, without
        losing existing attributes.

            >>> conn = sqlite.connect('/tmp/user.db')
            >>> # Override a pin for a specific connection
            >>> Pin.override(conn, service='user-db')
        Nr'   )r*   r   r8   r7   )clsr,   r   r   r   r-   s         r   overridezPin.overridet   sQ    $ ll3;d6:??DIIgDI@EEcJr   c                 \    t        | j                        xr | j                  j                  S )z,Return true if this pin's tracer is enabled.)boolr   enabledr   s    r   r?   zPin.enabled   s"     DKK 8T[[%8%88r   c                 z   	 t        |d      r|j                  |       S t        |t        j                        rt
        nt        }t        |      | _        | j                  r)t        j                  j                  | j                         t        |||       S # t        $ r t        j!                  dd       Y yw xY w)zPatch this pin onto the given object. If send is true, it will also
        queue the metadata to be sent to the server.
        __setddpin__zcan't pin onto object. skippingTexc_infoN)r1   rA   r2   r	   r3   r4   r5   r6   r   r   r   config_add_extra_servicesetattrr   logdebug)r   r,   sendr9   s       r   r8   zPin.onto   s    	HsN+''---7U=N=N-O)UaH c7DL||11$,,?3$// 	HII7$IG	Hs   B A7B  B:9B:c                     	 t        |t        j                        rt        nt        }t
        j                  |      }|t        ||       y y # t        $ r t        j                  dd       Y y w xY w)Nz&can't remove pin from object. skippingTrB   )r2   r	   r3   r4   r5   r   r*   delattrr   rG   rH   )r   r,   r9   r-   s       r   remove_fromzPin.remove_from   sd    	O-7U=N=N-O)UaH,,s#CX&  	OII>IN	Os   A	A  A0/A0c                     |s&| j                   r| j                   j                         }| j                  j                         }t        |xs | j                  ||xs | j
                  |      S )z=Return a clone of the pin with the given attributes replaced.)r   r   r   r   )r   copyr   r   r   r   )r   r   r   r   rD   s        r   r7   z	Pin.clone   s\     		99>>#D ""$+t||(T[[	
 	
r   )NNNN)NNN)T)__name__
__module____qualname____doc__	__slots__r   propertyr   r!   r(   staticmethodr.   r*   classmethodr<   r?   r8   rL   r7   __classcell__)r$   s   @r   r   r      s    	 II !& , ,2
^  &  2  K K49
H(
O 	
r   r   )typingr   r   r   r   r   internal.loggerr   vendorr	   rO   rG   r5   r4   objectr    r   r   <module>r]      sF          '  
 , x
& x
r   