[issue12004] PyZipFile.writepy gives internal error on syntax errors

Ben Morgan report at bugs.python.org
Thu May 5 04:27:20 CEST 2011


New submission from Ben Morgan <benpmorgan at gmail.com>:

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

----------
files: test_zipfile_error.py
messages: 135170
nosy: Ben.Morgan
priority: normal
severity: normal
status: open
title: PyZipFile.writepy gives internal error on syntax errors
type: behavior
Added file: http://bugs.python.org/file21888/test_zipfile_error.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12004>
_______________________________________


More information about the Python-bugs-list mailing list