Exemple #1
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")
Exemple #2
0
def test_decode_santa_gap():
    content = "hohoho"
    result = varipacker.decode(content)
    assert result == b"\x00" * (511 * 3)
Exemple #3
0
def test_decode_gap_sextet_stream_octet_run_and_linear64():
    content = "034801noon10173j74WogZ3n"
    result = varipacker.decode(content)
    assert result == b"\x00\x00\x00\x00\x01\x3e\x3f\x3f\x3e\x01\x00" + b"\xfa" * 7 + b"\xff\x77\xaa\xfe"
Exemple #4
0
def test_decode_linear64_length4():
    content = "74WogZ3n"
    result = varipacker.decode(content)
    assert result == b"\xff\x77\xaa\xfe"
Exemple #5
0
def test_decode_gap():
    content = "09"
    result = varipacker.decode(content)
    assert result == b"\x00" * 9
Exemple #6
0
def test_decode_linear64_length2():
    content = "727og"
    result = varipacker.decode(content)
    assert result == b"\xff\x77"
Exemple #7
0
def test_decode_linear64_length3():
    content = "73WogZ"
    result = varipacker.decode(content)
    assert result == b"\xff\x77\xaa"
Exemple #8
0
def test_decode_sextet_stream_and_octet_run():
    content = "4801noon10173j"
    result = varipacker.decode(content)
    assert result == b"\x00\x01\x3e\x3f\x3f\x3e\x01\x00" + b"\xfa" * 7
Exemple #9
0
def test_decode_linear64_length1():
    content = "713o"
    result = varipacker.decode(content)
    assert result == b"\xff"
Exemple #10
0
def test_decode_sextet_and_triad_stream():
    content = "4801noon10388ng14801noon10378ng1"
    result = varipacker.decode(content)
    assert result == b"\x00\x01\x3e\x3f\x3f\x3e\x01\x00\x00\x01\x06\x07\x07\x06\x01\x00\x00\x01\x3e\x3f\x3f\x3e\x01\x00\x00\x01\x06\x07\x07\x06\x01"
Exemple #11
0
def test_decode_triad_stream_odd_length():
    content = "378ng1"
    result = varipacker.decode(content)
    assert result == b"\x00\x01\x06\x07\x07\x06\x01"
Exemple #12
0
def test_decode_triad_stream():
    content = "388ng1"
    result = varipacker.decode(content)
    assert result == b"\x00\x01\x06\x07\x07\x06\x01\x00"
Exemple #13
0
def test_decode_sextet_stream():
    content = "4801noon10"
    result = varipacker.decode(content)
    assert result == b"\x00\x01\x3e\x3f\x3f\x3e\x01\x00"
Exemple #14
0
def test_decode_nothing():
    content = varipacker.decode("")
    assert content == b""