U
    YyŒh_2  ã                   @   s„   d dl Z d dlZd dlZd dlZd dlmZ d dlmZ dZddddd	gZ	d
Z
G dd„ deƒZG dd	„ d	eƒZddd„Zdd„ ZdS )é    N)Úversion)Údatez2.1.0Ú
deprecatedÚmessage_locationÚfail_if_not_removedÚDeprecatedWarningÚUnsupportedWarningÚbottomc                       s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )r   aw  A warning class for deprecated methods

    This is a specialization of the built-in :class:`DeprecationWarning`,
    adding parameters that allow us to get information into the __str__
    that ends up being sent through the :mod:`warnings` system.
    The attributes aren't able to be retrieved after the warning gets
    raised and passed through the system as only the class--not the
    instance--and message are what gets preserved.

    :param function: The function being deprecated.
    :param deprecated_in: The version that ``function`` is deprecated in
    :param removed_in: The version or :class:`datetime.date` specifying
                       when ``function`` gets removed.
    :param details: Optional details about the deprecation. Most often
                    this will include directions on what to use instead
                    of the now deprecated code.
    Ú c                    s2   || _ || _|| _|| _tt| ƒ ||||¡ d S )N)ÚfunctionÚdeprecated_inÚ
removed_inÚdetailsÚsuperr   Ú__init__)Úselfr   r   r   r   ©Ú	__class__© ú5/usr/local/lib/python3.8/dist-packages/deprecation.pyr   5   s     ÿzDeprecatedWarning.__init__c                 C   sˆ   t  t¡}| j|d< | jr(d| j |d< | jrPd t| jtƒrBdnd| j¡|d< t	| j| j| j
gƒrld|d	< | j
r€d
| j
 |d< d| S )Nr   z	 as of %sr   z and will be removed {} {}ÚonÚinÚremovedÚ.Zperiodú %sr   zH%(function)s is deprecated%(deprecated)s%(removed)s%(period)s%(details)s)ÚcollectionsÚdefaultdictÚstrr   r   r   ÚformatÚ
isinstancer   Úanyr   ©r   Úpartsr   r   r   Ú__str__@   s    

ÿÿzDeprecatedWarning.__str__)r
   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r#   Ú__classcell__r   r   r   r   r   "   s   c                   @   s   e Zd ZdZdd„ ZdS )r   aƒ  A warning class for methods to be removed

    This is a subclass of :class:`~deprecation.DeprecatedWarning` and is used
    to output a proper message about a function being unsupported.
    Additionally, the :func:`~deprecation.fail_if_not_removed` decorator
    will handle this warning and cause any tests to fail if the system
    under test uses code that raises this warning.
    c                 C   s:   t  t¡}| j|d< | j|d< | jr2d| j |d< d| S )Nr   r   r   r   z9%(function)s is unsupported as of %(removed)s.%(details)s)r   r   r   r   r   r   r!   r   r   r   r#   ^   s    


