diff -r 587fd4b91120 Lib/socket.py --- a/Lib/socket.py Tue Feb 18 12:37:12 2014 -0800 +++ b/Lib/socket.py Tue Feb 18 23:10:23 2014 +0200 @@ -66,12 +66,18 @@ # 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', +class _PickledByNameIntEnum(IntEnum): + def __reduce_ex__(self, proto): + if proto < 4: + return getattr, (self.__class__, self.name) + return self.__class__.__qualname__ + '.' + self.name + +AddressFamily = _PickledByNameIntEnum('AddressFamily', {name: value for name, value in globals().items() if name.isupper() and name.startswith('AF_')}) globals().update(AddressFamily.__members__) -SocketType = IntEnum('SocketType', +SocketType = _PickledByNameIntEnum('SocketType', {name: value for name, value in globals().items() if name.isupper() and name.startswith('SOCK_')}) globals().update(SocketType.__members__)