summaryrefslogtreecommitdiffstats
path: root/Lib/zipfile.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-01-20 19:59:33 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-01-20 19:59:33 (GMT)
commitc46d1faa4a4b483f2b241bfbe932824d54f2f026 (patch)
tree0dd3bdb38e220d2cf15dcad1a139a4f7216192d6 /Lib/zipfile.py
parentab0ac27d24076a2a09e3d8de97055a2fc978709f (diff)
parent9b7a1a1af6de71411102e2b95ee3f654cb0cc700 (diff)
downloadcpython-c46d1faa4a4b483f2b241bfbe932824d54f2f026.zip
cpython-c46d1faa4a4b483f2b241bfbe932824d54f2f026.tar.gz
cpython-c46d1faa4a4b483f2b241bfbe932824d54f2f026.tar.bz2
Issue #20262: Warnings are raised now when duplicate names are added in the
ZIP file or too long ZIP file comment is truncated.
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r--Lib/zipfile.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index 12c1754..7b6bd5f 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -1104,10 +1104,10 @@ class ZipFile:
if not isinstance(comment, bytes):
raise TypeError("comment: expected bytes, got %s" % type(comment))
# check for valid comment length
- if len(comment) >= ZIP_MAX_COMMENT:
- if self.debug:
- print('Archive comment is too long; truncating to %d bytes'
- % ZIP_MAX_COMMENT)
+ if len(comment) > ZIP_MAX_COMMENT:
+ import warnings
+ warnings.warn('Archive comment is too long; truncating to %d bytes'
+ % ZIP_MAX_COMMENT, stacklevel=2)
comment = comment[:ZIP_MAX_COMMENT]
self._comment = comment
self._didModify = True
@@ -1296,8 +1296,8 @@ class ZipFile:
def _writecheck(self, zinfo):
"""Check for errors before writing a file to the archive."""
if zinfo.filename in self.NameToInfo:
- if self.debug: # Warning for duplicate names
- print("Duplicate name:", zinfo.filename)
+ import warnings
+ warnings.warn('Duplicate name: %r' % zinfo.filename, stacklevel=3)
if self.mode not in ("w", "a"):
raise RuntimeError('write() requires mode "w" or "a"')
if not self.fp: