a
    J5d&                     @   s   d Z ddlZddlZddlZddlZddlZzddlZdZdZW n, e	yl   dZe
 dkrddZndZY n0 ededfZG dd	 d	ejZd
d ZdS )z
Classic deprecation warning
===========================

Classic ``@deprecated`` decorator to deprecate old python classes, functions or methods.

.. _The Warnings Filter: https://docs.python.org/3/library/warnings.html#the-warnings-filter
    N      PyPy     c                       s:   e Zd ZdZdddef fdd	Zdd Zdd	 Z  ZS )
ClassicAdaptera8  
    Classic adapter -- *for advanced usage only*

    This adapter is used to get the deprecation message according to the wrapped object type:
    class, function, standard method, static method, or class method.

    This is the base class of the :class:`~deprecated.sphinx.SphinxAdapter` class
    which is used to update the wrapped object docstring.

    You can also inherit this class to change the deprecation message.

    In the following example, we change the message into "The ... is deprecated.":

    .. code-block:: python

       import inspect

       from deprecated.classic import ClassicAdapter
       from deprecated.classic import deprecated


       class MyClassicAdapter(ClassicAdapter):
           def get_deprecated_msg(self, wrapped, instance):
               if instance is None:
                   if inspect.isclass(wrapped):
                       fmt = "The class {name} is deprecated."
                   else:
                       fmt = "The function {name} is deprecated."
               else:
                   if inspect.isclass(instance):
                       fmt = "The class method {name} is deprecated."
                   else:
                       fmt = "The method {name} is deprecated."
               if self.reason:
                   fmt += " ({reason})"
               if self.version:
                   fmt += " -- Deprecated since version {version}."
               return fmt.format(name=wrapped.__name__,
                                 reason=self.reason or "",
                                 version=self.version or "")

    Then, you can use your ``MyClassicAdapter`` class like this in your source code:

    .. code-block:: python

       @deprecated(reason="use another function", adapter_cls=MyClassicAdapter)
       def some_old_function(x, y):
           return x + y
    r   Nc                    s2   |pd| _ |pd| _|| _|| _tt|   dS )aQ  
        Construct a wrapper adapter.

        :type  reason: str
        :param reason:
            Reason message which documents the deprecation in your library (can be omitted).

        :type  version: str
        :param version:
            Version of your project which deprecates this feature.
            If you follow the `Semantic Versioning <https://semver.org/>`_,
            the version number has the format "MAJOR.MINOR.PATCH".

        :type  action: str
        :param action:
            A warning filter used to activate or not the deprecation warning.
            Can be one of "error", "ignore", "always", "default", "module", or "once".
            If ``None`` or empty, the the global filtering mechanism is used.
            See: `The Warnings Filter`_ in the Python documentation.

        :type  category: type
        :param category:
            The warning category to use for the deprecation warning.
            By default, the category class is :class:`~DeprecationWarning`,
            you can inherit this class to define your own deprecation warning category.
        r   N)reasonversionactioncategorysuperr   __init__)selfr   r	   r
   r   	__class__ N/var/www/html/django/DPS/env/lib/python3.9/site-packages/deprecated/classic.pyr   V   s
    

zClassicAdapter.__init__c                 C   sl   |du rt |rd}q2d}nt |r.d}nd}| jr@|d7 }| jrN|d7 }|j|j| jp^d| jpfdd	S )
z
        Get the deprecation warning message for the user.

        :param wrapped: Wrapped class or function.

        :param instance: The object to which the wrapped function was bound when it was called.

        :return: The warning message.
        Nz Call to deprecated class {name}.z5Call to deprecated function (or staticmethod) {name}.z'Call to deprecated class method {name}.z!Call to deprecated method {name}.z ({reason})z' -- Deprecated since version {version}.r   )namer   r	   )inspectisclassr   r	   format__name__)r   wrappedinstancefmtr   r   r   get_deprecated_msgw   s    


