o
    i(6                     @   s   d dl Z d dlZd dlZddlmZ dd ZdddZG dd	 d	eZ		dddZ			
	dddZ
		
	dddZ		
	dddZdS )    N   )_utilsc                 C   s   t | d S )Nr   )r   get_qualified_name)obj r   Y/home/ubuntu/.local/lib/python3.10/site-packages/ddtrace/vendor/debtcollector/removals.py_get_qualified_name   s   r   c                 C   s.   t d| ||fD ]}||}|r|  S q|S )z=Fetch first non-none/empty result of applying ``apply_func``.N)filter)fgetfsetfdel
apply_funcvalue_not_foundfresultr   r   r   _fetch_first_result   s   r   c                	   @   sx   e Zd ZdZddddZdddddedddf	dd	Zd
d Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )removed_propertya>  Property descriptor that deprecates a property.

    This works like the ``@property`` descriptor but can be used instead to
    provide the same functionality and also interact with the :mod:`warnings`
    module to warn when a property is accessed, set and/or deleted.

    :param message: string used as ending contents of the deprecate message
    :param version: version string (represents the version this deprecation
                    was created in)
    :param removal_version: version string (represents the version this
                            deprecation will be removed in); a string
                            of '?' will denote this will be removed in
                            some future unknown version
    :param stacklevel: stacklevel used in the :func:`warnings.warn` function
                       to locate where the users code is when reporting the
                       deprecation call (the default being 3)
    :param category: the :mod:`warnings` category to use, defaults to
                     :py:class:`DeprecationWarning` if not provided
    z'Setting the '%s' property is deprecatedz'Reading the '%s' property is deprecatedz(Deleting the '%s' property is deprecated)setgetdeleteN   c
           
      C   s^   || _ || _|| _|| _|| _|| _|| _|	| _|d u r't	|r't
|dd }i | _|| _d S )N__doc__)r   r
   r   
stacklevelcategoryversionremoval_versionmessageinspect
isfunctiongetattr_message_cacher   )
selfr
   r   r   docr   r   r   r   r   r   r   r   __init__@   s   
zremoved_property.__init__c                 C   sn   z| j | }W |S  ty6   | j| }|t| j| j| jtdd }tj	|| j
| j| jd}|| j |< Y |S w )Nz???)r   )r   r   r   )r    KeyError_PROPERTY_GONE_TPLSr   r
   r   r   r   r   generate_messager   r   r   )r!   kindout_message
prefix_tplprefixr   r   r   _fetch_message_from_cacheP   s    


z*removed_property._fetch_message_from_cachec                 K   s|   || _ |d| j| _|d| j| _|d| j| _|d| j| _|d| j| _|dt|d| j| _| j	
  | S )Nr   r   r   r   r   r"   r   )r
   r   r   r   r   r   r   r   r   r    clear)r!   r
   kwargsr   r   r   __call__^   s   
zremoved_property.__call__c                 C   s>   | j d u r	td| d}tj|| j| jd |  | d S )Nzcan't delete attributer   r   r   )r   AttributeErrorr+   r   deprecationr   r   )r!   r   r(   r   r   r   
__delete__l   s   


zremoved_property.__delete__c                 C   s@   | j d u r	td| d}tj|| j| jd |  || d S )Nzcan't set attributer   r/   )r   r0   r+   r   r1   r   r   r!   r   valuer(   r   r   r   __set__t   s   


zremoved_property.__set__c                 C   sF   |d u r| S | j d u rtd| d}tj|| j| jd |  |S )Nzunreadable attributer   r/   )r
   r0   r+   r   r1   r   r   r3   r   r   r   __get__|   s   



zremoved_property.__get__c                 C   sD   t | || j| j| j}| j|_| j|_| j|_| j|_| j|_|S N)	typer   r   r   r   r   r   r   r   )r!   r
   or   r   r   getter      zremoved_property.getterc                 C   sD   t | | j|| j| j}| j|_| j|_| j|_| j|_| j|_|S r7   )	r8   r
   r   r   r   r   r   r   r   )r!   r   r9   r   r   r   setter   r;   zremoved_property.setterc                 C   sD   t | | j| j|| j}| j|_| j|_| j|_| j|_| j|_|S r7   )	r8   r
   r   r   r   r   r   r   r   )r!   r   r9   r   r   r   deleter   r;   zremoved_property.deleter)__name__
