0
  7   =ˆÎ�þYq÷ÖnQðÈ0„¤óÔ„/ºïÙÍa–ßi~” T¾R( 	ÅõÀ
ão)‹Fÿ× 6™    =# Copyright (C) 2006-2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Symbol versioning

The methods here allow for api symbol versioning.
"""

__all__ = ['deprecated_function',
           'deprecated_in',
           'deprecated_list',
           'deprecated_method',
           'DEPRECATED_PARAMETER',
           'deprecated_passed',
           'set_warning_method',
           'warn',
           ]


import warnings
# Import the 'warn' symbol so breezy can call it even if we redefine it
from warnings import warn

import breezy


DEPRECATED_PARAMETER = "A deprecated parameter marker."


def deprecated_in(version_tuple):
    """Generate a message that something was deprecated in a release.

    >>> deprecated_in((1, 4, 0))
    '%s was deprecated in version 1.4.0.'
    """
    return ("%%s was deprecated in version %s."
            % breezy._format_version_tuple(version_tuple))


def set_warning_method(method):
    """Set the warning method to be used by this module.

    It should take a message and a warning category as warnings.warn does.
    """
    global warn
    warn = method


# TODO - maybe this would be easier to use as one 'smart' method that
# guess if it is a method or a class or an attribute ? If so, we can
# add that on top of the primitives, once we have all three written
# - RBC 20050105


def deprecation_string(a_callable, deprecation_version):
    """Generate an automatic deprecation string for a_callable.

    :param a_callable: The callable to substitute into deprecation_version.
    :param deprecation_version: A deprecation format warning string. This
        should have a single %s operator in it. a_callable will be turned into
        a nice python symbol and then substituted into deprecation_version.
    """
    if getattr(a_callable, '__self__', None) is not None:
        symbol = "{}.{}.{}".format(a_callable.__self__.__class__.__module__,
                               a_callable.__self__.__class__.__name__,
                               a_callable.__name__)
    elif getattr(a_callable, '__qualname__', None) is not None and '<' not in a_callable.__qualname__:
        symbol = "{}.{}".format(a_callable.__module__,
                            a_callable.__qualname__)
    else:
        symbol = "{}.{}".format(a_callable.__module__,
                            a_callable.__name__)
    return deprecation_version % symbol


def deprecated_function(deprecation_version):
    """Decorate a function so that use of it will trigger a warning."""

    def function_decorator(callable):
        """This is the function python calls to perform the decoration."""

        def decorated_function(*args, **kwargs):
            """This is the decorated function."""
            from . import trace
            trace.mutter_callsite(4, "Deprecated function called")
            warn(deprecation_string(callable, deprecation_version),
                 DeprecationWarning, stacklevel=2)
            return callable(*args, **kwargs)
        _populate_decorated(callable, deprecation_version, "function",
                            decorated_function)
        return decorated_function
    return function_decorator


def deprecated_method(deprecation_version):
    """Decorate a method so that use of it will trigger a warning.

    To deprecate a static or class method, use

        @staticmeth