Commit c7dc55eb authored by Victor Stinner's avatar Victor Stinner

Merge 3.4 (asyncio)

parents 0eb1896a f67f4602
...@@ -28,10 +28,12 @@ STDOUT = subprocess.STDOUT ...@@ -28,10 +28,12 @@ STDOUT = subprocess.STDOUT
_mmap_counter = itertools.count() _mmap_counter = itertools.count()
# Replacement for socket.socketpair() if hasattr(socket, 'socketpair'):
# Since Python 3.5, socket.socketpair() is now also available on Windows
socketpair = socket.socketpair
def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0): else:
# Replacement for socket.socketpair()
def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
"""A socket pair usable as a self-pipe, for Windows. """A socket pair usable as a self-pipe, for Windows.
Origin: https://gist.github.com/4325783, by Geert Jansen. Public domain. Origin: https://gist.github.com/4325783, by Geert Jansen. Public domain.
...@@ -41,7 +43,7 @@ def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0): ...@@ -41,7 +43,7 @@ def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
elif family == socket.AF_INET6: elif family == socket.AF_INET6:
host = '::1' host = '::1'
else: else:
raise ValueError("Ony AF_INET and AF_INET6 socket address families " raise ValueError("Only AF_INET and AF_INET6 socket address families "
"are supported") "are supported")
if type != socket.SOCK_STREAM: if type != socket.SOCK_STREAM:
raise ValueError("Only SOCK_STREAM socket type is supported") raise ValueError("Only SOCK_STREAM socket type is supported")
...@@ -63,8 +65,8 @@ def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0): ...@@ -63,8 +65,8 @@ def socketpair(family=socket.AF_INET, type=socket.SOCK_STREAM, proto=0):
csock.connect((addr, port)) csock.connect((addr, port))
except (BlockingIOError, InterruptedError): except (BlockingIOError, InterruptedError):
pass pass
ssock, _ = lsock.accept()
csock.setblocking(True) csock.setblocking(True)
ssock, _ = lsock.accept()
except: except:
csock.close() csock.close()
raise raise
......
...@@ -33,6 +33,8 @@ class WinsocketpairTests(unittest.TestCase): ...@@ -33,6 +33,8 @@ class WinsocketpairTests(unittest.TestCase):
ssock, csock = windows_utils.socketpair(family=socket.AF_INET6) ssock, csock = windows_utils.socketpair(family=socket.AF_INET6)
self.check_winsocketpair(ssock, csock) self.check_winsocketpair(ssock, csock)
@unittest.skipIf(hasattr(socket, 'socketpair'),
'socket.socketpair is available')
@mock.patch('asyncio.windows_utils.socket') @mock.patch('asyncio.windows_utils.socket')
def test_winsocketpair_exc(self, m_socket): def test_winsocketpair_exc(self, m_socket):
m_socket.AF_INET = socket.AF_INET m_socket.AF_INET = socket.AF_INET
...@@ -51,6 +53,8 @@ class WinsocketpairTests(unittest.TestCase): ...@@ -51,6 +53,8 @@ class WinsocketpairTests(unittest.TestCase):
self.assertRaises(ValueError, self.assertRaises(ValueError,
windows_utils.socketpair, proto=1) windows_utils.socketpair, proto=1)
@unittest.skipIf(hasattr(socket, 'socketpair'),
'socket.socketpair is available')
@mock.patch('asyncio.windows_utils.socket') @mock.patch('asyncio.windows_utils.socket')
def test_winsocketpair_close(self, m_socket): def test_winsocketpair_close(self, m_socket):
m_socket.AF_INET = socket.AF_INET m_socket.AF_INET = socket.AF_INET
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment