def expect_loop(self, searcher, timeout = -<NUM_LIT:1>, searchwindowsize = -<NUM_LIT:1>):
self.searcher = searcher<EOL>if timeout == -<NUM_LIT:1>:<EOL><INDENT>timeout = self.timeout<EOL><DEDENT>if timeout is not None:<EOL><INDENT>end_time = time.time() + timeout<EOL><DEDENT>if searchwindowsize == -<NUM_LIT:1>:<EOL><INDENT>searchwindowsize = self.searchwindowsize<EOL><DEDENT>try:<EOL><INDENT>incoming = self.buffer<EOL>freshlen = len(incoming)<EOL>while True: <EOL><INDENT>index = searcher.search(incoming, freshlen, searchwindowsize)<EOL>if index >= <NUM_LIT:0>:<EOL><INDENT>self.buffer = incoming[searcher.end : ]<EOL>self.before = incoming[ : searcher.start]<EOL>self.after = incoming[searcher.start : searcher.end]<EOL>self.match = searcher.match<EOL>self.match_index = index<EOL>return self.match_index<EOL><DEDENT>if timeout is not None and timeout < <NUM_LIT:0>:<EOL><INDENT>raise TIMEOUT ('<STR_LIT>')<EOL><DEDENT>c = self.read_nonblocking (self.maxread, timeout)<EOL>freshlen = len(c)<EOL>time.sleep (<NUM_LIT>)<EOL>incoming = incoming + c<EOL>if timeout is not None:<EOL><INDENT>timeout = end_time - time.time()<EOL><DEDENT><DEDENT><DEDENT>except EOF as e:<EOL><INDENT>self.buffer = self._empty_buffer<EOL>self.before = incoming<EOL>self.after = EOF<EOL>index = searcher.eof_index<EOL>if index >= <NUM_LIT:0>:<EOL><INDENT>self.match = EOF<EOL>self.match_index = index<EOL>return self.match_index<EOL><DEDENT>else:<EOL><INDENT>self.match = None<EOL>self.match_index = None<EOL>raise EOF (str(e) + '<STR_LIT:\n>' + str(self))<EOL><DEDENT><DEDENT>except TIMEOUT as e:<EOL><INDENT>self.buffer = incoming<EOL>self.before = incoming<EOL>self.after = TIMEOUT<EOL>index = searcher.timeout_index<EOL>if index >= <NUM_LIT:0>:<EOL><INDENT>self.match = TIMEOUT<EOL>self.match_index = index<EOL>return self.match_index<EOL><DEDENT>else:<EOL><INDENT>self.match = None<EOL>self.match_index = None<EOL>raise TIMEOUT (str(e) + '<STR_LIT:\n>' + str(self))<EOL><DEDENT><DEDENT>except:<EOL><INDENT>self.before = incoming<EOL>self.after = None<EOL>self.match = None<EOL>self.match_index = None<EOL>raise<EOL><DEDENT>
This is the common loop used inside expect. The 'searcher' should be
        an instance of searcher_re or searcher_string, which describes how and what
        to search for in the input.

        See expect() for other arguments, return value and exceptions.