@@ -139,23 +139,23 @@ def format_error(address, err):
139
139
result [key ] = val
140
140
141
141
if isinstance (result ['port' ], int ):
142
- # Looks like an inet address.
142
+ # Looks like an inet address or socket fd .
143
143
144
144
# 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' )
151
149
152
150
# Validate port.
153
151
if not isinstance (result ['port' ], int ):
154
152
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' )
159
159
160
160
# Looks okay.
161
161
return result , None
@@ -447,7 +447,8 @@ def __init__(self, host=None, port=None,
447
447
# Don't change user provided arguments.
448
448
addrs = addrs [:]
449
449
450
- if host and port :
450
+ if port :
451
+ # host can be None in the case of socket fd or Unix socket.
451
452
addrs .insert (0 , {'host' : host ,
452
453
'port' : port ,
453
454
'transport' : transport ,
0 commit comments