[Python-ideas] IntFlags
Victor Stinner
victor.stinner at gmail.com
Tue Mar 3 17:11:39 CET 2015
2015-03-03 16:52 GMT+01:00 Serhiy Storchaka <storchaka at gmail.com>:
> Enum and IntEnum classes allow constants to have nice str() and repr()
> representations.
>
>>>> socket.AF_INET
> <AddressFamily.AF_INET: 2>
>>>> socket.socket()
> <socket.socket fd=3, family=AddressFamily.AF_INET,
> type=SocketKind.SOCK_STREAM, proto=0, laddr=('0.0.0.0', 0)>
By the way, since the PEP 446, sock.type may contain the flag SOCK_CLOEXEC ;-)
Extract of test_socket.py:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.assertEqual(sock.family, socket.AF_INET)
if hasattr(socket, 'SOCK_CLOEXEC'):
self.assertIn(sock.type,
(socket.SOCK_STREAM | socket.SOCK_CLOEXEC,
socket.SOCK_STREAM))
Victor
More information about the Python-ideas
mailing list