summaryrefslogtreecommitdiffstats
path: root/Lib/signal.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2015-03-19 00:27:57 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2015-03-19 00:27:57 (GMT)
commit24e837f23126eab7486a77f3cb51b982226adb70 (patch)
treef73fe9872045e331ab42f6c34b2109620d9347f7 /Lib/signal.py
parent8eef6a9ad04f6f81190f44ae3ded427e4083baa2 (diff)
downloadcpython-24e837f23126eab7486a77f3cb51b982226adb70.zip
cpython-24e837f23126eab7486a77f3cb51b982226adb70.tar.gz
cpython-24e837f23126eab7486a77f3cb51b982226adb70.tar.bz2
issue23673
add private method to enum to support replacing global constants with Enum members: - search for candidate constants via supplied filter - create new enum class and members - insert enum class and replace constants with members via supplied module name - replace __reduce_ex__ with function that returns member name, so previous Python versions can unpickle modify IntEnum classes to use new method
Diffstat (limited to 'Lib/signal.py')
-rw-r--r--Lib/signal.py30
1 files changed, 12 insertions, 18 deletions
diff --git a/Lib/signal.py b/Lib/signal.py
index 0db3df8..371d712 100644
--- a/Lib/signal.py
+++ b/Lib/signal.py
@@ -5,27 +5,21 @@ from enum import IntEnum as _IntEnum
_globals = globals()
-Signals = _IntEnum(
- 'Signals',
- {name: value for name, value in _globals.items()
- if name.isupper()
- and (name.startswith('SIG') and not name.startswith('SIG_'))
- or name.startswith('CTRL_')})
+_IntEnum._convert(
+ 'Signals', __name__,
+ lambda name:
+ name.isupper()
+ and (name.startswith('SIG') and not name.startswith('SIG_'))
+ or name.startswith('CTRL_'))
-class Handlers(_IntEnum):
- SIG_DFL = _signal.SIG_DFL
- SIG_IGN = _signal.SIG_IGN
-
-_globals.update(Signals.__members__)
-_globals.update(Handlers.__members__)
+_IntEnum._convert(
+ 'Handlers', __name__,
+ lambda name: name in ('SIG_DFL', 'SIG_IGN'))
if 'pthread_sigmask' in _globals:
- class Sigmasks(_IntEnum):
- SIG_BLOCK = _signal.SIG_BLOCK
- SIG_UNBLOCK = _signal.SIG_UNBLOCK
- SIG_SETMASK = _signal.SIG_SETMASK
-
- _globals.update(Sigmasks.__members__)
+ _IntEnum._convert(
+ 'Sigmasks', __name__,
+ lambda name: name in ('SIG_BLOCK', 'SIG_UNBLOCK', 'SIG_SETMASK'))
def _int_to_enum(value, enum_klass):