parameters: (self, success_regex, failure_regex=None, timeout=None,
                retries=None)
docstring: Wait for a matching logcat line or until a timeout occurs.
  
      This will attempt to match lines in the logcat against both |success_regex|
      and |failure_regex| (if provided). Note that this calls re.search on each
      logcat line, not re.match, so the provided regular expressions don't have
      to match an entire line.
  
      Args:
        success_regex: The regular expression to search for.
        failure_regex: An optional regular expression that, if hit, causes this
          to stop looking for a match. Can be None.
        timeout: timeout in seconds
        retries: number of retries
  
      Returns:
        A match object if |success_regex| matches a part of a logcat line, or
        None if |failure_regex| matches a part of a logcat line.
      Raises:
        CommandFailedError on logcat failure (NOT on a |failure_regex| match).
        CommandTimeoutError if no logcat line matching either |success_regex| or
          |failure_regex| is found in |timeout| seconds.
        DeviceUnreachableError if the device becomes unreachable.
        LogcatMonitorCommandError when calling |WaitFor| while not recording
          logcat.
docstring_summary: Wait for a matching logcat line or until a timeout occurs.
docstring_tokens: Wait for a matching logcat line or until a timeout occurs .
function: def WaitFor(self, success_regex, failure_regex=None, timeout=None,
                retries=None):
      """Wait for a matching logcat line or until a timeout occurs.
  
      This will attempt to match lines in the logcat against both |success_regex|
      and |failure_regex| (if provided). Note that this calls re.search on each
      logcat line, not re.match, so the provided regular expressions don't have
      to match an entire line.
  
      Args:
        success_regex: The regular expression to search for.
        failure_regex: An optional regular expression that, if hit, causes this
          to stop looking for a match. Can be None.
        timeout: timeout in seconds
        retries: number of retries
  
      Returns:
        A match object if |success_regex| matches a part of a logcat line, or
        None if |failure_regex| matches a part of a logcat line.
      Raises:
        CommandFailedError on logcat failure (NOT on a |failure_regex| match).
        CommandTimeoutError if no logcat line matching either |success_regex| or
          |failure_regex| is found in |timeout| seconds.
        DeviceUnreachableError if the device becomes unreachable.
        LogcatMonitorCommandError when calling |WaitFor| while not recording
          logcat.
      """
      if self._record_thread is None:
        raise LogcatMonitorCommandError(
            'Must be recording logcat when calling |WaitFor|',
            device_serial=str(self._adb))
      if isinstance(success_regex, basestring):
        success_regex = re.compile(success_regex)
      if isinstance(failure_regex, basestring):
        failure_regex = re.compile(failure_regex)
  
      logger.debug('Waiting %d seconds for "%s"', timeout, success_regex.pattern)
  
      # NOTE This will continue looping until:
      #  - success_regex matches a line, in which case the match object is
      #    returned.
      #  - failure_regex matches a line, in which case None is returned
      #  - the timeout is hit, in which case a CommandTimeoutError is raised.
      with open(self._record_file.name, 'r') as f:
        while True:
          line = f.readline()
          if line:
            m = success_regex.search(line)
            if m:
              return m
            if failure_regex and failure_regex.search(line):
              return None
          else:
            time.sleep(self._WAIT_TIME)
function_tokens: def WaitFor ( self , success_regex , failure_regex = None , timeout = None , retries = None ) : if self . _record_thread is None : raise LogcatMonitorCommandError ( 'Must be recording logcat when calling |WaitFor|' , device_serial = str ( self . _adb ) ) if isinstance ( success_regex , basestring ) : success_regex = re . compile ( success_regex ) if isinstance ( failure_regex , basestring ) : failure_regex = re . compile ( failure_regex ) logger . debug ( 'Waiting %d seconds for "%s"' , timeout , success_regex . pattern ) # NOTE This will continue looping until: #  - success_regex matches a line, in which case the match object is #    returned. #  - failure_regex matches a line, in which case None is returned #  - the timeout is hit, in which case a CommandTimeoutError is raised. with open ( self . _record_file . name , 'r' ) as f : while True : line = f . readline ( ) if line : m = success_regex . search ( line ) if m : return m if failure_regex and failure_regex . search ( line ) : return None else : time . sleep ( self . _WAIT_TIME )