~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/symbol_versioning.py

  • Committer: Alexander Belchenko
  • Date: 2006-07-31 16:12:57 UTC
  • mto: (1711.2.111 jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1906.
  • Revision ID: bialix@ukr.net-20060731161257-91a231523255332c
new official bzr.ico

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',
34
32
           ]
35
33
 
36
34
from warnings import warn
41
39
zero_eight = "%s was deprecated in version 0.8."
42
40
zero_nine = "%s was deprecated in version 0.9."
43
41
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."
46
42
 
47
43
 
48
44
def set_warning_method(method):
59
55
# add that on top of the primitives, once we have all three written
60
56
# - RBC 20050105
61
57
 
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
 
 
82
58
def deprecated_function(deprecation_version):
83
59
    """Decorate a function so that use of it will trigger a warning."""
84
60
 
87
63
        
88
64
        def decorated_function(*args, **kwargs):
89
65
            """This is the decorated function."""
90
 
            warn(deprecation_string(callable, deprecation_version),
91
 
                DeprecationWarning, stacklevel=2)
 
66
            symbol = "%s.%s" % (callable.__module__, 
 
67
                                callable.__name__
 
68
                                )
 
69
            warn(deprecation_version % symbol, DeprecationWarning, stacklevel=2)
92
70
            return callable(*args, **kwargs)
93
71
        _populate_decorated(callable, deprecation_version, "function",
94
72
                            decorated_function)
107
85
        
108
86
        def decorated_method(self, *args, **kwargs):
109
87
            """This is the decorated method."""
110
 
            symbol = "%s.%s.%s" % (self.__class__.__module__,
 
88
            symbol = "%s.%s.%s" % (self.__class__.__module__, 
111
89
                                   self.__class__.__name__,
112
90
                                   callable.__name__
113
91
                                   )