@@ -139,23 +139,23 @@ def format_error(address, err):
139139 result [key ] = val
140140
141141 if isinstance (result ['port' ], int ):
142- # Looks like an inet address.
142+ # Looks like an inet address or socket fd .
143143
144144 # Validate host.
145- if 'host' not in result or result ['host' ] is None :
146- return format_error (result ,
147- 'host is mandatory for an inet result' )
148- if not isinstance (result ['host' ], str ):
149- return format_error (result ,
150- 'host must be a string for an inet result' )
145+ if ('host' in result and result ['host' ] is not None
146+ and not isinstance (result ['host' ], str )):
147+ return format_error (result , 'host must be a string for an inet result, '
148+ 'or None for a socket fd result' )
151149
152150 # Validate port.
153151 if not isinstance (result ['port' ], int ):
154152 return format_error (result ,
155- 'port must be an int for an inet result' )
156- if result ['port' ] < 1 or result ['port' ] > 65535 :
157- return format_error (result , 'port must be in range [1, 65535] '
158- 'for an inet result' )
153+ 'port must be an int for an inet/socket fd result' )
154+ if 'host' in result and isinstance (result ['host' ], str ):
155+ # Check that the port is correct.
156+ if result ['port' ] < 1 or result ['port' ] > 65535 :
157+ return format_error (result , 'port must be in range [1, 65535] '
158+ 'for an inet result' )
159159
160160 # Looks okay.
161161 return result , None
@@ -447,7 +447,8 @@ def __init__(self, host=None, port=None,
447447 # Don't change user provided arguments.
448448 addrs = addrs [:]
449449
450- if host and port :
450+ if port :
451+ # host can be None in the case of socket fd or Unix socket.
451452 addrs .insert (0 , {'host' : host ,
452453 'port' : port ,
453454 'transport' : transport ,
0 commit comments