示例#1
0
def test_hexify():
    h = hexify.Hexify(16).hexify(b'\xAB\xCD', 0xBEAF)
    assert next(h) == header1
    assert next(h) == header2
    assert next(
        h
    ) == '0000BEAF 00000000 AB CD                                           |..|\n'
示例#2
0
def test_hexify_multiline_data():
    h = hexify.Hexify(16).hexify_data(range(17), 0xC0DE)
    assert next(
        h
    ) == '0000C0DE 00000000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F |................|\n'
    assert next(
        h
    ) == '0000C0EE 00000010 10                                              |.|\n'
示例#3
0
async def transfer_logger(conn_n, from_writer_stream, to_writer_stream, queue):
    to_writer_info = format_peer_info(to_writer_stream)
    from_writer_info = format_peer_info(from_writer_stream)

    thread_id = threading.get_ident()

    now = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
    log_name = f"log-{now}-{conn_n:04}.{thread_id}-{from_writer_info}-{to_writer_info}.log"

    hexifier = hexify.Hexify(16)

    with open(log_name, 'w') as log:
        async for msg in queue:
            if isinstance(msg, str):
                log.write(msg)
                log.write('\n')
            elif isinstance(msg, list):
                bytes, offset = msg
                log.writelines(hexifier.hexify(bytes, offset))
示例#4
0
def test_constructor_parameters():
    h = hexify.Hexify(16)
    assert h.width == 16
    assert len(h.padding_legend) == len(h.padding_separator)
    assert isinstance(h.printables, list)
    assert len(h.printables) == 256
示例#5
0
def test_printable():
    h = hexify.Hexify(16)
    assert h.printable(0) == '.'
    assert h.printable(32) == ' '
    assert h.printable(255) == '.'
示例#6
0
def test_hexify_data():
    h = hexify.Hexify(16).hexify_data(b'*\xAB\xCD', 0x80001234)
    assert next(
        h
    ) == '80001234 00000000 2A AB CD                                        |*..|\n'
示例#7
0
def test_hexify_empty_data():
    h = hexify.Hexify(16).hexify_data("", -1)
    with pytest.raises(StopIteration):
        assert next(h)
示例#8
0
def test_header():
    h = hexify.Hexify(16).header()
    assert next(h) == header1
    assert next(h) == header2