/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/symbol_versioning.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-15 00:44:57 UTC
  • mfrom: (2009 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2050.
  • Revision ID: john@arbash-meinel.com-20060915004457-902cec0526a39337
[merge] bzr.dev 2009

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