ÿzUnsupportedWarning.__str__N)r$   r%   r&   r'   r#   r   r   r   r   r   T   s   	r
   c                    s¨   ˆ dkrˆdk	rt dƒ‚d}d‰tˆtƒrBt ¡ ˆkr<d‰q„d}nB|r€t |¡}ˆrh|t ˆ¡krhd‰q„ˆ r„|t ˆ ¡kr„d}nd}t|ˆgƒ‰‡ ‡‡‡‡fdd„}|S )aå	  Decorate a function to signify its deprecation

    This function wraps a method that will soon be removed and does two things:
        * The docstring of the method will be modified to include a notice
          about deprecation, e.g., "Deprecated since 0.9.11. Use foo instead."
        * Raises a :class:`~deprecation.DeprecatedWarning`
          via the :mod:`warnings` module, which is a subclass of the built-in
          :class:`DeprecationWarning`. Note that built-in
          :class:`DeprecationWarning`s are ignored by default, so for users
          to be informed of said warnings they will need to enable them--see
          the :mod:`warnings` module documentation for more details.

    :param deprecated_in: The version at which the decorated method is
                          considered deprecated. This will usually be the
                          next version to be released when the decorator is
                          added. The default is **None**, which effectively
                          means immediate deprecation. If this is not
                          specified, then the `removed_in` and
                          `current_version` arguments are ignored.
    :param removed_in: The version or :class:`datetime.date` when the decorated
                       method will be removed. The default is **None**,
                       specifying that the function is not currently planned
                       to be removed.
                       Note: This parameter cannot be set to a value if
                       `deprecated_in=None`.
    :param current_version: The source of version information for the
                            currently running code. This will usually be
                            a `__version__` attribute on your library.
                            The default is `None`.
                            When `current_version=None` the automation to
                            determine if the wrapped function is actually
                            in a period of deprecation or time for removal
                            does not work, causing a
                            :class:`~deprecation.DeprecatedWarning`
                            to be raised in all cases.
    :param details: Extra details to be added to the method docstring and
                    warning. For example, the details may point users to
                    a replacement method, such as "Use the foo_bar
                    method instead". By default there are no details.
    NzCCannot set removed_in to a value without also setting deprecated_inFTc                    sê   ˆrÆˆ j pd}ˆrdˆ ndˆr:d tˆtƒr2dndˆ¡ndˆrHdˆ nddœ}djf |Ž}d}| d	d¡}t|ƒdkr¢t |d ¡|d< | |d	¡ t	d
kr¢d}| ||¡ | |d¡ d 
|¡ˆ _ t ˆ ¡‡‡‡ ‡‡‡fdd„ƒ}|S )Nr
   r   z
   This will be removed {} {}.r   r   )r   r   r   z3.. deprecated::{deprecated_in}{removed_in}{details}é   Ú
Útopé   z

c                     s<   ˆr2ˆrt }nt}|ˆjˆ ˆˆƒ}tj|tdd ˆ| |ŽS )Né   )ÚcategoryÚ
stacklevel)r   r   r$   ÚwarningsÚwarnÚDeprecationWarning)ÚargsÚkwargsÚclsZthe_warning)r   r   r   Úis_unsupportedr   Úshould_warnr   r   Ú_inner÷   s     ÿÿz5deprecated.<locals>._function_wrapper.<locals>._inner)r'   r   r   r   ÚsplitÚlenÚtextwrapÚdedentÚinsertr   ÚjoinÚ	functoolsÚwraps)r   Zexisting_docstringr"   Zdeprecation_noteÚlocZstring_listr8   ©r   r   r6   r   r7   )r   r   Ú_function_wrapper»   s4    
ÿÿù	ÿz%deprecated.<locals>._function_wrapper)Ú	TypeErrorr   r   Útodayr   Úparser    )r   r   Úcurrent_versionr   Zis_deprecatedrC   r   rB   r   r   j   s,    ,

ÿÿKc                    s   t  ˆ ¡‡ fdd„ƒ}|S )a¤  Decorate a test method to track removal of deprecated code

    This decorator catches :class:`~deprecation.UnsupportedWarning`
    warnings that occur during testing and causes unittests to fail,
    making it easier to keep track of when code should be removed.

    :raises: :class:`AssertionError` if an
             :class:`~deprecation.UnsupportedWarning`
             is raised while running the test method.
    c               	      sZ   t jdd}t  d¡ ˆ | |Ž}W 5 Q R X |D ]$}|jtkr0tdˆ t|jƒf ƒ‚q0|S )NT)ÚrecordÚalwaysz-%s uses a function that should be removed: %s)r0   Úcatch_warningsÚsimplefilterr.   r   ÚAssertionErrorr   Úmessage)r3   r4   Zcaught_warningsÚrvÚwarning©Úmethodr   r   Ú
test_inner  s    

ÿÿz'fail_if_not_removed.<locals>.test_inner)r?   r@   )rQ   rR   r   rP   r   r   	  s    )NNNr
   )r   r?   r;   r0   Ú	packagingr   Údatetimer   Ú__version__Ú__all__r   r2   r   r   r   r   r   r   r   r   Ú<module>   s$    ÿ2  ÿ
  