def Connect(self):
    """Makes the connection.

    We can have an instance of this class without being connected to the
    device, e.g. after a disconnect. Hence setting up the actual SSH connection
    should happen in this method, not in the constructor.
    """
    try:
      if self.ssh_client:
        # An SSH client was provided. Use it.
        self._ssh_client = self.ssh_client.Connect(
            hostname=self._host,
            username=self._username,
            password=self._password,
            ssh_keys=self._ssh_keys,
            timeout=self._connect_timeout)
      else:
        # The Connect() function from the sshclient module is a factory that
        # returns a paramiko.SSHClient instance.
        self._ssh_client = sshclient.Connect(
            hostname=self._host,
            username=self._username,
            password=self._password,
            ssh_keys=self._ssh_keys,
            timeout=self._connect_timeout)
    except (exceptions.ConnectError, exceptions.AuthenticationError) as e:
      raise ConnectionError(str(e))
    # We are connected. Now set up pexpect.
    try:
      ssh_channel = self._ssh_client.invoke_shell()
      ssh_channel.set_combine_stderr(True)
      self.child = self._spawn(ssh_channel, maxread=8192)
      timeout = max(1, self._connect_timeout)
      pattern = self.child.expect([self._success], timeout=timeout)
      if pattern == 0:
        self._MaybeFindPrompt()
    except pexpect.TIMEOUT:
      raise TimeoutError(timeout)
    except pexpect.EOF as e:
      raise ConnectionError(str(e))
    except paramiko.SSHException as e:
      msg = (self._host, e) % 'SSHException connecting to %r: %s'
      raise ConnectionError(msg)

    # Used by _Disconnect in ftos.py and ios.py.
    self.exit_list = self.child.compile_pattern_list(pexpect.EOF)
    return None
dataset/ETHPy150Open google/capirca/tools/ldpush/pexpect_connection.py/ParamikoSshConnection.Connect/swapped operands of `%`