mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #20262: Warnings are raised now when duplicate names are added in the
ZIP file or too long ZIP file comment is truncated.
This commit is contained in:
commit
c46d1faa4a
3 changed files with 15 additions and 9 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue