diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-14 18:00:02 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-14 18:00:02 (GMT) |
commit | 9e0b864ac07ab85b618ccf3831eae97b2c91fb2e (patch) | |
tree | 195459e4f65f8d63c3ecd298f6d3790055a73b81 /Lib/socket.py | |
parent | 38615993b0b13729cc2afaa69686f5bff17547c4 (diff) | |
download | cpython-9e0b864ac07ab85b618ccf3831eae97b2c91fb2e.zip cpython-9e0b864ac07ab85b618ccf3831eae97b2c91fb2e.tar.gz cpython-9e0b864ac07ab85b618ccf3831eae97b2c91fb2e.tar.bz2 |
Issue #1552: socket.socketpair() now returns regular socket.socket
objects supporting the whole socket API (rather than the "raw"
_socket.socket objects).
Diffstat (limited to 'Lib/socket.py')
-rw-r--r-- | Lib/socket.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/socket.py b/Lib/socket.py index bfc9a726..9b5b23d 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -199,6 +199,27 @@ def fromfd(fd, family, type, proto=0): return socket(family, type, proto, nfd) +if hasattr(_socket, "socketpair"): + + def socketpair(family=None, type=SOCK_STREAM, proto=0): + """socketpair([family[, type[, proto]]]) -> (socket object, socket object) + + Create a pair of socket objects from the sockets returned by the platform + socketpair() function. + The arguments are the same as for socket() except the default family is + AF_UNIX if defined on the platform; otherwise, the default is AF_INET. + """ + if family is None: + try: + family = AF_UNIX + except NameError: + family = AF_INET + a, b = _socket.socketpair(family, type, proto) + a = socket(family, type, proto, a.detach()) + b = socket(family, type, proto, b.detach()) + return a, b + + class SocketIO(io.RawIOBase): """Raw I/O implementation for stream sockets. |