Fixed Socket.connect() method arguments.

This commit is contained in:
Joe Testa 2017-10-31 16:49:19 -04:00
parent 95ca0bb243
commit f44663bfc4
1 changed files with 12 additions and 9 deletions

View File

@ -1832,7 +1832,7 @@ class SSH(object): # pylint: disable=too-few-public-methods
SM_BANNER_SENT = 1 SM_BANNER_SENT = 1
def __init__(self, host, port): def __init__(self, host, port, ipvo, timeout):
# type: (Optional[str], int) -> None # type: (Optional[str], int) -> None
super(SSH.Socket, self).__init__() super(SSH.Socket, self).__init__()
self.__sock = None # type: Optional[socket.socket] self.__sock = None # type: Optional[socket.socket]
@ -1847,7 +1847,12 @@ class SSH(object): # pylint: disable=too-few-public-methods
raise ValueError('invalid port: {0}'.format(port)) raise ValueError('invalid port: {0}'.format(port))
self.__host = host self.__host = host
self.__port = nport self.__port = nport
self.__ipvo = () if ipvo is not None:
self.__ipvo = ipvo
else:
self.__ipvo = ()
self.__timeout = timeout
def _resolve(self, ipvo): def _resolve(self, ipvo):
# type: (Sequence[int]) -> Iterable[Tuple[int, Tuple[Any, ...]]] # type: (Sequence[int]) -> Iterable[Tuple[int, Tuple[Any, ...]]]
@ -1872,16 +1877,14 @@ class SSH(object): # pylint: disable=too-few-public-methods
out.fail('[exception] {0}'.format(e)) out.fail('[exception] {0}'.format(e))
sys.exit(1) sys.exit(1)
def connect(self, ipvo, timeout): def connect(self):
# type: (Sequence[int], float) -> None # type: () -> None
err = None err = None
if ipvo is not None:
self.__ipvo = ipvo
for af, addr in self._resolve(self.__ipvo): for af, addr in self._resolve(self.__ipvo):
s = None s = None
try: try:
s = socket.socket(af, socket.SOCK_STREAM) s = socket.socket(af, socket.SOCK_STREAM)
s.settimeout(timeout) s.settimeout(self.__timeout)
s.connect(addr) s.connect(addr)
self.__sock = s self.__sock = s
return return
@ -2835,8 +2838,8 @@ def audit(aconf, sshv=None):
out.verbose = aconf.verbose out.verbose = aconf.verbose
out.level = aconf.level out.level = aconf.level
out.use_colors = aconf.colors out.use_colors = aconf.colors
s = SSH.Socket(aconf.host, aconf.port) s = SSH.Socket(aconf.host, aconf.port, aconf.ipvo, aconf.timeout)
s.connect(aconf.ipvo, aconf.timeout) s.connect()
if sshv is None: if sshv is None:
sshv = 2 if aconf.ssh2 else 1 sshv = 2 if aconf.ssh2 else 1
err = None err = None