__module____qualname__r   r%   DeprecationWarningr#   r+   r.   r2   r5   r6   r:   r<   r=   r   r   r   r   r   $   s$    

		r   r   c                    s@   | du rt jt dS tj fdd}|| S )a  Decorates a function, method, or class to emit a deprecation warning

    Due to limitations of the wrapt library (and python) itself, if this
    is applied to subclasses of metaclasses then it likely will not work
    as expected. More information can be found at bug #1520397 to see if
    this situation affects your usage of this *universal* decorator, for
    this specific scenario please use :py:func:`.removed_class` instead.

    :param str message: A message to include in the deprecation warning
    :param str version: Specify what version the removed function is present in
    :param str removal_version: What version the function will be removed. If
                                '?' is used this implies an undefined future
                                version
    :param int stacklevel: How many entries deep in the call stack before
                           ignoring
    :param type category: warnings message category (this defaults to
                          ``DeprecationWarning`` when none is provided)
    N)r   r   r   r   r   c                    s(  t | \}}|rt| rd}d}nd}d}|snd}d }|d u rXt| rEd}d}tt| }	|	dkr=t j| dd}n$t j| dd}nd}tt| }	|	dkrWt | }n	d}t j|dd}|rkd	||g}
n|}
n|}
|rv|
|7 }
|d
|
  }t j	|d}t j
| d | |i |S )NzUsing class zUsing function/methodz()__main__F)fully_qualifiedT.z '%s' is deprecated)r   r   r   r/   )r   r   r   isclassr   	getmoduleget_class_nameget_callable_namejoinr&   r1   )r   instanceargsr-   	qualifiedf_name
prefix_pre
thing_post	base_namemodule_name
thing_namer*   r(   r   r   r   r   r   r   r   wrapper   s`   


zremove.<locals>.wrapper)	functoolspartialremovewrapt	decorator)r   r   r   r   r   r   rU   r   rT   r   rX      s   4rX   c                    s8   d }t j|d|||dtj fdd}|S )zBDecorates a kwarg accepting function to deprecate a removed kwarg.z%Using the '%s' argument is deprecatedNpostfixr   r   r   c                    s&   |v rt j d | |i |S Nr/   r   r1   )r   rK   rL   r-   r   old_namer(   r   r   r   rU      s
   zremoved_kwarg.<locals>.wrapper)r   r&   rY   rZ   )r`   r   r   r   r   r   r*   rU   r   r_   r   removed_kwarg   s   ra   c                    s0   fdddd   fdd}|S )zBDecorates a class to denote that it will be removed at some point.c                    s*   t j t d fdd}|S )N)assignedc                    s&   t j d | g|R i |S r]   r^   )r!   rL   r-   )r   old_initr(   r   r   r   new_init  s   z1removed_class.<locals>._wrap_it.<locals>.new_init)rV   wrapsr   get_assigned)rc   r(   rd   )r   r   )rc   r(   r   _wrap_it  s   zremoved_class.<locals>._wrap_itc                 S   s,   t | stt| \}}td| d S )Nz5Unexpected class type '%s' (expected class type only))r   rF   r   r   r8   	TypeError)cls_qual	type_namer   r   r   	_check_it  s   
z removed_class.<locals>._check_itc                    s2    |  t jd d d}| j|| _| S )NzCUsing class '%s' (either directly or via inheritance) is deprecatedr[   )r   r&   r#   )ri   r(   )rl   rg   cls_namer   r   r   r   r   _cls_decorator  s   z%removed_class.<locals>._cls_decoratorr   )rm   replacementr   r   r   r   r   rn   r   )rl   rg   r   rm   r   r   r   r   r   removed_class	  s   
	rp   c                 C   s   t | r
t| }nt| tr| }ntt| \}}	td|	 d| }
|r,d| }nd}tj	|
||||d}tj
|||d dS )a6  Helper to be called inside a module to emit a deprecation warning

    :param str replacment: A location (or information about) of any potential
                           replacement for the removed module (if applicable)
    :param str message: A message to include in the deprecation warning
    :param str version: Specify what version the removed module is present in
    :param str removal_version: What version the module will be removed. If
                                '?' is used this implies an undefined future
                                version
    :param int stacklevel: How many entries deep in the call stack before
                           ignoring
    :param type category: warnings message category (this defaults to
                          ``DeprecationWarning`` when none is provided)
    zAUnexpected module type '%s' (expected string or module type only)z#The '%s' module usage is deprecatedz, please use %s insteadNr[   r/   )r   ismoduler   
isinstancestrr   r   r8   rh   r&   r1   )modulero   r   r   r   r   r   rR   rj   rk   r*   r\   r(   r   r   r   removed_module*  s(   




ru   r7   )NNNNr   N)NNNr   N)rV   r   rY   rB   r   r   r   objectr   rX   ra   rp   ru   r   r   r   r   <module>   s,   
	~
S

!