code: def expect(self, prompt):
          
          while True:
              try:
                  result = self._expect(prompt)
              except DriverReplacedException:
                  continue  # retry
              return result
docs: Like waitfor(), but also removes the matched string from the buffer
          containing the incoming data. In other words, the following may not
          alway complete::
  
              conn.expect('myprompt>')
              conn.expect('myprompt>') # timeout
  
          Returns the index of the regular expression that matched.
  
          .. HINT::
              May raise the same exceptions as :class:`waitfor`.
  
          :type  prompt: str|re.RegexObject|list(str|re.RegexObject)
          :param prompt: One or more regular expressions.
          :rtype:  int, re.MatchObject
          :return: The index of the regular expression that matched,
            and the match object.