ยปCore Development>Code coverage>Lib/signal.py

Python code coverage for Lib/signal.py

#countcontent
1n/aimport _signal
2n/afrom _signal import *
3n/afrom functools import wraps as _wraps
4n/afrom enum import IntEnum as _IntEnum
5n/a
6n/a_globals = globals()
7n/a
8n/a_IntEnum._convert(
9n/a 'Signals', __name__,
10n/a lambda name:
11n/a name.isupper()
12n/a and (name.startswith('SIG') and not name.startswith('SIG_'))
13n/a or name.startswith('CTRL_'))
14n/a
15n/a_IntEnum._convert(
16n/a 'Handlers', __name__,
17n/a lambda name: name in ('SIG_DFL', 'SIG_IGN'))
18n/a
19n/aif 'pthread_sigmask' in _globals:
20n/a _IntEnum._convert(
21n/a 'Sigmasks', __name__,
22n/a lambda name: name in ('SIG_BLOCK', 'SIG_UNBLOCK', 'SIG_SETMASK'))
23n/a
24n/a
25n/adef _int_to_enum(value, enum_klass):
26n/a """Convert a numeric value to an IntEnum member.
27n/a If it's not a known member, return the numeric value itself.
28n/a """
29n/a try:
30n/a return enum_klass(value)
31n/a except ValueError:
32n/a return value
33n/a
34n/a
35n/adef _enum_to_int(value):
36n/a """Convert an IntEnum member to a numeric value.
37n/a If it's not an IntEnum member return the value itself.
38n/a """
39n/a try:
40n/a return int(value)
41n/a except (ValueError, TypeError):
42n/a return value
43n/a
44n/a
45n/a@_wraps(_signal.signal)
46n/adef signal(signalnum, handler):
47n/a handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
48n/a return _int_to_enum(handler, Handlers)
49n/a
50n/a
51n/a@_wraps(_signal.getsignal)
52n/adef getsignal(signalnum):
53n/a handler = _signal.getsignal(signalnum)
54n/a return _int_to_enum(handler, Handlers)
55n/a
56n/a
57n/aif 'pthread_sigmask' in _globals:
58n/a @_wraps(_signal.pthread_sigmask)
59n/a def pthread_sigmask(how, mask):
60n/a sigs_set = _signal.pthread_sigmask(how, mask)
61n/a return set(_int_to_enum(x, Signals) for x in sigs_set)
62n/a pthread_sigmask.__doc__ = _signal.pthread_sigmask.__doc__
63n/a
64n/a
65n/aif 'sigpending' in _globals:
66n/a @_wraps(_signal.sigpending)
67n/a def sigpending():
68n/a sigs = _signal.sigpending()
69n/a return set(_int_to_enum(x, Signals) for x in sigs)
70n/a
71n/a
72n/aif 'sigwait' in _globals:
73n/a @_wraps(_signal.sigwait)
74n/a def sigwait(sigset):
75n/a retsig = _signal.sigwait(sigset)
76n/a return _int_to_enum(retsig, Signals)
77n/a sigwait.__doc__ = _signal.sigwait
78n/a
79n/adel _globals, _wraps