def test_api(self): raw_text = 'abc- "d" ""ef"" g' stream = StringStream(raw_text) assert stream.index == 0 assert stream.len == len(raw_text) buf = stream.read(1) assert_match(buf, "a") assert stream.index == 1 stream.seek(-1) assert stream.index == 0 buf = stream.advance_past_chars(['"']) buf = stream.advance_past_string_with_gdb_escapes() assert_match(buf, "d") buf = stream.advance_past_chars(['"']) buf = stream.advance_past_chars(['"']) buf = stream.advance_past_string_with_gdb_escapes() assert_match(buf, "ef") # read way past end to test it gracefully returns the # remainder of the string without failing buf = stream.read(50) assert_match(buf, '" g')
def _get_notify_msg_and_payload(result, stream: StringStream): """Get notify message and payload dict""" token = stream.advance_past_chars(["=", "*"]) token = int(token) if token != "" else None logger.debug("%s", fmt_green("parsing message")) message = stream.advance_past_chars([","]) logger.debug("parsed message") logger.debug("%s", fmt_green(message)) payload = _parse_dict(stream) return token, message.strip(), payload
def _get_result_msg_and_payload(result, stream: StringStream): """Get result message and payload dict""" match = _GDB_MI_RESULT_RE.match(result) assert match is not None groups = match.groups() token = int(groups[0]) if groups[0] != "" else None message = groups[1] if groups[2] is None: payload = None else: stream.advance_past_chars([","]) payload = _parse_dict(stream) return token, message, payload
def _get_notify_msg_and_payload(result, stream: StringStream): """Get notify message and payload dict""" match = _GDB_MI_NOTIFY_RE.match(result) assert match is not None groups = match.groups() token = int(groups[0]) if groups[0] != "" else None message = groups[1] logger.debug("parsed message") logger.debug("%s", fmt_green(message)) if groups[2] is None: payload = None else: stream.advance_past_chars([","]) payload = _parse_dict(stream) return token, message.strip(), payload
def _parse_key(stream: StringStream): """Parse key, value combination returns : Parsed key (string) """ logger.debug("parsing key") key = stream.advance_past_chars(["="]) logger.debug("parsed key:") logger.debug("%s", fmt_green(key)) return key