Beispiel #1
0
def test_zip_passwd():
    r = io.BytesIO()
    z = zipfile.ZipFile(r, "w")

    z.writestr("a.txt", "hello world")
    z.writestr("b.txt", "A" * 1024)

    value = zip_set_password(z, "password")
    z.close()

    z = zipfile.ZipFile(io.BytesIO(value))
    z.setpassword("password")
    assert z.read("a.txt") == "hello world"
    assert z.read("b.txt") == "A" * 1024
Beispiel #2
0
def test_zip_passwd():
    r = io.BytesIO()
    z = zipfile.ZipFile(r, "w")

    z.writestr("a.txt", "hello world")
    z.writestr("b.txt", "A"*1024)

    value = zip_set_password(z, "password")
    z.close()

    z = zipfile.ZipFile(io.BytesIO(value))
    z.setpassword("password")
    assert z.read("a.txt") == "hello world"
    assert z.read("b.txt") == "A"*1024
Beispiel #3
0
def zipify(f, password=None):
    """Turns any type of archive into an equivalent .zip file."""
    r = io.BytesIO()
    z = zipfile.ZipFile(r, "w")

    for child in f.children:
        z.writestr(child.relapath, child.contents)

    if password:
        ret = zip_set_password(z, password)
        z.close()
        return ret

    z.close()
    return r.getvalue()
Beispiel #4
0
def zipify(f, password=None):
    """Turns any type of archive into an equivalent .zip file."""
    r = io.BytesIO()
    z = zipfile.ZipFile(r, "w")

    for child in f.children:
        z.writestr(child.relapath, child.contents)

    if password:
        ret = zip_set_password(z, password)
        z.close()
        return ret

    z.close()
    return r.getvalue()
Beispiel #5
0
def zipify(f, password=None):
    """Turns any type of archive into an equivalent .zip file."""
    r = io.BytesIO()
    z = zipfile.ZipFile(r, "w")

    for child in f.children:
        filepath = child.temp_path()
        z.write(filepath, child.relapath)
        os.unlink(filepath)

    if password:
        ret = zip_set_password(z, password)
        z.close()
        return ret

    z.close()
    return r.getvalue()