summaryrefslogtreecommitdiffstats
path: root/Lib/socket.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/socket.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/socket.py')
-rw-r--r--Lib/socket.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/socket.py b/Lib/socket.py
index 9c39c69..db34ab3 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -69,16 +69,16 @@ __all__.extend(os._get_exports_list(_socket))
# Note that _socket only knows about the integer values. The public interface
# in this module understands the enums and translates them back from integers
# where needed (e.g. .family property of a socket object).
-AddressFamily = IntEnum('AddressFamily',
- {name: value for name, value in globals().items()
- if name.isupper() and name.startswith('AF_')})
-globals().update(AddressFamily.__members__)
-SocketKind = IntEnum('SocketKind',
- {name: value for name, value in globals().items()
- if name.isupper() and name.startswith('SOCK_')})
-globals().update(SocketKind.__members__)
+IntEnum._convert(
+ 'AddressFamily',
+ __name__,
+ lambda C: C.isupper() and C.startswith('AF_'))
+IntEnum._convert(
+ 'SocketKind',
+ __name__,
+ lambda C: C.isupper() and C.startswith('SOCK_'))
_LOCALHOST = '127.0.0.1'
_LOCALHOST_V6 = '::1'