|
1 | | -""" mutable zip file """ |
| 1 | +"""mutable zip file""" |
| 2 | + |
2 | 3 | from __future__ import annotations |
3 | 4 |
|
4 | 5 | from os import PathLike |
@@ -28,9 +29,7 @@ def __init__( |
28 | 29 | compression: int = ZIP_STORED, |
29 | 30 | allowZip64: bool = False, |
30 | 31 | ): |
31 | | - super().__init__( |
32 | | - file, mode=mode, compression=compression, allowZip64=allowZip64 |
33 | | - ) |
| 32 | + super().__init__(file, mode=mode, compression=compression, allowZip64=allowZip64) |
34 | 33 | # track file to override in zip |
35 | 34 | self._replace = {} |
36 | 35 | # Whether the with statement was called |
@@ -83,9 +82,7 @@ def write( |
83 | 82 | # mark the entry, and create a temp-file for it |
84 | 83 | # we allow this only if the with statement is used |
85 | 84 | if self._allowUpdates and arcname in self.namelist(): |
86 | | - tempFile = self._replace[arcname] = self._replace.get( |
87 | | - arcname, TemporaryFile() |
88 | | - ) |
| 85 | + tempFile = self._replace[arcname] = self._replace.get(arcname, TemporaryFile()) |
89 | 86 | with open(filename, "rb") as source: |
90 | 87 | copyfileobj(source, tempFile) |
91 | 88 | # Behave normally |
@@ -119,13 +116,13 @@ def __exit__( |
119 | 116 | self._allowUpdates = False |
120 | 117 |
|
121 | 118 | def _closeAllTempFiles(self): |
122 | | - """close all temporary files""" |
| 119 | + """Close all temporary files""" |
123 | 120 | for tempFile in self._replace.values(): |
124 | 121 | if hasattr(tempFile, "close"): |
125 | 122 | tempFile.close() |
126 | 123 |
|
127 | 124 | def removeFile(self, path: str | PathLike[str]): |
128 | | - """flag a file with a delete marker""" |
| 125 | + """Flag a file with a delete marker""" |
129 | 126 | self._replace[path] = self.DeleteMarker() |
130 | 127 |
|
131 | 128 | def _rebuildZip(self): |
|
0 commit comments