@@ -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.
@@ -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 )
0 commit comments