a
    a*j6                     @   s\   d Z ddlZddlZddlZzddlZW n eyB   ddlZY n0 G dd deZeZ	dS )a  
Parameters deprecation
======================

.. _Tantale's Blog: https://tantale.github.io/
.. _Deprecated Parameters: https://tantale.github.io/articles/deprecated_params/

This module introduces a :class:`deprecated_params` decorator to specify that one (or more)
parameter(s) are deprecated: when the user executes a function with a deprecated parameter,
he will see a warning message in the console.

The decorator is customizable, the user can specify the deprecated parameter names
and associate to each of them a message providing the reason of the deprecation.
As with the :func:`~deprecated.classic.deprecated` decorator, the user can specify
a version number (using the *version* parameter) and also define the warning message category
(a subclass of :class:`Warning`) and when to display the messages (using the *action* parameter).

The complete study concerning the implementation of this decorator is available on the `Tantale's blog`_,
on the `Deprecated Parameters`_ page.
    Nc                   @   s@   e Zd ZdZdefddZdddZdd Zd	d
 Zdd Z	dS )DeprecatedParamszg
    Decorator used to decorate a function which at least one
    of the parameters is deprecated.
     c                 C   s   i | _ || _| j||d d S )N)reason)messagescategorypopulate_messages)selfparamr   r    r
   M/var/www/html/assistant/venv/lib/python3.9/site-packages/deprecated/params.py__init__'   s    zDeprecatedParams.__init__c                 C   sN   t |tr| j| n2t |trBd}|p4|j|d}|| j|< nt|d S )Nz!'{param}' parameter is deprecated)r	   )
isinstancedictr   updatestrformat	TypeError)r   r	   r   fmtr
   r
   r   r   ,   s    

z"DeprecatedParams.populate_messagesc                    s8   |j |i |}tj|jfi |j} fdd|D S )Nc                    s   g | ]}| j v r|qS r
   r   .0r	   r   r
   r   
<listcomp>9       z1DeprecatedParams.check_params.<locals>.<listcomp>)bindcollectionsOrderedDict	argumentskwargs)r   	signatureargsr   Zbindingboundr
   r   r   check_params6   s    zDeprecatedParams.check_paramsc                 C   s    |D ]}t j|| jdd qd S )N   )r   
stacklevel)warningswarnr   )r   r   messager
   r
   r   warn_messages;   s    zDeprecatedParams.warn_messagesc                    s(   t  t  fdd}|S )Nc                     s>   j g| R i |}fdd|D   | i |S )Nc                    s   g | ]} j | qS r
   r   r   r   r
   r   r   G   r   z>DeprecatedParams.__call__.<locals>.wrapper.<locals>.<listcomp>)r"   r(   )r    r   Zinvalid_paramsfr   r   r
   r   wrapperD   s    z*DeprecatedParams.__call__.<locals>.wrapper)inspectr   	functoolswraps)r   r*   r+   r
   r)   r   __call__@   s    
zDeprecatedParams.__call__N)r   )
__name__
__module____qualname____doc__DeprecationWarningr   r   r"   r(   r/   r
   r
   r
   r   r   !   s   

r   )
r3   r   r-   r%   Zinspect2r,   ImportErrorobjectr   Zdeprecated_paramsr
   r
   r
   r   <module>   s   .