@@ -322,11 +322,12 @@ async def open_connection(self, host, port, local_addr, lbind):
322322 await self .streams
323323 return self .streams .result ()
324324 try :
325+ local_addr = local_addr if self .lbind == 'in' else (self .lbind , 0 ) if self .lbind else \
326+ local_addr if lbind == 'in' else (lbind , 0 ) if lbind else None
327+ family = 0 if local_addr is None else socket .AF_INET6 if ':' in local_addr [0 ] else socket .AF_INET
325328 if self .direct :
326329 if host == 'tunnel' :
327330 raise Exception ('Unknown tunnel endpoint' )
328- local_addr = local_addr if lbind == 'in' else (lbind , 0 ) if lbind else None
329- family = 0 if local_addr is None else socket .AF_INET6 if ':' in local_addr [0 ] else socket .AF_INET
330331 wait = asyncio .open_connection (host = host , port = port , local_addr = local_addr , family = family )
331332 elif self .ssh :
332333 try :
@@ -341,8 +342,6 @@ async def open_connection(self, host, port, local_addr, lbind):
341342 password = None
342343 else :
343344 client_keys = None
344- local_addr = local_addr if self .lbind == 'in' else (self .lbind , 0 ) if self .lbind else None
345- family = 0 if local_addr is None else socket .AF_INET6 if ':' in local_addr [0 ] else socket .AF_INET
346345 conn = await asyncssh .connect (host = self .host_name , port = self .port , local_addr = local_addr , family = family , x509_trusted_certs = None , known_hosts = None , username = username , password = password , client_keys = client_keys )
347346 if not self .streams .done ():
348347 self .streams .set_result ((conn , None ))
@@ -352,8 +351,6 @@ async def open_connection(self, host, port, local_addr, lbind):
352351 elif self .unix :
353352 wait = asyncio .open_unix_connection (path = self .bind , ssl = self .sslclient , server_hostname = '' if self .sslclient else None )
354353 else :
355- local_addr = local_addr if self .lbind == 'in' else (self .lbind , 0 ) if self .lbind else None
356- family = 0 if local_addr is None else socket .AF_INET6 if ':' in local_addr [0 ] else socket .AF_INET
357354 wait = asyncio .open_connection (host = self .host_name , port = self .port , ssl = self .sslclient , local_addr = local_addr , family = family )
358355 reader , writer = await asyncio .wait_for (wait , timeout = SOCKET_TIMEOUT )
359356 except Exception as ex :
0 commit comments