mirror of
https://github.com/python/cpython.git
synced 2025-09-09 02:11:51 +00:00
Issue #6716/2: Backslash-replace error output in compilall.
This commit is contained in:
parent
09c86afb1e
commit
4b00307425
3 changed files with 31 additions and 2 deletions
|
@ -104,7 +104,10 @@ def compile_file(fullname, ddir=None, force=0, rx=None, quiet=0):
|
||||||
print('*** Error compiling', fullname, '...')
|
print('*** Error compiling', fullname, '...')
|
||||||
else:
|
else:
|
||||||
print('*** ', end='')
|
print('*** ', end='')
|
||||||
print(err.msg)
|
# escape non-printable characters in msg
|
||||||
|
msg = err.msg.encode(sys.stdout.encoding, errors='backslashreplace')
|
||||||
|
msg = msg.decode(sys.stdout.encoding)
|
||||||
|
print(msg)
|
||||||
success = 0
|
success = 0
|
||||||
except (SyntaxError, UnicodeError, IOError) as e:
|
except (SyntaxError, UnicodeError, IOError) as e:
|
||||||
if quiet:
|
if quiet:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import sys
|
||||||
import compileall
|
import compileall
|
||||||
import imp
|
import imp
|
||||||
import os
|
import os
|
||||||
|
@ -7,6 +8,7 @@ import struct
|
||||||
import tempfile
|
import tempfile
|
||||||
from test import support
|
from test import support
|
||||||
import unittest
|
import unittest
|
||||||
|
import io
|
||||||
|
|
||||||
|
|
||||||
class CompileallTests(unittest.TestCase):
|
class CompileallTests(unittest.TestCase):
|
||||||
|
@ -72,8 +74,30 @@ class CompileallTests(unittest.TestCase):
|
||||||
os.unlink(self.bc_path)
|
os.unlink(self.bc_path)
|
||||||
os.unlink(self.bc_path2)
|
os.unlink(self.bc_path2)
|
||||||
|
|
||||||
|
class EncodingTest(unittest.TestCase):
|
||||||
|
'Issue 6716: compileall should escape source code when printing errors to stdout.'
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.directory = tempfile.mkdtemp()
|
||||||
|
self.source_path = os.path.join(self.directory, '_test.py')
|
||||||
|
with open(self.source_path, 'w', encoding='utf-8') as file:
|
||||||
|
file.write('# -*- coding: utf-8 -*-\n')
|
||||||
|
file.write('print u"\u20ac"\n')
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
shutil.rmtree(self.directory)
|
||||||
|
|
||||||
|
def test_error(self):
|
||||||
|
try:
|
||||||
|
orig_stdout = sys.stdout
|
||||||
|
sys.stdout = io.TextIOWrapper(io.BytesIO(),encoding='ascii')
|
||||||
|
compileall.compile_dir(self.directory)
|
||||||
|
finally:
|
||||||
|
sys.stdout = orig_stdout
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
support.run_unittest(CompileallTests)
|
support.run_unittest(CompileallTests,
|
||||||
|
EncodingTest)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -283,6 +283,8 @@ C-API
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #6716/2: Backslash-replace error output in compilall.
|
||||||
|
|
||||||
- Issue #4961: Inconsistent/wrong result of askyesno function in tkMessageBox
|
- Issue #4961: Inconsistent/wrong result of askyesno function in tkMessageBox
|
||||||
with Tcl/Tk-8.5.
|
with Tcl/Tk-8.5.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue