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
45c4375e
Commit
45c4375e
authored
Jan 29, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #12004: Fix an internal error in PyZipFile when writing an invalid
Python file. Patch by Ben Morgan.
parent
a97c57c8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
2 deletions
+29
-2
Lib/test/test_zipfile.py
Lib/test/test_zipfile.py
+24
-1
Lib/zipfile.py
Lib/zipfile.py
+1
-1
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/test/test_zipfile.py
View file @
45c4375e
...
...
@@ -19,7 +19,8 @@ from tempfile import TemporaryFile
from
random
import
randint
,
random
from
unittest
import
skipUnless
from
test.support
import
TESTFN
,
run_unittest
,
findfile
,
unlink
from
test.support
import
(
TESTFN
,
run_unittest
,
findfile
,
unlink
,
captured_stdout
)
TESTFN2
=
TESTFN
+
"2"
TESTFNDIR
=
TESTFN
+
"d"
...
...
@@ -735,6 +736,28 @@ class PyZipFileTests(unittest.TestCase):
self
.
assertRaises
(
RuntimeError
,
zipfp
.
writepy
,
TESTFN
)
os
.
remove
(
TESTFN
)
def
test_write_pyfile_bad_syntax
(
self
):
os
.
mkdir
(
TESTFN2
)
try
:
with
open
(
os
.
path
.
join
(
TESTFN2
,
"mod1.py"
),
"w"
)
as
fp
:
fp
.
write
(
"Bad syntax in python file
\
n
"
)
with
TemporaryFile
()
as
t
,
zipfile
.
PyZipFile
(
t
,
"w"
)
as
zipfp
:
# syntax errors are printed to stdout
with
captured_stdout
()
as
s
:
zipfp
.
writepy
(
os
.
path
.
join
(
TESTFN2
,
"mod1.py"
))
self
.
assertIn
(
"SyntaxError"
,
s
.
getvalue
())
# as it will not have compiled the python file, it will
# include the .py file not .pyc or .pyo
names
=
zipfp
.
namelist
()
self
.
assertIn
(
'mod1.py'
,
names
)
self
.
assertNotIn
(
'mod1.pyc'
,
names
)
self
.
assertNotIn
(
'mod1.pyo'
,
names
)
finally
:
shutil
.
rmtree
(
TESTFN2
)
class
OtherTests
(
unittest
.
TestCase
):
zips_with_bad_crc
=
{
...
...
Lib/zipfile.py
View file @
45c4375e
...
...
@@ -1436,7 +1436,7 @@ class PyZipFile(ZipFile):
print
(
"Compiling"
,
file
)
try
:
py_compile
.
compile
(
file
,
doraise
=
True
,
optimize
=
optimize
)
except
py_compile
.
PyCompileError
as
err
or
:
except
py_compile
.
PyCompileError
as
err
:
print
(
err
.
msg
)
return
False
return
True
...
...
Misc/ACKS
View file @
45c4375e
...
...
@@ -741,6 +741,7 @@ The Dragon De Monsyne
Skip Montanaro
Paul Moore
Ross Moore
Ben Morgan
Derek Morr
James A Morrison
Alessandro Moura
...
...
Misc/NEWS
View file @
45c4375e
...
...
@@ -216,6 +216,9 @@ Core and Builtins
Library
-------
- Issue #12004: Fix an internal error in PyZipFile when writing an invalid
Python file. Patch by Ben Morgan.
- Issue #9290: In IDLE the sys.std* streams now implement io.TextIOBase
interface and support all mandatory methods and properties.
...
...
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