Message389382
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) |
|
Date |
User |
Action |
Args |
2021-03-23 10:30:58 | christian.heimes | set | recipients:
+ christian.heimes, jondo, obfusk, eighthave |
2021-03-23 10:30:58 | christian.heimes | set | messageid: <1616495458.69.0.0110864034677.issue43547@roundup.psfhosted.org> |
2021-03-23 10:30:58 | christian.heimes | link | issue43547 messages |
2021-03-23 10:30:58 | christian.heimes | create | |
|