z!ClassicAdapter.get_deprecated_msgc                    s.   t r*j  fdd}t|_S )a  
        Decorate your class or function.

        :param wrapped: Wrapped class or function.

        :return: the decorated class or function.

        .. versionchanged:: 1.2.4
           Don't pass arguments to :meth:`object.__new__` (other than *cls*).

        .. versionchanged:: 1.2.8
           The warning filter is not set if the *action* parameter is ``None`` or empty.
        c                    s    d }jr^t 2 tjj tj|jtd W d    qp1 sR0    Y  ntj|jtd  tj	u r | S  | g|R i |S N)r   
stacklevel)
r   r
   warningscatch_warningssimplefilterr   warn_class_stacklevelobject__new__)clsargskwargsmsgZold_new1r   r   r   r   wrapped_cls   s    
2
z,ClassicAdapter.__call__.<locals>.wrapped_cls)r   r   r$   staticmethod)r   r   r*   r   r)   r   __call__   s
    

zClassicAdapter.__call__)	r   
__module____qualname____doc__DeprecationWarningr   r   r,   __classcell__r   r   r   r   r   #   s   2!r   c                     s   | r*t | d tr*| d |d< | dd } | rNt| d sNttt| d | r|d |dt|dt	}|f i || d }t
|r|}|S t
|rtjd fd	d
}||S ttt|tjtfi |S )a  
    This is a decorator which can be used to mark functions
    as deprecated. It will result in a warning being emitted
    when the function is used.

    **Classic usage:**

    To use this, decorate your deprecated function with **@deprecated** decorator:

    .. code-block:: python

       from deprecated import deprecated


       @deprecated
       def some_old_function(x, y):
           return x + y

    You can also decorate a class or a method:

    .. code-block:: python

       from deprecated import deprecated


       class SomeClass(object):
           @deprecated
           def some_old_method(self, x, y):
               return x + y


       @deprecated
       class SomeOldClass(object):
           pass

    You can give a *reason* message to help the developer to choose another function/class,
    and a *version* number to specify the starting version number of the deprecation.

    .. code-block:: python

       from deprecated import deprecated


       @deprecated(reason="use another function", version='1.2.0')
       def some_old_function(x, y):
           return x + y

    The *category* keyword argument allow you to specify the deprecation warning class of your choice.
    By default, :exc:`DeprecationWarning` is used but you can choose :exc:`FutureWarning`,
    :exc:`PendingDeprecationWarning` or a custom subclass.

    .. code-block:: python

       from deprecated import deprecated


       @deprecated(category=PendingDeprecationWarning)
       def some_old_function(x, y):
           return x + y

    The *action* keyword argument allow you to locally change the warning filtering.
    *action* can be one of "error", "ignore", "always", "default", "module", or "once".
    If ``None``, empty or missing, the the global filtering mechanism is used.
    See: `The Warnings Filter`_ in the Python documentation.

    .. code-block:: python

       from deprecated import deprecated


       @deprecated(action="error")
       def some_old_function(x, y):
           return x + y

    r   r      Nr
   r   adapter_cls)adapterc                    st    | |} rVt , t  tj|td W d    qf1 sJ0    Y  ntj|td | |i |S r   )r   r   r   r    r!   _routine_stacklevel)Zwrapped_Z	instance_args_kwargs_r(   r
   r4   r   r   r   wrapper_function  s    
0z$deprecated.<locals>.wrapper_function)
isinstancestring_typescallable	TypeErrorreprtypegetr0   popr   r   r   	isroutinewrapt	decorator	functoolspartial
deprecated)r&   r'   r3   r   r9   r   r8   r   rG      s(    L




rG   )r/   rE   r   platformr   rC   Zwrapt._wrappersr5   r"   ImportErrorpython_implementationr?   r;   ZAdapterFactoryr   rG   r   r   r   r   <module>   s$   
 