
    uYf                         d dl Z d dlmZ 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 ej                   d       G d de             Zy# e$ r	 d d
l mZ Y 7w xY w)    N)deepcopy)Any)Callable)Optional)Set   )
get_logger)DefaultDict)defaultdictT)slotsc                   h    e Zd ZdZ ej
                  dd eeef         Z	d
dZ
	 d
dZeZd Zd	 Zy)Hooksz
    Hooks configuration object is used for registering and calling hook functions

    Example::

        @config.falcon.hooks.on('request')
        def on_request(span, request, response):
            pass
    Fc                  4    t        j                  t              S N)collectionsr   set     N/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/ddtrace/_hooks.py<lambda>zHooks.<lambda>!   s    1H1H1M r   )initfactorytypeNc                 P    t               }t        | j                  |      |_        |S r   )r   r   _hooks)selfmemodicthookss      r   __deepcopy__zHooks.__deepcopy__#   s     X6r   c                 X     |s fd}|S  j                      j                  |       y)a  
        Function used to register a hook for the provided name.

        Example::

            def on_request(span, request, response):
                pass

            config.falcon.hooks.register('request', on_request)


        If no function is provided then a decorator is returned::

            @config.falcon.hooks.register('request')
            def on_request(span, request, response):
                pass

        :param hook: The name of the hook to register the function for
        :type hook: object
        :param func: The function to register, or ``None`` if a decorator should be returned
        :type func: function, None
        :returns: Either a function decorator if ``func is None``, otherwise ``None``
        :rtype: function, None
        c                 ,    j                  |        | S r   )register)funchookr   s    r   wrapperzHooks.register.<locals>.wrapperI   s    dD)r   N)r   add)r   r$   r#   r%   s   ``  r   r"   zHooks.register(   s.    >  NDd#r   c                 ~    || j                   v r 	 | j                   |   j                  |       yy# t        $ r Y yw xY w)a  
        Function to deregister a function from a hook it was registered under

        Example::

            @config.falcon.hooks.on('request')
            def on_request(span, request, response):
                pass

            config.falcon.hooks.deregister('request', on_request)

        :param hook: The name of the hook to register the function for
        :type hook: object
        :param func: Function hook to register
        :type func: function
        N)r   removeKeyError)r   r$   r#   s      r   
deregisterzHooks.deregisterW   sE    , 4;;D!((.   s   0 	<<c                     | j                   j                  |d      D ]  }	  ||i |  y# t        $ r t        j	                  d||d       Y 3w xY w)aR  
        Function used to call registered hook functions.

        :param hook: The hook to call functions for
        :type hook: str
        :param args: Positional arguments to pass to the hook functions
        :type args: list
        :param kwargs: Keyword arguments to pass to the hook functions
        :type kwargs: dict
        r   z!Failed to run hook %s function %sT)exc_infoN)r   get	Exceptionlogerror)r   r$   argskwargsr#   s        r   emitz
Hooks.emits   s`    $ KKOOD"- 	ZDZd%f%	Z  Z		=tTTX	YZs   ,"AAr   )__name__
__module____qualname____doc__attribr
   strr   r   r   r"   onr*   r3   r   r   r   r   r      sM     TWW%)MT_`ceh`hTijF 'Z 
B8Zr   r   )r   copyr   typingr   r   r   r   r8   internal.loggerr	   r
   ImportErrorr   r4   r/   sobjectr   r   r   r   <module>rB      sq           '7"  dsZF sZ sZ  767s   A A,+A,