@@ -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-
109101def _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.
@@ -795,9 +787,15 @@ def create_connection(self, protocol_factory, host=None, port=None, *,
795787 if sock is None :
796788 raise ValueError (
797789 'host and port was not specified and no sock specified' )
798- if not _is_stream_socket (sock ) or not _is_ip_socket (sock ):
790+ if not _is_stream_socket (sock ):
791+ # We allow AF_INET, AF_INET6, AF_UNIX as long as they
792+ # are SOCK_STREAM.
793+ # We support passing AF_UNIX sockets even though we have
794+ # a dedicated API for that: create_unix_connection.
795+ # Disallowing AF_UNIX in this method, breaks backwards
796+ # compatibility.
799797 raise ValueError (
800- 'A TCP Stream Socket was expected, got {!r}' .format (sock ))
798+ 'A Stream Socket was expected, got {!r}' .format (sock ))
801799
802800 transport , protocol = yield from self ._create_connection_transport (
803801 sock , protocol_factory , ssl , server_hostname )
@@ -1054,9 +1052,9 @@ def create_server(self, protocol_factory, host=None, port=None,
10541052 else :
10551053 if sock is None :
10561054 raise ValueError ('Neither host/port nor sock were specified' )
1057- if not _is_stream_socket (sock ) or not _is_ip_socket ( sock ) :
1055+ if not _is_stream_socket (sock ):
10581056 raise ValueError (
1059- 'A TCP Stream Socket was expected, got {!r}' .format (sock ))
1057+ 'A Stream Socket was expected, got {!r}' .format (sock ))
10601058 sockets = [sock ]
10611059
10621060 server = Server (self , sockets )
0 commit comments