code: def read_until(self, expected_commands, timeout):
      
      msg = timeouts.loop_until_timeout_or_valid(
          timeout, lambda: self.read_message(timeout),
          lambda m: m.command in expected_commands, 0)
      if msg.command not in expected_commands:
        raise usb_exceptions.AdbTimeoutError(
            'Timed out establishing connection, waiting for: %s',
            expected_commands)
      return msg
docs: Read AdbMessages from this transport until we get an expected command.
  
      The ADB protocol specifies that before a successful CNXN handshake, any
      other packets must be ignored, so this method provides the ability to
      ignore unwanted commands.  It's primarily used during the initial
      connection to the device.  See Read() for more details, including more
      exceptions that may be raised.
  
      Args:
        expected_commands: Iterable of expected command responses, like
            ('CNXN', 'AUTH').
        timeout: timeouts.PolledTimeout object to use for timeout.
  
      Returns:
        The ADB message received that matched one of expected_commands.
  
      Raises:
        AdbProtocolError: If timeout expires between reads, this can happen
          if we are getting spammed with unexpected commands.