~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/symbol_versioning.py

  • Committer: John Arbash Meinel
  • Date: 2009-06-04 16:50:33 UTC
  • mto: This revision was merged to the branch mainline in revision 4410.
  • Revision ID: john@arbash-meinel.com-20090604165033-bfdo0lyf4yt4vjcz
We don't need a base Coder class, because Decoder._update_tail is different than Encoder._update_tail.
(one adds, one subtracts from self.size).
So we now have 2 versions of the macro, and the test suite stops crashing... :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
19
19
The methods here allow for api symbol versioning.
20
20
"""
21
21
 
22
 
from __future__ import absolute_import
23
 
 
24
22
__all__ = ['deprecated_function',
25
23
           'deprecated_in',
26
24
           'deprecated_list',
31
29
           'warn',
32
30
           ]
33
31
 
34
 
 
35
 
import warnings
36
 
# Import the 'warn' symbol so bzrlib can call it even if we redefine it
37
32
from warnings import warn
38
33
 
39
34
import bzrlib
46
41
    """Generate a message that something was deprecated in a release.
47
42
 
48
43
    >>> deprecated_in((1, 4, 0))
49
 
    '%s was deprecated in version 1.4.0.'
 
44
    '%s was deprecated in version 1.4.'
50
45
    """
51
46
    return ("%%s was deprecated in version %s."
52
47
            % bzrlib._format_version_tuple(version_tuple))
301
296
    :param error_only: Only match an 'error' filter
302
297
    :return: True if a filter is found, False otherwise
303
298
    """
 
299
    import warnings
304
300
    for filter in warnings.filters:
305
301
        if issubclass(DeprecationWarning, filter[2]):
306
302
            # This filter will effect DeprecationWarning
309
305
    return False
310
306
 
311
307
 
312
 
def _remove_filter_callable(filter):
313
 
    """Build and returns a callable removing filter from the warnings.
314
 
 
315
 
    :param filter: The filter to remove (can be None).
316
 
 
317
 
    :return: A callable that will remove filter from warnings.filters.
318
 
    """
319
 
    def cleanup():
320
 
        if filter:
321
 
            warnings.filters.remove(filter)
322
 
    return cleanup
323
 
 
324
 
 
325
308
def suppress_deprecation_warnings(override=True):
326
309
    """Call this function to suppress all deprecation warnings.
327
310
 
331
314
 
332
315
    :param override: If True, always set the ignore, if False, only set the
333
316
        ignore if there isn't already a filter.
334
 
 
335
 
    :return: A callable to remove the new warnings this added.
336
317
    """
 
318
    import warnings
337
319
    if not override and _check_for_filter(error_only=False):
338
320
        # If there is already a filter effecting suppress_deprecation_warnings,
339
321
        # then skip it.
340
 
        filter = None
341
 
    else:
342
 
        warnings.filterwarnings('ignore', category=DeprecationWarning)
343
 
        filter = warnings.filters[0]
344
 
    return _remove_filter_callable(filter)
 
322
        return
 
323
    warnings.filterwarnings('ignore', category=DeprecationWarning)
345
324
 
346
325
 
347
326
def activate_deprecation_warnings(override=True):
358
337
    :param override: If False, only add a filter if there isn't an error filter
359
338
        already. (This slightly differs from suppress_deprecation_warnings, in
360
339
        because it always overrides everything but -Werror).
361
 
 
362
 
    :return: A callable to remove the new warnings this added.
363
340
    """
 
341
    import warnings
364
342
    if not override and _check_for_filter(error_only=True):
365
343
        # DeprecationWarnings are already turned into errors, don't downgrade
366
344
        # them to 'default'.
367
 
        filter = None
368
 
    else:
369
 
        warnings.filterwarnings('default', category=DeprecationWarning)
370
 
        filter = warnings.filters[0]
371
 
    return _remove_filter_callable(filter)
 
345
        return
 
346
    warnings.filterwarnings('default', category=DeprecationWarning)