예제 #1
0
def relay_definition_message():
    header = h.token('\xa5\xc0')
    any_char = h.ch_range('\x00', '\xff')

    parser = h.sequence(header, h.uint8(), h.uint8(), h.uint8(), h.uint8(),
                        h.many1(any_char))

    return parser
예제 #2
0
def init_parser():
    return h.sequence(
        h.many1(
            h.choice(relay_definition_message(),
                     fast_meter_configuration_block(), fast_meter_message(),
                     demand_fast_meter_configuration_block(),
                     peak_fast_meter_configuration_block(),
                     fast_message_block(), relay_operate_configuration())),
        h.end_p())
예제 #3
0
def init_parser():
    return h.sequence(
        h.many1(
            h.choice(
                #sampleEvents_parser,
                #pollingEngine_parser,
                #envelope_parser,
                #measurementDevice_parser,
                #sensors_parser,
                schemaVersion_parser())))
예제 #4
0
def fast_message_block():
    header = h.token('\xa5\x46')
    length = h.uint8()
    routing_address = h.repeat_n(h.uint8(), 5)
    status = h.uint8()
    function_code = h.uint8()
    sequence_byte = h.uint8()
    response_number = h.uint8()
    any_value = h.many1(h.ch_range('\x00', '\xff'))
    crc = h.uint16()

    parser = h.sequence(header, length, routing_address, status, function_code,
                        sequence_byte, response_number, any_value)

    return parser
예제 #5
0
def init_parser():
    return h.sequence(h.many1(h.choice(
        length_block(),
        connection_start_parser(),
        connection_start_ok_parser(),
        connection_tune_parser(),
        connection_tune_ok_parser(),
        connection_open_vhost_parser(),
        channel_open_parser(),
        channel_open_ok_parser(),
        queue_declare_parser(),
        queue_declare_ok_parser(),
        basic_consume_parser(),
        basic_consume_ok_parser(),
        basic_publish_parser(),
        basic_deliver_parser(),
        channel_close_parser(),
        channel_close_ok_parser(),
        connection_close_parser(),
        connection_close_ok_parser()
    )))
예제 #6
0

digit   = h.ch_range('0','9')
upper   = h.ch_range('A', 'Z')
lower   = h.ch_range('a', 'z')
chars   = h.choice(digit, upper, lower)

alphanumeric = h.many(chars)

words = h.sepBy1(alphanumeric, h.ch(' '))
version = h.token("Version")
allchars = h.ch_range("!", "~")

printable_chars = h.many(allchars)

token = h.many1(printable_chars)
tokens = h.sepBy1(printable_chars, h.choice(h.ch(' '), h.ch('\n'), h.ch('\r')))

# Action Modifiers

def tuple_string(t):
    new_coll = list()
    for c in t:
        if isinstance(c, tuple):
                new_coll.append("".join(c))
        else:
            return "".join(t)
    return tuple(new_coll)


# FastIron Parsers
예제 #7
0
 def setUpClass(cls):
     cls.parser = h.attr_bool(h.many1(h.choice(h.ch("a"), h.ch("b"))),
                              lambda x: x[0] == x[1])
예제 #8
0
 def setUpClass(cls):
     cls.parser = h.many1(h.choice(h.ch("a"), h.ch("b")))
예제 #9
0
 def setUpClass(cls):
     cls.parser = h.attr_bool(h.many1(h.choice(h.ch(b"a"), h.ch(b"b"))),
                              lambda x: x[0] == x[1])
예제 #10
0
 def setUpClass(cls):
     cls.parser = h.many1(h.choice(h.ch(b"a"), h.ch(b"b")))
예제 #11
0
import hammer as h

abcd = h.sequence(h.many1(h.uint8()), h.many(h.uint16()),
                  h.sequence(h.uint8()))
efgh = h.sequence(h.many1(h.uint8()), h.many(h.uint16()),
                  h.sequence(h.uint8()))