def expect(self, searcher, timeout=<NUM_LIT:3>):
timeout = float(timeout)<EOL>end = time.time() + timeout<EOL>match = searcher.search(self._history[self._start:])<EOL>while not match:<EOL><INDENT>incoming = self._stream_adapter.poll(end - time.time())<EOL>self.input_callback(incoming)<EOL>self._history += incoming<EOL>match = searcher.search(self._history[self._start:])<EOL>trimlength = len(self._history) - self._window<EOL>if trimlength > <NUM_LIT:0>:<EOL><INDENT>self._start -= trimlength<EOL>self._history = self._history[trimlength:]<EOL><DEDENT><DEDENT>self._start += match.end<EOL>if (self._start < <NUM_LIT:0>):<EOL><INDENT>self._start = <NUM_LIT:0><EOL><DEDENT>return match<EOL>
Wait for input matching *searcher*.

        Waits for input matching *searcher* for up to *timeout* seconds. If
        a match is found, the match result is returned (the specific type of
        returned result depends on the :class:`Searcher` type). If no match is
        found within *timeout* seconds, raise an :class:`ExpectTimeout`
        exception.

        :param Searcher searcher: :class:`Searcher` to apply to underlying
            stream.
        :param float timeout: Timeout in seconds.