~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/symbol_versioning.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-02-11 04:02:41 UTC
  • mfrom: (5017.2.2 tariff)
  • Revision ID: pqm@pqm.ubuntu.com-20100211040241-w6n021dz0uus341n
(mbp) add import-tariff tests

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
29
29
           'warn',
30
30
           ]
31
31
 
32
 
 
33
 
import warnings
34
 
# Import the 'warn' symbol so bzrlib can call it even if we redefine it
35
32
from warnings import warn
36
33
 
37
34
import bzrlib
299
296
    :param error_only: Only match an 'error' filter
300
297
    :return: True if a filter is found, False otherwise
301
298
    """
 
299
    import warnings
302
300
    for filter in warnings.filters:
303
301
        if issubclass(DeprecationWarning, filter[2]):
304
302
            # This filter will effect DeprecationWarning
307
305
    return False
308
306
 
309
307
 
310
 
def _remove_filter_callable(filter):
311
 
    """Build and returns a callable removing filter from the warnings.
312
 
 
313
 
    :param filter: The filter to remove (can be None).
314
 
 
315
 
    :return: A callable that will remove filter from warnings.filters.
316
 
    """
317
 
    def cleanup():
318
 
        if filter:
319
 
            warnings.filters.remove(filter)
320
 
    return cleanup
321
 
 
322
 
 
323
308
def suppress_deprecation_warnings(override=True):
324
309
    """Call this function to suppress all deprecation warnings.
325
310
 
329
314
 
330
315
    :param override: If True, always set the ignore, if False, only set the
331
316
        ignore if there isn't already a filter.
332
 
 
333
 
    :return: A callable to remove the new warnings this added.
334
317
    """
 
318
    import warnings
335
319
    if not override and _check_for_filter(error_only=False):
336
320
        # If there is already a filter effecting suppress_deprecation_warnings,
337
321
        # then skip it.
338
 
        filter = None
339
 
    else:
340
 
        warnings.filterwarnings('ignore', category=DeprecationWarning)
341
 
        filter = warnings.filters[0]
342
 
    return _remove_filter_callable(filter)
 
322
        return
 
323
    warnings.filterwarnings('ignore', category=DeprecationWarning)
343
324
 
344
325
 
345
326
def activate_deprecation_warnings(override=True):
356
337
    :param override: If False, only add a filter if there isn't an error filter
357
338
        already. (This slightly differs from suppress_deprecation_warnings, in
358
339
        because it always overrides everything but -Werror).
359
 
 
360
 
    :return: A callable to remove the new warnings this added.
361
340
    """
 
341
    import warnings
362
342
    if not override and _check_for_filter(error_only=True):
363
343
        # DeprecationWarnings are already turned into errors, don't downgrade
364
344
        # them to 'default'.
365
 
        filter = None
366
 
    else:
367
 
        warnings.filterwarnings('default', category=DeprecationWarning)
368
 
        filter = warnings.filters[0]
369
 
    return _remove_filter_callable(filter)
 
345
        return
 
346
    warnings.filterwarnings('default', category=DeprecationWarning)