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
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
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()
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()