bpo-34097: Add support for zipping files older than 1980-01-01 (GH-8270)

ZipFile can zip files older than 1980-01-01 and newer than 2107-12-31 using
a new strict_timestamps parameter at the cost of setting the timestamp
to the limit.
This commit is contained in:
Marcel Plch 2018-08-02 15:04:52 +02:00 committed by Victor Stinner
parent fc512e3e06
commit a2fe1e52eb
4 changed files with 48 additions and 5 deletions

View file

@ -549,6 +549,22 @@ 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)
zinfo = zipfp.getinfo(TESTFN)
self.assertEqual(zinfo.date_time, (1980, 1, 1, 0, 0, 0))
def test_add_file_after_2107(self):
# Set atime and mtime to 2108-12-30
os.utime(TESTFN, (4386268800, 4386268800))
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)
zinfo = zipfp.getinfo(TESTFN)
self.assertEqual(zinfo.date_time, (2107, 12, 31, 23, 59, 59))
@requires_zlib
class DeflateTestsWithSourceFile(AbstractTestsWithSourceFile,