summaryrefslogtreecommitdiffstats
path: root/Lib/zipfile.py
diff options
context:
space:
mode:
authorMickaƫl Schoentgen <contact@tiger-222.fr>2019-09-09 13:08:54 (GMT)
committerDino Viehland <dinoviehland@gmail.com>2019-09-09 13:08:54 (GMT)
commit992347d7376765fe3f4fc958fb1be193ba21f6c3 (patch)
treea4f56bf20ede8f3e607ad1192980231e21fdaba5 /Lib/zipfile.py
parent1a8de82d3a30ecc7ed18a5ad51a0e17417ebfb89 (diff)
downloadcpython-992347d7376765fe3f4fc958fb1be193ba21f6c3.zip
cpython-992347d7376765fe3f4fc958fb1be193ba21f6c3.tar.gz
cpython-992347d7376765fe3f4fc958fb1be193ba21f6c3.tar.bz2
bpo-26185: Fix repr() on empty ZipInfo object (#13441)
* bpo-26185: Fix repr() on empty ZipInfo object It was failing on AttributeError due to inexistant but required attributes file_size and compress_size. They are now initialized to 0 in ZipInfo.__init__(). * Remove useless hasattr() in ZipInfo._open_to_write() * Completely remove file_size setting in _open_to_write().
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r--Lib/zipfile.py8
1 files changed, 3 insertions, 5 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index dfd0907..c2c5b6a 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -376,11 +376,11 @@ class ZipInfo (object):
self.volume = 0 # Volume number of file header
self.internal_attr = 0 # Internal attributes
self.external_attr = 0 # External file attributes
+ self.compress_size = 0 # Size of the compressed file
+ self.file_size = 0 # Size of the uncompressed file
# Other attributes are set by class ZipFile:
# header_offset Byte offset to the file header
# CRC CRC-32 of the uncompressed file
- # compress_size Size of the compressed file
- # file_size Size of the uncompressed file
def __repr__(self):
result = ['<%s filename=%r' % (self.__class__.__name__, self.filename)]
@@ -1564,9 +1564,7 @@ class ZipFile:
"another write handle open on it. "
"Close the first handle before opening another.")
- # Sizes and CRC are overwritten with correct data after processing the file
- if not hasattr(zinfo, 'file_size'):
- zinfo.file_size = 0
+ # Size and CRC are overwritten with correct data after processing the file
zinfo.compress_size = 0
zinfo.CRC = 0