Issue #1552: socket.socketpair() now returns regular socket.socket
objects supporting the whole socket API (rather than the "raw" _socket.socket objects).
This commit is contained in:
parent
38615993b0
commit
9e0b864ac0
|
@ -364,6 +364,10 @@ The module :mod:`socket` exports the following constants and functions:
|
||||||
if defined on the platform; otherwise, the default is :const:`AF_INET`.
|
if defined on the platform; otherwise, the default is :const:`AF_INET`.
|
||||||
Availability: Unix.
|
Availability: Unix.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.2
|
||||||
|
The returned socket objects now support the whole socket API, rather
|
||||||
|
than a subset.
|
||||||
|
|
||||||
|
|
||||||
.. function:: fromfd(fd, family, type[, proto])
|
.. function:: fromfd(fd, family, type[, proto])
|
||||||
|
|
||||||
|
|
|
@ -199,6 +199,27 @@ def fromfd(fd, family, type, proto=0):
|
||||||
return socket(family, type, proto, nfd)
|
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):
|
class SocketIO(io.RawIOBase):
|
||||||
|
|
||||||
"""Raw I/O implementation for stream sockets.
|
"""Raw I/O implementation for stream sockets.
|
||||||
|
|
|
@ -714,6 +714,7 @@ class BasicTCPTest(SocketConnectedTest):
|
||||||
# Testing fromfd()
|
# Testing fromfd()
|
||||||
fd = self.cli_conn.fileno()
|
fd = self.cli_conn.fileno()
|
||||||
sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.fromfd(fd, socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
self.assertIsInstance(sock, socket.socket)
|
||||||
msg = sock.recv(1024)
|
msg = sock.recv(1024)
|
||||||
self.assertEqual(msg, MSG)
|
self.assertEqual(msg, MSG)
|
||||||
|
|
||||||
|
@ -814,6 +815,23 @@ class BasicSocketPairTest(SocketPairTest):
|
||||||
def __init__(self, methodName='runTest'):
|
def __init__(self, methodName='runTest'):
|
||||||
SocketPairTest.__init__(self, methodName=methodName)
|
SocketPairTest.__init__(self, methodName=methodName)
|
||||||
|
|
||||||
|
def _testDefaults(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def testDefaults(self):
|
||||||
|
self.assertIsInstance(self.cli, socket.socket)
|
||||||
|
self.assertIsInstance(self.serv, socket.socket)
|
||||||
|
if hasattr(socket, 'AF_UNIX'):
|
||||||
|
self.assertEqual(self.cli.family, socket.AF_UNIX)
|
||||||
|
self.assertEqual(self.serv.family, socket.AF_UNIX)
|
||||||
|
else:
|
||||||
|
self.assertEqual(self.cli.family, socket.AF_INET)
|
||||||
|
self.assertEqual(self.serv.family, socket.AF_INET)
|
||||||
|
self.assertEqual(self.cli.type, socket.SOCK_STREAM)
|
||||||
|
self.assertEqual(self.serv.type, socket.SOCK_STREAM)
|
||||||
|
self.assertEqual(self.cli.proto, 0)
|
||||||
|
self.assertEqual(self.serv.proto, 0)
|
||||||
|
|
||||||
def testRecv(self):
|
def testRecv(self):
|
||||||
msg = self.serv.recv(1024)
|
msg = self.serv.recv(1024)
|
||||||
self.assertEqual(msg, MSG)
|
self.assertEqual(msg, MSG)
|
||||||
|
|
|
@ -52,6 +52,10 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #1552: socket.socketpair() now returns regular socket.socket
|
||||||
|
objects supporting the whole socket API (rather than the "raw"
|
||||||
|
_socket.socket objects).
|
||||||
|
|
||||||
- Issue #9853: Fix the signature of SSLSocket.recvfrom() and
|
- Issue #9853: Fix the signature of SSLSocket.recvfrom() and
|
||||||
SSLSocket.sendto() to match the corresponding socket methods.
|
SSLSocket.sendto() to match the corresponding socket methods.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue