Beispiel #1
0
def decode(article: Article, raw_data: List[bytes]) -> bytes:
    # Let SABYenc do all the heavy lifting
    decoded_data, yenc_filename, crc, crc_expected, crc_correct = sabyenc3.decode_usenet_chunks(
        raw_data, article.bytes)

    # Mark as decoded
    article.decoded = True

    # Assume it is yenc
    article.nzf.type = "yenc"

    # Only set the name if it was found and not obfuscated
    if not article.nzf.filename_checked and yenc_filename:
        # Set the md5-of-16k if this is the first article
        if article.lowest_partnum:
            article.nzf.md5of16k = hashlib.md5(decoded_data[:16384]).digest()

        # Try the rename, even if it's not the first article
        # For example when the first article was missing
        article.nzf.nzo.verify_nzf_filename(article.nzf, yenc_filename)

    # CRC check
    if not crc_correct:
        raise CrcError(crc_expected, crc, decoded_data)

    return decoded_data
Beispiel #2
0
###################
# Real test
###################

nr_runs = 500
chunk_size = 14

# Read some data (can pick any of the files from the yencfiles folder)
with open("tests/yencfiles/test_regular.txt", "rb") as yencfile:
    data_raw = yencfile.read()
    data_bytes = len(data_raw)
    n = 2 ** chunk_size
    data_chunks = [data_raw[i : i + n] for i in range(0, len(data_raw), n)]

###################
# YENC C - NEW
###################

# Time it!
time1_new = time.clock()

for i in range(nr_runs):
    decoded_data_new, output_filename, crc, crc_yenc, crc_correct = sabyenc3.decode_usenet_chunks(
        data_chunks, data_bytes
    )

print("---")
time1_new_disp = 1000 * (time.clock() - time1_new)
print("%15s  took  %4d ms" % ("yEnc C New", time1_new_disp))
print("---")
Beispiel #3
0
def sabyenc3_wrapper(data_chunks):
    """CRC's are"""
    decoded_data, filename, crc_correct = sabyenc3.decode_usenet_chunks(data_chunks)
    return decoded_data, correct_unknown_encoding(filename), crc_correct
Beispiel #4
0
for fname in all_crc_fails:
    # Open file
    print("\n\n ======================================= \n\n")
    print(fname)
    data_p = open(fname, "r")
    try:
        data_chunks, data_size, lines = pickle.load(data_p)
    except:
        data_p.seek(0)
        data_chunks, data_size = pickle.load(data_p)
    data_p.close()
    """
    First we check SABYenc
    """
    output_buffer, output_filename, crc, crc_yenc, crc_correct = sabyenc3.decode_usenet_chunks(
        data_chunks, data_size)
    print("\n---- SABYenc output ----\n")
    print("Filename:", output_filename)
    print("Size:", len(output_buffer))
    print("NZB size:", data_size)
    print("CRC Calc:", crc)
    print("CRC Yenc:", crc_yenc)
    print("CRC Bool:", crc_correct)
    """
    Validate using _yenc
    """
    data = []
    new_lines = "".join(data_chunks).split("\r\n")
    for i in range(len(new_lines)):
        if new_lines[i][:2] == "..":
            new_lines[i] = new_lines[i][1:]
Beispiel #5
0
def test_list_dict():
    with pytest.raises(TypeError) as excinfo:
        sabyenc3.decode_usenet_chunks({1: "yenc"})
    assert "Expected list" in str(excinfo.value)
Beispiel #6
0
def test_list_str():
    with pytest.raises(TypeError) as excinfo:
        sabyenc3.decode_usenet_chunks("baddata")
    assert "Expected list" in str(excinfo.value)
def test_size_dict():
    with pytest.raises(TypeError) as excinfo:
        sabyenc3.decode_usenet_chunks(["yenc1", "yenc2"], {1: "yenc"})
    assert "integer" in str(excinfo.value)