Index: Lib/socket.py =================================================================== --- Lib/socket.py (revision 56404) +++ Lib/socket.py (working copy) @@ -87,8 +87,11 @@ __all__.append("errorTab") -_os_has_dup = hasattr(os, "dup") -if _os_has_dup: +# True if os.dup() can duplicate socket descriptors. +# (On Windows at least, os.dup only works on files) +_can_dup_socket = hasattr(_socket, "dup") + +if _can_dup_socket: def fromfd(fd, family=AF_INET, type=SOCK_STREAM, proto=0): nfd = os.dup(fd) return socket(family, type, proto, fileno=nfd) @@ -99,7 +102,7 @@ """A subclass of _socket.socket adding the makefile() method.""" __slots__ = ["__weakref__"] - if not _os_has_dup: + if not _can_dup_socket: __slots__.append("_base") def __repr__(self): @@ -116,7 +119,7 @@ conn, addr = _socket.socket.accept(self) fd = conn.fileno() nfd = fd - if _os_has_dup: + if _can_dup_socket: nfd = os.dup(fd) wrapper = socket(self.family, self.type, self.proto, fileno=nfd) if fd == nfd: @@ -125,7 +128,7 @@ conn.close() return wrapper, addr - if not _os_has_dup: + if not _can_dup_socket: def close(self): """Wrap close() to close the _base as well.""" _socket.socket.close(self)