Пример #1
0
def test_encode_long_sequence():
    """ encode byte sequence long enough for output to wrap """
    result = hextream.encode(bytes(range(0, 40)))
    assert result == (
        "00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F\n" +
        "10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F\n"+
        "20 21 22 23 24 25 26 27"
    )
Пример #2
0
def main():
    """ Program entry point """

    parser = argparse.ArgumentParser(
        description=
        "Strip comments and normalize whitespace for Hextream format content")
    parser.add_argument('infile',
                        nargs='?',
                        type=argparse.FileType('r', encoding="UTF-8"),
                        help="Name of file with content to be cleaned",
                        default=sys.stdin)
    parser.add_argument(
        'outfile',
        nargs='?',
        type=argparse.FileType('w', encoding="UTF-8"),
        help="Name of file in which to write the cleaned content",
        default=sys.stdout)
    args = parser.parse_args()

    hex_content = args.infile.read()
    binary_content = hextream.decode(hex_content)
    hex_content = hextream.encode(binary_content)
    args.outfile.write(hex_content)
Пример #3
0
def main():
    """ Program entry point """

    parser = argparse.ArgumentParser(
        description="Packs/unpacks Hextream content to/from the Varipacker format"
    )
    commands = parser.add_mutually_exclusive_group(required=True)
    commands.add_argument("-p", "--pack", action="store_true",
                          help="Pack Hextream content into Varipacker format")
    commands.add_argument("-u", "--unpack", action="store_true",
                          help="Unpack Varipacker content into Hextream format")
    parser.add_argument('infile', nargs='?', type=argparse.FileType('r', encoding="UTF-8"),
                        help="Name of file with content to be packed/unpacked",
                        default=sys.stdin)
    parser.add_argument('outfile', nargs='?', type=argparse.FileType('w', encoding="UTF-8"),
                        help="Name of file in which to write packed/unpacked content",
                        default=sys.stdout)
    parser.add_argument("-c", "--comment", type=str,
                        help="Prepend the output with specified comment string")
    parser.add_argument("-n", "--omit-newline", action="store_true",
                        help="The ending newline character(s) will be omitted from the output")
    args = parser.parse_args()

    source_content = args.infile.read()

    if args.pack:
        binary_content = hextream.decode(source_content)
        output_content = varipacker.encode(binary_content)
    else:
        binary_content = varipacker.decode(varipacker.distill(source_content))
        output_content = hextream.encode(binary_content)

    if args.comment:
        args.outfile.write("# {}\n".format(args.comment))
    args.outfile.write(output_content)
    if not args.omit_newline:
        args.outfile.write("\n")
Пример #4
0
def test_encode_single_byte():
    """ encode one byte sequence """
    result = hextream.encode(b"\xab")
    assert result == "AB"
Пример #5
0
def test_encode_empty():
    """ encode empty bytes sequence """
    result = hextream.encode(b"")
    assert result == ""
Пример #6
0
def test_encode_multiple_bytes():
    """ encode several byte sequence """
    result = hextream.encode(b"\xab\x01\x9a\xa9\xff")
    assert result == "AB 01 9A A9 FF"