← Back
Editing: deprecate.cpython-38.pyc
U W[�h � @ sH d Z ddlmZmZ ddddddgZdd lZdd lZdd lmam Z ddl mZ ddlm Z dd lmZ ddlmZ dZdd� Zde_de_de_dd� Zd2dd�Zd3dd�Zd4dd�Zdd� Zd5dd�Zd6dd�Zdd� Zd d� ZG d!d"� d"e �Z!G d#d$� d$e �Z"G d%d&� d&e �Z#d'd(� Z$d)d� Z%d*d+� Z&d,d-� Z'd.d/� Z(d0d1� Z)d S )7am Deprecation framework for Twisted. To mark a method, function, or class as being deprecated do this:: from incremental import Version from twisted.python.deprecate import deprecated @deprecated(Version("Twisted", 8, 0, 0)) def badAPI(self, first, second): ''' Docstring for badAPI. ''' ... @deprecated(Version("Twisted", 16, 0, 0)) class BadClass(object): ''' Docstring for BadClass. ''' The newly-decorated badAPI will issue a warning when called, and BadClass will issue a warning when instantiated. Both will also have a deprecation notice appended to their docstring. To deprecate properties you can use:: from incremental import Version from twisted.python.deprecate import deprecatedProperty class OtherwiseUndeprecatedClass(object): @deprecatedProperty(Version('Twisted', 16, 0, 0)) def badProperty(self): ''' Docstring for badProperty. ''' @badProperty.setter def badProperty(self, value): ''' Setter sill also raise the deprecation warning. ''' To mark module-level attributes as being deprecated you can use:: badAttribute = "someValue" ... deprecatedModuleAttribute( Version("Twisted", 8, 0, 0), "Use goodAttribute instead.", "your.full.module.name", "badAttribute") The deprecated attributes will issue a warning whenever they are accessed. If the attributes being deprecated are in the same module as the L{deprecatedModuleAttribute} call is being made from, the C{__name__} global can be used as the C{moduleName} parameter. See also L{incremental.Version}. @type DEPRECATION_WARNING_FORMAT: C{str} @var DEPRECATION_WARNING_FORMAT: The default deprecation warning string format to use when one is not provided by the user. � )�division�absolute_import� deprecated�deprecatedProperty�getDeprecationWarningString�getWarningMethod�setWarningMethod�deprecatedModuleAttributeN)�warn� warn_explicit)�findlinestarts��wraps)�getVersionString)�_PY3z&%(fqpn)s was deprecated in %(version)sc C s� z | j }W n tk r$ | j}Y nX t�| �s:t�| �rL| j}d||f S t�| �r�z | j}W n$ tk r� d| j| j f Y S X t |�}d||f S |S )z� Return the fully qualified name of a module, class, method or function. Classes and functions need to be module level ones to be correctly qualified. @rtype: C{str}. z%s.%s) �__qualname__�AttributeError�__name__�inspectZisclassZ isfunction� __module__ZismethodZim_class�_fullyQualifiedName)�obj�name� moduleName�cls� className� r �:/usr/lib/python3/dist-packages/twisted/python/deprecate.pyr c s r ztwisted.python.reflectZfullyQualifiedNamec C s t | �rt| �} d| f S )a Surround a replacement for a deprecated API with some polite text exhorting the user to consider it as an alternative. @type replacement: C{str} or callable @return: a string like "please use twisted.python.modules.getModule instead". zplease use %s instead)�callabler )�replacementr r r �_getReplacementString� s r c C s* dt | �f }|r"d|t|�f }|d S )a� Generate an addition to a deprecated object's docstring that explains its deprecation. @param version: the version it was deprecated. @type version: L{incremental.Version} @param replacement: The replacement, if specified. @type replacement: C{str} or callable @return: a string like "Deprecated in Twisted 27.2.0; please use twisted.timestream.tachyon.flux instead." zDeprecated in %s�%s; %s�.)r r )�versionr �docr r r �_getDeprecationDocstring� s r% c C s6 |dkrt }|| t|�d� }|r2d|t|�f }|S )ag Return a string indicating that the Python name was deprecated in the given version. @param fqpn: Fully qualified Python name of the thing being deprecated @type fqpn: C{str} @param version: Version that C{fqpn} was deprecated in. @type version: L{incremental.Version} @param format: A user-provided format to interpolate warning values into, or L{DEPRECATION_WARNING_FORMAT <twisted.python.deprecate.DEPRECATION_WARNING_FORMAT>} if L{None} is given. @type format: C{str} @param replacement: what should be used in place of C{fqpn}. Either pass in a string, which will be inserted into the warning message, or a callable, which will be expanded to its full import path. @type replacement: C{str} or callable @return: A textual description of the deprecation @rtype: C{str} N)�fqpnr# r! )�DEPRECATION_WARNING_FORMATr r )r&