aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/warnings.py
blob: 6759857d909399272c635189a71e21c698795c34 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import sys

__all__ = [
    "warn",
    "warn_explicit",
    "showwarning",
    "formatwarning",
    "filterwarnings",
    "simplefilter",
    "resetwarnings",
    "catch_warnings",
    "deprecated",
]

from _py_warnings import (
    WarningMessage,
    _DEPRECATED_MSG,
    _OptionError,
    _add_filter,
    _deprecated,
    _filters_mutated,
    _filters_mutated_lock_held,
    _filters_version,
    _formatwarning_orig,
    _formatwarnmsg,
    _formatwarnmsg_impl,
    _get_context,
    _get_filters,
    _getaction,
    _getcategory,
    _is_filename_to_skip,
    _is_internal_filename,
    _is_internal_frame,
    _lock,
    _new_context,
    _next_external_frame,
    _processoptions,
    _set_context,
    _set_module,
    _setoption,
    _setup_defaults,
    _showwarning_orig,
    _showwarnmsg,
    _showwarnmsg_impl,
    _use_context,
    _warn_unawaited_coroutine,
    _warnings_context,
    catch_warnings,
    defaultaction,
    deprecated,
    filters,
    filterwarnings,
    formatwarning,
    onceregistry,
    resetwarnings,
    showwarning,
    simplefilter,
    warn,
    warn_explicit,
)

try:
    # Try to use the C extension, this will replace some parts of the
    # _py_warnings implementation imported above.
    from _warnings import (
        _acquire_lock,
        _defaultaction as defaultaction,
        _filters_mutated_lock_held,
        _onceregistry as onceregistry,
        _release_lock,
        _warnings_context,
        filters,
        warn,
        warn_explicit,
    )

    _warnings_defaults = True

    class _Lock:
        def __enter__(self):
            _acquire_lock()
            return self

        def __exit__(self, *args):
            _release_lock()

    _lock = _Lock()
except ImportError:
    _warnings_defaults = False


# Module initialization
_set_module(sys.modules[__name__])
_processoptions(sys.warnoptions)
if not _warnings_defaults:
    _setup_defaults()

del _warnings_defaults
del _setup_defaults