diff options
author | Marcel Plch <mplch@redhat.com> | 2018-08-31 14:43:31 (GMT) |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2018-08-31 14:43:31 (GMT) |
commit | 77b112cd56a50232abcdbf28f9aba88dc5d33ad3 (patch) | |
tree | 29cc007270c33892d68a5b7dc3b5266e2fc85c2f /Lib | |
parent | 1b5f9c9653f348b0aa8b7ca39f8a9361150f7dfc (diff) | |
download | cpython-77b112cd56a50232abcdbf28f9aba88dc5d33ad3.zip cpython-77b112cd56a50232abcdbf28f9aba88dc5d33ad3.tar.gz cpython-77b112cd56a50232abcdbf28f9aba88dc5d33ad3.tar.bz2 |
bpo-34097: Polish API design (GH-8725)
Move strict_timestamps to constructor.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_zipfile.py | 8 | ||||
-rw-r--r-- | Lib/zipfile.py | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 68b56a0..4c6f57c 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -549,8 +549,8 @@ class StoredTestsWithSourceFile(AbstractTestsWithSourceFile, with zipfile.ZipFile(TESTFN2, "w") as zipfp: self.assertRaises(ValueError, zipfp.write, TESTFN) - with zipfile.ZipFile(TESTFN2, "w") as zipfp: - zipfp.write(TESTFN, strict_timestamps=False) + with zipfile.ZipFile(TESTFN2, "w", strict_timestamps=False) as zipfp: + zipfp.write(TESTFN) zinfo = zipfp.getinfo(TESTFN) self.assertEqual(zinfo.date_time, (1980, 1, 1, 0, 0, 0)) @@ -564,8 +564,8 @@ class StoredTestsWithSourceFile(AbstractTestsWithSourceFile, with zipfile.ZipFile(TESTFN2, "w") as zipfp: self.assertRaises(struct.error, zipfp.write, TESTFN) - with zipfile.ZipFile(TESTFN2, "w") as zipfp: - zipfp.write(TESTFN, strict_timestamps=False) + with zipfile.ZipFile(TESTFN2, "w", strict_timestamps=False) as zipfp: + zipfp.write(TESTFN) zinfo = zipfp.getinfo(TESTFN) self.assertEqual(zinfo.date_time, (2107, 12, 31, 23, 59, 59)) diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 6da1778..7f23778 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -1151,7 +1151,7 @@ class ZipFile: _windows_illegal_name_trans_table = None def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True, - compresslevel=None): + compresslevel=None, *, strict_timestamps=True): """Open the ZIP file with mode read 'r', write 'w', exclusive create 'x', or append 'a'.""" if mode not in ('r', 'w', 'x', 'a'): @@ -1169,6 +1169,7 @@ class ZipFile: self.mode = mode self.pwd = None self._comment = b'' + self._strict_timestamps = strict_timestamps # Check if we were passed a file-like object if isinstance(file, os.PathLike): @@ -1677,8 +1678,7 @@ class ZipFile: " would require ZIP64 extensions") def write(self, filename, arcname=None, - compress_type=None, compresslevel=None, *, - strict_timestamps=True): + compress_type=None, compresslevel=None): """Put the bytes from filename into the archive under the name arcname.""" if not self.fp: @@ -1690,7 +1690,7 @@ class ZipFile: ) zinfo = ZipInfo.from_file(filename, arcname, - strict_timestamps=strict_timestamps) + strict_timestamps=self._strict_timestamps) if zinfo.is_dir(): zinfo.compress_size = 0 |