~ubuntu-branches/ubuntu/lucid/python-apt/lucid-proposed

« back to all changes in this revision

Viewing changes to apt/deprecation.py

  • Committer: Bazaar Package Importer
  • Author(s): Julian Andres Klode
  • Date: 2010-03-29 13:18:20 UTC
  • Revision ID: james.westby@ubuntu.com-20100329131820-sqceztw560dyvc2b
Tags: 0.7.94.2ubuntu4
If PYTHON_APT_DEPRECATION_WARNINGS is unset, also disable the
deprecation warnings in apt_pkg directly; and don't just
disable any deprecation warning in apt/__init__.py (LP: #548623)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
"""
25
25
import re
26
26
import operator
 
27
import os
27
28
import warnings
28
29
 
29
30
import apt_pkg
49
50
        """Issue a  DeprecationWarning and return the requested value."""
50
51
        if obj is None:
51
52
            return getattr(type_, self.attribute, self)
52
 
        warnings.warn(self.__doc__, DeprecationWarning, stacklevel=2)
 
53
        if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ:
 
54
            warnings.warn(self.__doc__, DeprecationWarning, stacklevel=2)
53
55
        return self.getter(obj or type_)
54
56
 
55
57
    def __set__(self, obj, value):
56
58
        """Issue a  DeprecationWarning and set the requested value."""
57
 
        warnings.warn(self.__doc__, DeprecationWarning, stacklevel=2)
 
59
        if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ:
 
60
            warnings.warn(self.__doc__, DeprecationWarning, stacklevel=2)
58
61
        setattr(obj, self.attribute, value)
59
62
 
60
63
 
71
74
 
72
75
    def deprecated_function(*args, **kwds):
73
76
        """Wrapper around a deprecated function."""
74
 
        warnings.warn(warning, DeprecationWarning, stacklevel=2)
 
77
        if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ:
 
78
            warnings.warn(warning, DeprecationWarning, stacklevel=2)
75
79
        if convert_names:
76
80
            for key in kwds.keys():
77
81
                kwds[re.sub('([A-Z])', '_\\1', key).lower()] = kwds.pop(key)
93
97
        for key in kwds.keys():
94
98
            new_key = re.sub('([A-Z])', '_\\1', key).lower()
95
99
            if new_key != key:
96
 
                warnings.warn("Deprecated parameter %r" % key)
 
100
                if "PYTHON_APT_DEPRECATION_WARNINGS" in os.environ:
 
101
                    warnings.warn("Deprecated parameter %r" % key)
97
102
                kwds[new_key] = kwds.pop(key)
98
103
        return func(*args, **kwds)
99
104