@@ -98,14 +98,6 @@ def _is_dgram_socket(sock):
98
98
return (sock .type & socket .SOCK_DGRAM ) == socket .SOCK_DGRAM
99
99
100
100
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
-
109
101
def _ipaddr_info (host , port , family , type , proto ):
110
102
# Try to skip getaddrinfo if "host" is already an IP. Users might have
111
103
# 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, *,
795
787
if sock is None :
796
788
raise ValueError (
797
789
'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.
799
797
raise ValueError (
800
- 'A TCP Stream Socket was expected, got {!r}' .format (sock ))
798
+ 'A Stream Socket was expected, got {!r}' .format (sock ))
801
799
802
800
transport , protocol = yield from self ._create_connection_transport (
803
801
sock , protocol_factory , ssl , server_hostname )
@@ -1054,9 +1052,9 @@ def create_server(self, protocol_factory, host=None, port=None,
1054
1052
else :
1055
1053
if sock is None :
1056
1054
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 ):
1058
1056
raise ValueError (
1059
- 'A TCP Stream Socket was expected, got {!r}' .format (sock ))
1057
+ 'A Stream Socket was expected, got {!r}' .format (sock ))
1060
1058
sockets = [sock ]
1061
1059
1062
1060
server = Server (self , sockets )
0 commit comments