~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/symbol_versioning.py

  • Committer: Aaron Bentley
  • Date: 2006-09-29 00:04:13 UTC
  • mto: (1731.2.8 nested-trees)
  • mto: This revision was merged to the branch mainline in revision 2078.
  • Revision ID: aaron.bentley@utoronto.ca-20060929000413-bb6d513b7171b59f
fix version_info stuff to deliberately include root

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
           'zero_eight',
30
30
           'zero_nine',
31
31
           'zero_ten',
 
32
           'zero_eleven',
 
33
           'zero_twelve',
32
34
           ]
33
35
 
34
36
from warnings import warn
39
41
zero_eight = "%s was deprecated in version 0.8."
40
42
zero_nine = "%s was deprecated in version 0.9."
41
43
zero_ten = "%s was deprecated in version 0.10."
 
44
zero_eleven = "%s was deprecated in version 0.11."
 
45
zero_twelve = "%s was deprecated in version 0.12."
42
46
 
43
47
 
44
48
def set_warning_method(method):
55
59
# add that on top of the primitives, once we have all three written
56
60
# - RBC 20050105
57
61
 
 
62
 
 
63
def deprecation_string(a_callable, deprecation_version):
 
64
    """Generate an automatic deprecation string for a_callable.
 
65
 
 
66
    :param a_callable: The callable to substitute into deprecation_version.
 
67
    :param deprecation_version: A deprecation format warning string. This should
 
68
        have a single %s operator in it. a_callable will be turned into a nice
 
69
        python symbol and then substituted into deprecation_version.
 
70
    """
 
71
    if getattr(a_callable, 'im_class', None) is None:
 
72
        symbol = "%s.%s" % (a_callable.__module__,
 
73
                            a_callable.__name__)
 
74
    else:
 
75
        symbol = "%s.%s.%s" % (a_callable.im_class.__module__,
 
76
                               a_callable.im_class.__name__,
 
77
                               a_callable.__name__
 
78
                               )
 
79
    return deprecation_version % symbol
 
80
 
 
81
 
58
82
def deprecated_function(deprecation_version):
59
83
    """Decorate a function so that use of it will trigger a warning."""
60
84
 
63
87
        
64
88
        def decorated_function(*args, **kwargs):
65
89
            """This is the decorated function."""
66
 
            symbol = "%s.%s" % (callable.__module__, 
67
 
                                callable.__name__
68
 
                                )
69
 
            warn(deprecation_version % symbol, DeprecationWarning, stacklevel=2)
 
90
            warn(deprecation_string(callable, deprecation_version),
 
91
                DeprecationWarning, stacklevel=2)
70
92
            return callable(*args, **kwargs)
71
93
        _populate_decorated(callable, deprecation_version, "function",
72
94
                            decorated_function)
85
107
        
86
108
        def decorated_method(self, *args, **kwargs):
87
109
            """This is the decorated method."""
88
 
            symbol = "%s.%s.%s" % (self.__class__.__module__, 
 
110
            symbol = "%s.%s.%s" % (self.__class__.__module__,
89
111
                                   self.__class__.__name__,
90
112
                                   callable.__name__
91
113
                                   )