def test_filter(): '''Smoke.''' filt = StreamFilter(re.compile(rb"\n\(gdb\) ")) assert (b"", None) == filt.filter(b" server nvim-gdb-breakpoint") assert (b"", None) == filt.filter(b"foo-bar") assert (b"", b' server nvim-gdb-breakpointfoo-bar\n(gdb) ') \ == filt.filter(b"\n(gdb) ")
def filter_command(self, command): tokens = re.split(r'\s+', command.decode('utf-8')) if tokens[0] == 'info-breakpoints': last_src = tokens[1] res = self.set_filter( StreamFilter(GdbProxy.PROMPT), lambda resp: self.process_info_breakpoints(last_src, resp)) return b'server info breakpoints' if res else b'' if tokens[0] == 'handle-command': cmd = b'server ' + command[len('handle-command '):] res = self.set_filter( StreamFilter(GdbProxy.PROMPT), lambda resp: self.process_handle_command(cmd, resp)) return cmd if res else b'' return command
def filter_command(self, command): # Map GDB commands to Pdb commands. tokens = re.split(r'\s+', command.decode('utf-8')) if tokens[0] == 'info-breakpoints': last_src = tokens[1] res = self.set_filter( StreamFilter(PdbProxy.PROMPT), lambda d: self.process_info_breakpoints(last_src, d)) return b'break' if res else b'' if tokens[0] == 'handle-command': cmd = command[len('handle-command '):] res = self.set_filter( StreamFilter(PdbProxy.PROMPT), lambda d: self.process_handle_command(cmd, d)) return cmd if res else b'' # Just pass the original command to highlight it isn't implemented. return command
def test_update_finish(): '''End matcher update.''' filt = StreamFilter(re.compile(b"\nXXXX ")) assert (b"", None) == filt.filter(b" server nvim-gdb-breakpoint") assert (b"", None) == filt.filter(b"foo-bar") filt.update_finish_matcher(re.compile(rb"\n\(gdb\) ")) assert (b"", b' server nvim-gdb-breakpointfoo-bar\n(gdb) ') \ == filt.filter(b"\n(gdb) ")
def filter_command(self, command): """Prepare a requested command for execution.""" tokens = re.split(r'\s+', command.decode('utf-8')) if tokens[0] == 'handle-command': cmd = b'server ' + command[len('handle-command '):] res = self.set_filter( StreamFilter(self.get_prompt()), lambda resp: self.process_handle_command(cmd, resp)) return cmd if res else b'' return command
def test_timeout(): '''Timeout.''' filt = StreamFilter(re.compile(b"qwer")) assert (b"", None) == filt.filter(b"asdf") assert (b"", None) == filt.filter(b"xyz") assert filt.timeout() == b"asdfxyz"