
    mhu                         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ZddlmZ  ee	          Z
dZd	ez   Z G d
 de          ZdS )    )TYPE_CHECKING)Any)Dict)OptionalN   )
get_logger_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_initializedNc                     |pt           j        }|| _        || _        d | _        |pi | _        || j        d<   d| _        d S )Nservice_nameT)ddtracer   r   r   r   r   )selfservicer   r   r   s        6/usr/local/lib/python3.11/site-packages/ddtrace/pin.py__init__zPin.__init__$   sL     )7>	 }"'.^$     c                     | j         d         S )zoBackward compatibility: accessing to `pin.service` returns the underlying
        configuration value.
        r   )r   r   s    r   r   zPin.service7   s     |N++r   c                     t          | dd          r|dk    rt          d          t          t          |                               ||           d S )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__?   sW    4// 	ZDI4E4E !XYYYc4$$T511111r   c                 8    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__D   s'     8<diiiQUQ\Q\Q\]]r   c                  P    | D ]"}t                               |          }|r|c S #dS )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._findG   s?      	 	C,,s##C 


tr   c                 F   t          | d          r|                                 S t          | t          j                  rt
          nt          }t          | |d          }|A|j        t          |           k    r)|
                                }|                    |            |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)hasattrr/   
isinstancewraptObjectProxy_DD_PIN_PROXY_NAME_DD_PIN_NAMEr   r   idcloneonto)r+   pin_namer,   s      r   r)   zPin.get_from[   s     3'' 	&##%%%)3C9J)K)K]%%Q]c8T**?s{bgg55))++CHHSMMM
r   c                     |sdS |                      |          }|'t          |||                              |           dS |                    |||                              |           dS )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.overrideu   s|    $  	Fll3;d6:::??DDDDDIIgDI@@EEcJJJJJr   c                 Z    t          | j                  o| j        j        p| j        j        S )z,Return true if this pin's tracer is enabled.)boolr   enabled_apm_opt_outr   s    r   r?   zPin.enabled   s(     DK  Vdk&9&UT[=UVr   Tc                    	 t          |d          r|                    |           S t          |t          j                  rt
          nt          }t          |          | _        | j	        r$t          j                            | j	                   t          |||           S # t          $ r  t                              dd           Y dS 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)r0   rB   r1   r2   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-O-Oa))UaH c77DL| @11$,???3$/// 	H 	H 	HII7$IGGGGGG	Hs   $B A7B &C	C	c                    	 t          |t          j                  rt          nt          }t
                              |          }|t          ||           d S d S # t          $ r  t          
                    dd           Y d S w xY w)Nz&can't remove pin from object. skippingTrC   )r1   r2   r3   r4   r5   r   r)   delattrr   rH   rI   )r   r+   r9   r,   s       r   remove_fromzPin.remove_from   s    	O-7U=N-O-Oa))UaH,,s##CX&&&&&  	O 	O 	OII>INNNNNN	Os   AA &BBc                     |s | j         r| j                                         }| j                                        }t          |p| j        ||p| 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   rE   s        r   r7   z	Pin.clone   sl      	$	 	$9>>##D ""$$+t|(T[	
 
 
 	
r   )NNNN)NNN)T)__name__
__module____qualname____doc__	__slots__r   propertyr   r    r'   staticmethodr-   r)   classmethodr<   r?   r8   rM   r7   __classcell__)r#   s   @r   r   r      s_       	 	 IHHI ! ! ! !& , , X,2 2 2 2 2
^ ^ ^   \&   \2  K K K [K4W W W
H H H H(
O 
O 
O 	
 
 
 
 
 
 
 
r   r   )typingr   r   r   r   r2   r   internal.loggerr   rP   rH   r5   r4   objectr    r   r   <module>r]      s                                    ' ' ' ' ' ' j
 , x
 x
 x
 x
 x
& x
 x
 x
 x
 x
r   