Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(8)  |  Call(6)  |  Derive(0)  |  Import(2)
Class with methods to open, read, write, close, list zip files.

z = ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=False)

file: Either the path to the file, or a file-like object.
      If it is a path, the file will be opened and closed by ZipFile.
mode: The mode can be either read "r", write "w" or append "a".
compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib).
allowZip64: if True ZipFile will create files with ZIP64 extensions when
            needed, otherwise it will raise an exception when this would(more...)

src/x/p/xpisign.py-HEAD/tests/test_context.py   xpisign.py(Download)
from zipfile import ZIP_DEFLATED as DEFLATED
 
from xpisign.compat import BytesIO, ZipFile
from xpisign.context import *
 
def test_ZipFileMinorCompression():
    """ZipFileMinorCompression has a (deterministic) effect."""
    with BytesIO() as bi:
        with ZipFile(bi, "w", DEFLATED) as zp:
            zp.writestr("test.txt", "sttesttesttesttest" * 10000)
        len1 = len(bi.getvalue())
    with BytesIO() as bi:
        with ZipFile(bi, "w", DEFLATED) as zp:
    assert len1 == len2
    with BytesIO() as bi:
        with ZipFile(bi, "w", DEFLATED) as zp:
            with ZipFileMinorCompression(zp):
                zp.writestr("test.txt", "sttesttesttesttest" * 10000)

src/x/p/xpisign.py-HEAD/tests/test_compat.py   xpisign.py(Download)
from tempfile import NamedTemporaryFile
 
from xpisign.compat import BytesIO, ZipFile
 
from helper import *
def test_ZipFile_read():
    """ZipFiles can be read."""
    with ZipFile(relfile("addon.xpi"), "r") as zp:
        assert zp.read("test.txt") == "testfile\n"
 
 
def test_ZipFile_write():
    """ZipFiles can be written."""
    with NamedTemporaryFile() as tmp:
        with ZipFile(tmp.name, "w") as zp:
        with ZipFile(tmp.name, "w") as zp:
            zp.writestr("test.txt", "testfile\n")
        with ZipFile(tmp.name, "r") as zp:
            assert zp.read("test.txt") == "testfile\n"