/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-13 02:09:37 UTC
  • mto: This revision was merged to the branch mainline in revision 2004.
  • Revision ID: john@arbash-meinel.com-20060913020937-2df2f49f9a28ec43
Update HACKING and docstrings

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
2
 
#   Authors: Robert Collins <robert.collins@canonical.com> and others
 
1
# Copyright (C) 2006 by Canonical Ltd
 
2
#   Authors: Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
30
30
           'zero_nine',
31
31
           'zero_ten',
32
32
           'zero_eleven',
33
 
           'zero_twelve',
34
 
           'zero_thirteen',
35
 
           'zero_fourteen',
36
 
           'zero_fifteen',
37
 
           'zero_sixteen',
38
33
           ]
39
34
 
40
35
from warnings import warn
46
41
zero_nine = "%s was deprecated in version 0.9."
47
42
zero_ten = "%s was deprecated in version 0.10."
48
43
zero_eleven = "%s was deprecated in version 0.11."
49
 
zero_twelve = "%s was deprecated in version 0.12."
50
 
zero_thirteen = "%s was deprecated in version 0.13."
51
 
zero_fourteen = "%s was deprecated in version 0.14."
52
 
zero_fifteen = "%s was deprecated in version 0.15."
53
 
zero_sixteen = "%s was deprecated in version 0.16."
54
44
 
55
45
 
56
46
def set_warning_method(method):
180
170
    decorated_callable.is_deprecated = True
181
171
 
182
172
 
183
 
def _dict_deprecation_wrapper(wrapped_method):
184
 
    """Returns a closure that emits a warning and calls the superclass"""
185
 
    def cb(dep_dict, *args, **kwargs):
186
 
        msg = 'access to %s' % (dep_dict._variable_name, )
187
 
        msg = dep_dict._deprecation_version % (msg,)
188
 
        if dep_dict._advice:
189
 
            msg += ' ' + dep_dict._advice
190
 
        warn(msg, DeprecationWarning, stacklevel=2)
191
 
        return wrapped_method(dep_dict, *args, **kwargs)
192
 
    return cb
193
 
 
194
 
 
195
 
class DeprecatedDict(dict):
196
 
    """A dictionary that complains when read or written."""
197
 
 
198
 
    is_deprecated = True
199
 
 
200
 
    def __init__(self,
201
 
        deprecation_version,
202
 
        variable_name,
203
 
        initial_value,
204
 
        advice,
205
 
        ):
206
 
        """Create a dict that warns when read or modified.
207
 
 
208
 
        :param deprecation_version: something like zero_nine
209
 
        :param initial_value: The contents of the dict
210
 
        :param variable_name: This allows better warnings to be printed
211
 
        :param advice: String of advice on what callers should do instead 
212
 
            of using this variable.
213
 
        """
214
 
        self._deprecation_version = deprecation_version
215
 
        self._variable_name = variable_name
216
 
        self._advice = advice
217
 
        dict.__init__(self, initial_value)
218
 
 
219
 
    # This isn't every possible method but it should trap anyone using the
220
 
    # dict -- add more if desired
221
 
    __len__ = _dict_deprecation_wrapper(dict.__len__)
222
 
    __getitem__ = _dict_deprecation_wrapper(dict.__getitem__)
223
 
    __setitem__ = _dict_deprecation_wrapper(dict.__setitem__)
224
 
    __delitem__ = _dict_deprecation_wrapper(dict.__delitem__)
225
 
    keys = _dict_deprecation_wrapper(dict.keys)
226
 
    __contains__ = _dict_deprecation_wrapper(dict.__contains__)
227
 
 
228
 
 
229
173
def deprecated_list(deprecation_version, variable_name,
230
174
                    initial_value, extra=None):
231
175
    """Create a list that warns when modified