예제 #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
예제 #2
0
파일: test_misc.py 프로젝트: jbremer/sflock
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
예제 #3
0
파일: main.py 프로젝트: BuloZB/sflock
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()
예제 #4
0
파일: main.py 프로젝트: jbremer/sflock
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()
예제 #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()