o
    Á¿i™  ã                   @   s8  d dl mZ d dl mZ d dl mZ d dl mZ G dd„ deƒZ	d deee ee f d	e	e
ef d
ede
dedee fdd„Z	d deedf d	e	e
ef d
ede
dededeeedf e	e
ef f fdd„Zdedeee
e
f  fdd„ZG dd„ deƒZdee fdd„Zd!dee	e
ef  ddfdd„ZdS )"é    )ÚAny)ÚOptional)ÚProtocol)ÚUnionc                   @   s   e Zd ZdZdS )ÚArgumentErrorze
    This is raised when an argument lookup, either by position or by keyword, is
    not found.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úS/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/internal/utils/__init__.pyr      s    r   FÚargsÚkwargsÚposÚkwÚoptionalÚreturnc                 C   sT   z|| W S  t y)   z| | W  Y S  ty(   |r Y Y dS td||f ƒ‚w w )aC  
    This function parses the value of a target function argument that may have been
    passed in as a positional argument or a keyword argument. Because monkey-patched
    functions do not define the same signature as their target function, the value of
    arguments must be inferred from the packed args and kwargs.
    Keyword arguments are prioritized, followed by the positional argument. If the
    argument cannot be resolved, an ``ArgumentError`` exception is raised, which could
    be used, e.g., to handle a default value by the caller.
    :param args: Positional arguments
    :param kwargs: Keyword arguments
    :param pos: The positional index of the argument if passed in as a positional arg
    :param kw: The name of the keyword if passed in as a keyword argument
    :return: The value of the target argument
    Nz%s (at position %d))ÚKeyErrorÚ
IndexErrorr   )r   r   r   r   r   r   r   r   Úget_argument_value   s   
ýýr   .ÚvalueÚoverride_unsetc                 C   sb   t | ƒ|kr| d|… |f | |d d…  } | |fS ||v s!|r)|||< | |fS td||f ƒ‚)aD  
    Returns a new args, kwargs with the given value updated
    :param args: Positional arguments
    :param kwargs: Keyword arguments
    :param pos: The positional index of the argument
    :param kw: The name of the keyword
    :param value: The new value of the target argument
    :return: Updated args and kwargs
    Né   z%s (at position %d) is invalid)Úlenr   )r   r   r   r   r   r   r   r   r   Úset_argument_value.   s   "ûþr   Úcontextc                 C   s(   | d u rg S t | j ¡ ƒ}dd„ |D ƒS )Nc                 S   s,   g | ]\}}t |tƒr| d ¡r||f‘qS )z_dd.p.)Ú
isinstanceÚstrÚ
startswith)Ú.0ÚkÚvr   r   r   Ú
<listcomp>O   s   , z+_get_metas_to_propagate.<locals>.<listcomp>)ÚlistÚ_metaÚitems)r   r%   r   r   r   Ú_get_metas_to_propagateI   s   r&   c                	   @   sŽ   e Zd ZU eed< eed< eed< eed< eed< eed< dded	ed
eeef fdd„Zded
e	eeef  fdd„Z
ded
efdd„ZdS )ÚBlock_configÚblock_idÚgrpc_status_codeÚstatus_codeÚtypeÚlocationÚcontent_typeNÚkeyÚdefaultr   c                 C   ó   d S ©Nr   )Úselfr.   r/   r   r   r   ÚgetZ   ó    zBlock_config.getc                 C   r0   r1   r   ©r2   r.   r   r   r   Ú__getitem__\   r4   zBlock_config.__getitem__c                 C   r0   r1   r   r5   r   r   r   Ú__contains__^   r4   zBlock_config.__contains__r1   )r   r   r	   r   Ú__annotations__Úintr   r   r3   r   r6   Úboolr7   r   r   r   r   r'   R   s   
  r'   c                  C   s,   ddl m}  |  d¡}|r|jr|jjS d S )Nr   ©Úcorezasm.get_blocked)Úddtrace.internalr<   Údispatch_with_resultsÚblock_configr   )r<   Úresr   r   r   Úget_blockeda   s
   

rA   NÚblock_settingsc                 C   s.   ddl m} ddlm} | d| p|f¡ d S )Nr   r;   )ÚSTATUS_403_TYPE_AUTOzasm.set_blocked)r=   r<   Úddtrace.internal.constantsrC   Údispatch)rB   r<   rC   r   r   r   Úset_blockedk   s   rF   )Fr1   )Útypingr   r   r   r   Ú	Exceptionr   Útupler#   Údictr   r9   r:   r   r   r&   r'   rA   rF   r   r   r   r   Ú<module>   sN    ûÿ
þýüû
ú&ú
ÿ
þýüûú
ù	$
