This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PyZipFile.writepy gives internal error on syntax errors
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: Ben.Morgan, alanmcintyre, eric.smith, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2011-05-05 02:27 by Ben.Morgan, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_zipfile_error.py Ben.Morgan, 2011-05-05 02:27 Test case
pyzipfile-error.patch Ben.Morgan, 2011-05-05 02:28 Patch
test-zipfile.patch Ben.Morgan, 2011-05-06 01:04 test_zipfile.py test case
Messages (10)
msg135170 - (view) Author: Ben Morgan (Ben.Morgan) * Date: 2011-05-05 02:27
PyZipFile.writepy gives internal error on syntax errors in files it processes.

For example, in the attached test case:
Traceback (most recent call last):
  File "C:\tfs\SDKS\python\Python32\lib\py_compile.py", line 119, in compile
    optimize=optimize)
  File "test_zipfile_error_bad_syntax.py", line 1
    syntax error
               ^
SyntaxError: invalid syntax

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\tfs\SDKS\python\Python32\lib\zipfile.py", line 1393, in _compile
    py_compile.compile(file, doraise=True, optimize=optimize)
  File "C:\tfs\SDKS\python\Python32\lib\py_compile.py", line 123, in compile
    raise py_exc
py_compile.PyCompileError:   File "test_zipfile_error_bad_syntax.py", line 1
    syntax error
               ^
SyntaxError: invalid syntax


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_zipfile_error.py", line 7, in <module>
    pzf.writepy(PYFILE)
  File "C:\tfs\SDKS\python\Python32\lib\zipfile.py", line 1376, in writepy
    fname, arcname = self._get_codename(pathname[0:-3], basename)
  File "C:\tfs\SDKS\python\Python32\lib\zipfile.py", line 1428, in _get_codename

    if _compile(file_py):
  File "C:\tfs\SDKS\python\Python32\lib\zipfile.py", line 1395, in _compile
    print(err.msg)
NameError: global name 'err' is not defined

Around zipfile.py:1395 
in PyZipFile._get_codename _compile
            try:
                py_compile.compile(file, doraise=True, optimize=optimize)
            except py_compile.PyCompileError as error:
                print(err.msg)
                return False

The print should be printing error.msg not err.msg
msg135254 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2011-05-06 00:08
Could you incorporate the test into Lib/test/test_zipfile?

Thanks!
msg135256 - (view) Author: Ben Morgan (Ben.Morgan) * Date: 2011-05-06 01:04
I've attached a patch to test_zipfile.py. I noticed that it writes out the error to stdout not stderr; I don't know if this is the desired behaviour.
msg176743 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-01 13:00
The patches look good to me, except that `self.assertIn('mod1.py', names)` can be used instead `self.assertTrue('mod1.py' in names)`.
msg178318 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-27 20:19
Ben Morgan, can you please submit a contributor form?

http://python.org/psf/contrib/contrib-form/
http://python.org/psf/contrib/
msg178639 - (view) Author: Ben Morgan (Ben.Morgan) * Date: 2012-12-31 02:44
Okay, I've emailed a contributor agreement.
msg179694 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-01-11 16:18
Ben, can you please resend your agreement?
msg179735 - (view) Author: Ben Morgan (Ben.Morgan) * Date: 2013-01-11 22:05
I've sent it again.
msg180921 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-01-29 18:22
New changeset 3a1ac42435f9 by Serhiy Storchaka in branch '3.2':
Issue #12004: Fix an internal error in PyZipFile when writing an invalid
http://hg.python.org/cpython/rev/3a1ac42435f9

New changeset 678320c7f63d by Serhiy Storchaka in branch '3.3':
Issue #12004: Fix an internal error in PyZipFile when writing an invalid
http://hg.python.org/cpython/rev/678320c7f63d

New changeset e24fd2c35d27 by Serhiy Storchaka in branch 'default':
Issue #12004: Fix an internal error in PyZipFile when writing an invalid
http://hg.python.org/cpython/rev/e24fd2c35d27
msg180923 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-01-29 18:28
Thank you for the patch.
History
Date User Action Args
2022-04-11 14:57:16adminsetgithub: 56213
2013-01-29 18:28:31serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg180923

stage: commit review -> resolved
2013-01-29 18:22:39python-devsetnosy: + python-dev
messages: + msg180921
2013-01-11 22:05:47Ben.Morgansetmessages: + msg179735
2013-01-11 16:18:17serhiy.storchakasetmessages: + msg179694
2012-12-31 02:44:04Ben.Morgansetmessages: + msg178639
2012-12-29 21:08:55serhiy.storchakasetassignee: serhiy.storchaka
2012-12-27 20:19:12serhiy.storchakasetmessages: + msg178318
2012-12-01 13:00:43serhiy.storchakasetversions: + Python 3.2, Python 3.3, Python 3.4
nosy: + alanmcintyre, serhiy.storchaka

messages: + msg176743

stage: commit review
2011-05-06 01:04:52Ben.Morgansetfiles: + test-zipfile.patch

messages: + msg135256
2011-05-06 00:08:06eric.smithsetnosy: + eric.smith
messages: + msg135254
components: + Library (Lib)
2011-05-05 02:28:06Ben.Morgansetfiles: + pyzipfile-error.patch
keywords: + patch
2011-05-05 02:27:20Ben.Morgancreate