Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5cb0c09

Browse files
committed
Merge 3.5 (issue #28652)
2 parents bf87126 + dab0584 commit 5cb0c09

2 files changed

Lines changed: 14 additions & 18 deletions

File tree

Lib/asyncio/base_events.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@ def _is_dgram_socket(sock):
9898
return (sock.type & socket.SOCK_DGRAM) == socket.SOCK_DGRAM
9999

100100

101-
def _is_ip_socket(sock):
102-
if sock.family == socket.AF_INET:
103-
return True
104-
if hasattr(socket, 'AF_INET6') and sock.family == socket.AF_INET6:
105-
return True
106-
return False
107-
108-
109101
def _ipaddr_info(host, port, family, type, proto):
110102
# Try to skip getaddrinfo if "host" is already an IP. Users might have
111103
# handled name resolution in their own code and pass in resolved IPs.
@@ -796,9 +788,15 @@ def create_connection(self, protocol_factory, host=None, port=None, *,
796788
if sock is None:
797789
raise ValueError(
798790
'host and port was not specified and no sock specified')
799-
if not _is_stream_socket(sock) or not _is_ip_socket(sock):
791+
if not _is_stream_socket(sock):
792+
# We allow AF_INET, AF_INET6, AF_UNIX as long as they
793+
# are SOCK_STREAM.
794+
# We support passing AF_UNIX sockets even though we have
795+
# a dedicated API for that: create_unix_connection.
796+
# Disallowing AF_UNIX in this method, breaks backwards
797+
# compatibility.
800798
raise ValueError(
801-
'A TCP Stream Socket was expected, got {!r}'.format(sock))
799+
'A Stream Socket was expected, got {!r}'.format(sock))
802800

803801
transport, protocol = yield from self._create_connection_transport(
804802
sock, protocol_factory, ssl, server_hostname)
@@ -1055,9 +1053,9 @@ def create_server(self, protocol_factory, host=None, port=None,
10551053
else:
10561054
if sock is None:
10571055
raise ValueError('Neither host/port nor sock were specified')
1058-
if not _is_stream_socket(sock) or not _is_ip_socket(sock):
1056+
if not _is_stream_socket(sock):
10591057
raise ValueError(
1060-
'A TCP Stream Socket was expected, got {!r}'.format(sock))
1058+
'A Stream Socket was expected, got {!r}'.format(sock))
10611059
sockets = [sock]
10621060

10631061
server = Server(self, sockets)

Lib/test/test_asyncio/test_base_events.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,22 +1047,20 @@ def test_create_connection_host_port_sock(self):
10471047
MyProto, 'example.com', 80, sock=object())
10481048
self.assertRaises(ValueError, self.loop.run_until_complete, coro)
10491049

1050-
@unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'no Unix sockets')
10511050
def test_create_connection_wrong_sock(self):
1052-
sock = socket.socket(socket.AF_UNIX)
1051+
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
10531052
with sock:
10541053
coro = self.loop.create_connection(MyProto, sock=sock)
10551054
with self.assertRaisesRegex(ValueError,
1056-
'A TCP Stream Socket was expected'):
1055+
'A Stream Socket was expected'):
10571056
self.loop.run_until_complete(coro)
10581057

1059-
@unittest.skipUnless(hasattr(socket, 'AF_UNIX'), 'no Unix sockets')
10601058
def test_create_server_wrong_sock(self):
1061-
sock = socket.socket(socket.AF_UNIX)
1059+
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
10621060
with sock:
10631061
coro = self.loop.create_server(MyProto, sock=sock)
10641062
with self.assertRaisesRegex(ValueError,
1065-
'A TCP Stream Socket was expected'):
1063+
'A Stream Socket was expected'):
10661064
self.loop.run_until_complete(coro)
10671065

10681066
@unittest.skipUnless(hasattr(socket, 'SOCK_NONBLOCK'),

0 commit comments

Comments
 (0)