File: //lib/python3.9/site-packages/deprecated/__pycache__/sphinx.cpython-39.pyc
a
%lDge+ � @ s^ d Z ddlZddlZddlmZ ddlmZ G dd� de�Zdd d
�Zddd�Z dd
d�ZdS )a-
Sphinx directive integration
============================
We usually need to document the life-cycle of functions and classes:
when they are created, modified or deprecated.
To do that, `Sphinx <http://www.sphinx-doc.org>`_ has a set
of `Paragraph-level markups <http://www.sphinx-doc.org/en/stable/markup/para.html>`_:
- ``versionadded``: to document the version of the project which added the described feature to the library,
- ``versionchanged``: to document changes of a feature,
- ``deprecated``: to document a deprecated feature.
The purpose of this module is to defined decorators which adds this Sphinx directives
to the docstring of your function and classes.
Of course, the ``@deprecated`` decorator will emit a deprecation warning
when the function/method is called or the class is constructed.
� N)�ClassicAdapter)�
deprecatedc sF e Zd ZdZdddeddf� fdd� Z� fdd �Z� fd
d�Z� ZS )�
SphinxAdaptera
Sphinx adapter -- *for advanced usage only*
This adapter override the :class:`~deprecated.classic.ClassicAdapter`
in order to add the Sphinx directives to the end of the function/class docstring.
Such a directive is a `Paragraph-level markup <http://www.sphinx-doc.org/en/stable/markup/para.html>`_
- The directive can be one of "versionadded", "versionchanged" or "deprecated".
- The version number is added if provided.
- The reason message is obviously added in the directive block if not empty.
� Nr �F c s6 |st d��|| _|| _tt| �j|||||d� dS )aV
Construct a wrapper adapter.
:type directive: str
:param directive:
Sphinx directive: can be one of "versionadded", "versionchanged" or "deprecated".
: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: Literal["default", "error", "ignore", "always", "module", "once"]
: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 global filtering mechanism is used.
See: `The Warnings Filter`_ in the Python documentation.
:type category: Type[Warning]
: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.
:type extra_stacklevel: int
:param extra_stacklevel:
Number of additional stack levels to consider instrumentation rather than user code.
With the default value of 0, the warning refers to where the class was instantiated
or the function was called.
:type line_length: int
:param line_length:
Max line length of the directive text. If non nul, a long text is wrapped in several lines.
.. versionchanged:: 1.2.15
Add the *extra_stacklevel* parameter.
z3'version' argument is required in Sphinx directives)�reason�version�action�category�extra_stacklevelN)�
ValueError� directive�line_length�superr �__init__)�selfr
r r r r
r r �� __class__� �5/usr/lib/python3.9/site-packages/deprecated/sphinx.pyr * s 5
�zSphinxAdapter.__init__c s2 | j r
dnd}|j| j| j d�g}| jdkr6| jd nd}t�| j��� }|�� D ]0}|rx|� tj
||ddd��� � qR|�d� qR|jp�d}|�d �p�dg}t
|�d
kr�t�d�|d
d� ��nd}|d | }|r�tjd
d|tjd�d }nd}|d�dd� |D ��7 }||_| jdv �r"|S tt| ��|�S )z�
Add the Sphinx directive to your class or function.
:param wrapped: Wrapped class or function.
:return: the decorated class or function.
z.. {directive}:: {version}z.. {directive}::)r
r � i z )�width�initial_indent�subsequent_indentr T� Nr z\n+$��flagsz
�
c s s | ]}d � |�V qdS )z{}
N)�format)�.0�liner r r � <genexpr>� � z)SphinxAdapter.__call__.<locals>.<genexpr>> �versionchanged�versionadded)r r r
r �textwrap�dedentr �strip�
splitlines�extend�fill�append�__doc__�len�join�re�sub�DOTALLr r �__call__) r �wrappedZfmtZ div_linesr r Z paragraphZ docstring�linesr r r r2 h s6 ��
(zSphinxAdapter.__call__c s* t t| ��||�}tjdd|tjd�}|S )a�
Get the deprecation warning message (without Sphinx cross-referencing syntax) 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.
.. versionadded:: 1.2.12
Strip Sphinx cross-referencing syntax from warning message.
z*(?: : [a-zA-Z]+ )? : [a-zA-Z]+ : (`[^`]*`)z\1r )r r �get_deprecated_msgr/ r0 �X)r r3 �instance�msgr r r r5 � s z SphinxAdapter.get_deprecated_msg) �__name__�
__module__�__qualname__r, �DeprecationWarningr r2 r5 �
__classcell__r r r r r s �>/r r r c C s t d| ||d�}|S )a1
This decorator can be used to insert a "versionadded" directive
in your function/class docstring in order to document the
version of the project which adds this new functionality in your library.
:param str reason:
Reason message which documents the addition in your library (can be omitted).
:param str version:
Version of your project which adds this feature.
If you follow the `Semantic Versioning <https://semver.org/>`_,
the version number has the format "MAJOR.MINOR.PATCH", and,
in the case of a new functionality, the "PATCH" component should be "0".
:type line_length: int
:param line_length:
Max line length of the directive text. If non nul, a long text is wrapped in several lines.
:return: the decorated function.
r$ �r r r �r �r r r Zadapterr r r r$ � s �r$ c C s t d| ||d�}|S )a�
This decorator can be used to insert a "versionchanged" directive
in your function/class docstring in order to document the
version of the project which modifies this functionality in your library.
:param str reason:
Reason message which documents the modification in your library (can be omitted).
:param str version:
Version of your project which modifies this feature.
If you follow the `Semantic Versioning <https://semver.org/>`_,
the version number has the format "MAJOR.MINOR.PATCH".
:type line_length: int
:param line_length:
Max line length of the directive text. If non nul, a long text is wrapped in several lines.
:return: the decorated function.
r# r>