def _MaybeFindPrompt(self):
    """Perform real login and then enable if we have an enable password."""
    # We always run this for HP, no matter the state of self._find_prompt.
    self._prompt = r'(?:^|\n|\r)([A-Za-z0-9\._-]+)(?:>|#) '
    # Shake out the prompt.  We may be facing a Password prompt or
    # a 'Press any key to continue' prompt.
    self.child.send('\r')

    # Only send the password once.
    password_sent = False
    try:
      # Login.
      while True:
        logging.vlog(3, 'Expecting prompt %r', self._prompt)
        compiled_regexes = self.child.compile_pattern_list(
            [self._prompt, r'Press any key to continue',
             'Password:', 'Invalid password',
             'Unable to verify password'])
        i = self.child.expect(compiled_regexes, timeout=10)
        if i == 0:
          re_str = (re.escape(self.child.match.group(1)) +
                    r'(?:>|#) ')
          logging.vlog(3, 'Prompt set to %r', re_str)
          self.re_prompt = re.compile(re_str)
          break
        elif i == 1:
          logging.vlog(3, 'Pressing any key (space)')
          self.child.send(' ')
        elif i == 2 and not password_sent:
          # Send the password only once.
          try:
            self.child.sendline(self._password)
            logging.vlog(3, 'Sent user password (again) to %r', self._host)
            password_sent = True
          except (pexpect.TIMEOUT, pexpect.EOF) as e:
            self._ssh_client = None
            raise ConnectionError(str(e))
        elif 3 <= i and i < 5:
          logging.error('CONNECT_ERROR Incorrect user password on %r',
                        self._host)

        # Sleep momentarily before expecting again to break buffer swap races.
        time.sleep(0.05)

      # Enable.
      password_sent = False
      logging.vlog(3, 'Enabling for HP on %r', self._host)
      self.child.sendline('enable')
      while True:
        i = self.child.expect([self._prompt, 'Password:',
                               'Invalid password',
                               'Unable to verify password'], timeout=10)
        if i == 0:
          # Found the prompt, we're enabled.
          break
        elif i == 1 and not password_sent:
          if self._enable_password is not None:
            self.child.sendline(self._enable_password)
            logging.vlog(3, 'Sent enable password to %r', self._host)
          else:
            self.child.sendline(self._password)
            logging.vlog(3, 'Sent user password to %r', self._host)
          password_sent = True
        elif i <= 3 and i < 5:
          logging.error('CONNECT_ERROR Incorrect user password on %r',
                        self._host)
          # Sleep momentarily before expecting again to break buffer swap races.
          time.sleep(0.05)
    except (pexpect.TIMEOUT, pexpect.EOF) as e:
      self._ssh_client = None
      raise ConnectionError(str(e))
dataset/ETHPy150Open google/capirca/tools/ldpush/pexpect_connection.py/HpSshFilterConnection._MaybeFindPrompt/swapped operands of `<=`