def expect_regex(self, pattern):
<EOL>end_time = time.time() + self.timeout<EOL>buf = '<STR_LIT>'<EOL>prog = regex.compile(pattern)<EOL>while (end_time - time.time()) > <NUM_LIT:0.0>:<EOL><INDENT>reads, _, _ = select.select([self.fd], [], [], end_time - time.time())<EOL>if len(reads) > <NUM_LIT:0>:<EOL><INDENT>try:<EOL><INDENT>buf = remove_ansi_escape_sequences(buf + self.read())<EOL><DEDENT>except EOFError:<EOL><INDENT>assert prog.match(buf) is not None,'<STR_LIT>' % (buf, pattern)<EOL><DEDENT>if prog.match(buf):<EOL><INDENT>return True<EOL><DEDENT><DEDENT>else:<EOL><INDENT>time.sleep(self.timeout/<NUM_LIT:10>)<EOL><DEDENT><DEDENT>assert prog.match(buf) is not None,'<STR_LIT>' % (buf, pattern)<EOL>
Read until matches pattern or timeout.