Christian Heimes <[email protected]> added the comment:
The __getattr__ hack is not needed. You can reset the flags in a different,
more straight forward way:
class ReproducibleZipInfo(ZipInfo):
__slots__ = ()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._reset_flags()
@classmethod
def from_file(cls, *args, **kwargs):
zinfo = super().from_file(*args, **kwargs)
zinfo._reset_flags()
return zinfo
def _reset_flags(self):
self.date_time = (1980, 0, 0, 0, 0, 0)
self.create_system = 0
self.external_attr = 0
>>> zinfo = ReproducibleZipInfo.from_file("/etc/os-release")
>>> zinfo.external_attr
0
>>> zinfo.create_system
0
>>> zinfo.date_time
(1980, 0, 0, 0, 0, 0)
I think it makes also sense to replace hard-coded ZipInfo class with dispatcher
attribute on the class:
@@ -1203,6 +1211,7 @@ class ZipFile:
fp = None # Set here since __del__ checks it
_windows_illegal_name_trans_table = None
+ zipinfo_class = ZipInfo
def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True,
compresslevel=None, *, strict_timestamps=True):
@@ -1362,7 +1371,7 @@ def _RealGetContents(self):
# Historical ZIP filename encoding
filename = filename.decode('cp437')
# Create ZipInfo instance to store file information
- x = ZipInfo(filename)
+ x = self.zipinfo_class(filename)
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue43547>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com