From 03a1553c81681c2489fb3a2c7028c04cf5da3bb9 Mon Sep 17 00:00:00 2001 From: Abhijeet Kasurde Date: Tue, 25 Jun 2024 20:48:04 -0700 Subject: [PATCH] zipfile: Support for extended_*time attributes zipinfo now supports attributes like extended_atime, extended_ctime, extended_mtime Signed-off-by: Abhijeet Kasurde --- Doc/library/zipfile.rst | 5 ++ Lib/test/test_zipfile/test_core.py | 51 +++++++++++++++++++ Lib/zipfile/__init__.py | 11 ++++ ...-06-25-20-53-57.gh-issue-121021.you8hf.rst | 1 + 4 files changed, 68 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2024-06-25-20-53-57.gh-issue-121021.you8hf.rst diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst index 5583c6b24be5c6f..ac7974176732c5f 100644 --- a/Doc/library/zipfile.rst +++ b/Doc/library/zipfile.rst @@ -890,6 +890,11 @@ Instances have the following methods and attributes: Size of the uncompressed file. +.. attribute:: ZipInfo.extended_mtime + + Extended modified timestamp of the uncompressed file. + + .. versionadded:: 3.14 .. _zipfile-commandline: .. program:: zipfile diff --git a/Lib/test/test_zipfile/test_core.py b/Lib/test/test_zipfile/test_core.py index 423974aada4ac1a..93da78b57ee07a8 100644 --- a/Lib/test/test_zipfile/test_core.py +++ b/Lib/test/test_zipfile/test_core.py @@ -1,5 +1,6 @@ import array import contextlib +import datetime import importlib.util import io import itertools @@ -1877,6 +1878,54 @@ def test_read_after_write_unicode_filenames(self): zipfp.writestr('приклад', b'sample') self.assertEqual(zipfp.read('приклад'), b'sample') + def create_zipfile_with_extended_timestamp_extra_data(self, filename, extra_timestamp_data): + with zipfile.ZipFile(TESTFN, mode='w') as zf: + filename_encoded = filename.encode("utf-8") + zip_info = zipfile.ZipInfo(filename) + + tag_for_extra_block = b'\x55\x54' + + # Set only modification time + flags = b'\x01' + + # modification time + if extra_timestamp_data is not None: + mtime = struct.pack('= 5: + try: + self.extended_mtime, = unpack("