Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9b7a1a1a
Commit
9b7a1a1a
authored
Jan 20, 2014
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20262: Warnings are raised now when duplicate names are added in the
ZIP file or too long ZIP file comment is truncated.
parent
7e52705e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
8 deletions
+14
-8
Lib/test/test_zipfile.py
Lib/test/test_zipfile.py
+5
-2
Lib/zipfile.py
Lib/zipfile.py
+6
-6
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_zipfile.py
View file @
9b7a1a1a
...
...
@@ -844,7 +844,9 @@ class OtherTests(unittest.TestCase):
# Create the ZIP archive
with
zipfile
.
ZipFile
(
TESTFN2
,
"w"
,
zipfile
.
ZIP_STORED
)
as
zipfp
:
zipfp
.
writestr
(
"name"
,
"foo"
)
zipfp
.
writestr
(
"name"
,
"bar"
)
with
self
.
assertWarns
(
UserWarning
):
zipfp
.
writestr
(
"name"
,
"bar"
)
self
.
assertEqual
(
zipfp
.
namelist
(),
[
"name"
]
*
2
)
with
zipfile
.
ZipFile
(
TESTFN2
,
"r"
)
as
zipfp
:
infos
=
zipfp
.
infolist
()
...
...
@@ -1150,7 +1152,8 @@ class OtherTests(unittest.TestCase):
# check a comment that is too long is truncated
with
zipfile
.
ZipFile
(
TESTFN
,
mode
=
"w"
)
as
zipf
:
zipf
.
comment
=
comment2
+
b'oops'
with
self
.
assertWarns
(
UserWarning
):
zipf
.
comment
=
comment2
+
b'oops'
zipf
.
writestr
(
"foo.txt"
,
"O, for a Muse of Fire!"
)
with
zipfile
.
ZipFile
(
TESTFN
,
mode
=
"r"
)
as
zipfr
:
self
.
assertEqual
(
zipfr
.
comment
,
comment2
)
...
...
Lib/zipfile.py
View file @
9b7a1a1a
...
...
@@ -1102,10 +1102,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
:
i
f
self
.
debug
:
print
(
'Archive comment is too long; truncating to %d bytes'
%
ZIP_MAX_COMMENT
)
if
len
(
comment
)
>
ZIP_MAX_COMMENT
:
i
mport
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
...
...
@@ -1290,8 +1290,8 @@ class ZipFile:
def
_writecheck
(
self
,
zinfo
):
"""Check for errors before writing a file to the archive."""
if
zinfo
.
filename
in
self
.
NameToInfo
:
i
f
self
.
debug
:
# Warning for duplicate name
s
print
(
"Duplicate name:"
,
zinfo
.
filename
)
i
mport
warning
s
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
:
...
...
Misc/NEWS
View file @
9b7a1a1a
...
...
@@ -43,6 +43,9 @@ Core and Builtins
Library
-------
- Issue #20262: Warnings are raised now when duplicate names are added in the
ZIP file or too long ZIP file comment is truncated.
- Issue #18574: Added missing newline in 100-Continue reply from
http.server.BaseHTTPRequestHandler. Patch by Nikolaus Rath.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment