|
13 | 13 | import sys |
14 | 14 | import threading |
15 | 15 | import time |
| 16 | +from typing import Self |
16 | 17 |
|
17 | 18 | try: |
18 | 19 | import zlib # We may need its compression method |
@@ -605,17 +606,15 @@ def from_file(cls, filename, arcname=None, *, strict_timestamps=True): |
605 | 606 |
|
606 | 607 | return zinfo |
607 | 608 |
|
608 | | - @classmethod |
609 | | - def for_name(cls, filename, archive, *, date_time=None): |
610 | | - """Construct an appropriate ZipInfo from a filename and a ZipFile. |
| 609 | + def _for_archive(self, archive: ZipFile) -> Self: |
| 610 | + """Resolve suitable defaults from the archive. |
611 | 611 |
|
612 | | - The *filename* is expected to be the name of a file in the archive. |
| 612 | + Resolve the date_time, compression attributes, and external attributes |
| 613 | + to suitable defaults as used by :method:`ZipFile.writestr`. |
613 | 614 |
|
614 | | - If *date_time* is not specified, the current local time is used. |
| 615 | + Return self. |
615 | 616 | """ |
616 | | - if date_time is None: |
617 | | - date_time = time.localtime(time.time())[:6] |
618 | | - self = cls(filename=filename, date_time=date_time) |
| 617 | + self.date_time = time.localtime(time.time())[:6] |
619 | 618 | self.compress_type = archive.compression |
620 | 619 | self.compress_level = archive.compresslevel |
621 | 620 | if self.filename.endswith('/'): # pragma: no cover |
@@ -1931,7 +1930,7 @@ def writestr(self, zinfo_or_arcname, data, |
1931 | 1930 | if isinstance(zinfo_or_arcname, ZipInfo): |
1932 | 1931 | zinfo = zinfo_or_arcname |
1933 | 1932 | else: |
1934 | | - zinfo = ZipInfo.for_name(zinfo_or_arcname, self) |
| 1933 | + zinfo = ZipInfo(zinfo_or_arcname)._for_archive(self) |
1935 | 1934 |
|
1936 | 1935 | if not self.fp: |
1937 | 1936 | raise ValueError( |
|
0 commit comments