Ejemplo n.º 1
0
    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')
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
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