Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e96ac3a

Browse files
committed
Merged revisions 78991-78992,78994 via svnmerge from
svn+ssh://[email protected]/python/branches/py3k ................ r78991 | martin.v.loewis | 2010-03-16 12:03:13 +0100 (Di, 16 Mär 2010) | 9 lines Merged revisions 78976 via svnmerge from svn+ssh://[email protected]/python/trunk ........ r78976 | martin.v.loewis | 2010-03-15 14:00:17 +0100 (Mo, 15 Mär 2010) | 1 line Issue #6716: Quote -x arguments of compileall in MSI installer. ........ ................ r78992 | martin.v.loewis | 2010-03-16 14:19:21 +0100 (Di, 16 Mär 2010) | 2 lines Issue #6716/2: Backslash-replace error output in compilall. ................ r78994 | martin.v.loewis | 2010-03-16 17:19:47 +0100 (Di, 16 Mär 2010) | 1 line Issue #6716/3: Exclude 2to3 tests from compileall. ................
1 parent 1d6af70 commit e96ac3a

4 files changed

Lines changed: 38 additions & 3 deletions

File tree

Lib/compileall.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ def compile_dir(dir, maxlevels=10, ddir=None,
7777
print('*** Error compiling', fullname, '...')
7878
else:
7979
print('*** ', end='')
80-
print(err.msg)
80+
# escape non-printable characters in msg
81+
msg = err.msg.encode(sys.stdout.encoding, 'backslashreplace')
82+
msg = msg.decode(sys.stdout.encoding)
83+
print(msg)
8184
success = 0
8285
except (SyntaxError, UnicodeError, IOError) as e:
8386
if quiet:

Lib/test/test_compileall.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import compileall
23
import imp
34
import os
@@ -9,6 +10,7 @@
910
import time
1011
from test import support
1112
import unittest
13+
import io
1214

1315

1416
class CompileallTests(unittest.TestCase):
@@ -55,8 +57,30 @@ def test_magic_number(self):
5557
self.recreation_check(b'\0\0\0\0')
5658

5759

60+
class EncodingTest(unittest.TestCase):
61+
'Issue 6716: compileall should escape source code when printing errors to stdout.'
62+
63+
def setUp(self):
64+
self.directory = tempfile.mkdtemp()
65+
self.source_path = os.path.join(self.directory, '_test.py')
66+
with open(self.source_path, 'w', encoding='utf-8') as file:
67+
file.write('# -*- coding: utf-8 -*-\n')
68+
file.write('print u"\u20ac"\n')
69+
70+
def tearDown(self):
71+
shutil.rmtree(self.directory)
72+
73+
def test_error(self):
74+
try:
75+
orig_stdout = sys.stdout
76+
sys.stdout = io.TextIOWrapper(io.BytesIO(),encoding='ascii')
77+
compileall.compile_dir(self.directory)
78+
finally:
79+
sys.stdout = orig_stdout
80+
5881
def test_main():
59-
support.run_unittest(CompileallTests)
82+
support.run_unittest(CompileallTests,
83+
EncodingTest)
6084

6185

6286
if __name__ == "__main__":

Misc/NEWS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@ What's New in Python 3.1.3?
99

1010
*Release date: 20XX-XX-XX*
1111

12+
Library
13+
-------
14+
15+
- Issue #6716/2: Backslash-replace error output in compilall.
16+
1217
Build
1318
-----
1419

20+
- Issue #6716: Quote -x arguments of compileall in MSI installer.
21+
Exclude 2to3 tests from compileall.
22+
1523
- Issue #1628484: The Makefile doesn't ignore the CFLAGS environment
1624
variable anymore. It also forwards the LDFLAGS settings to the linker
1725
when building a shared library.

Tools/msi/msi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def add_ui(db):
403403
("VerdanaRed9", "Verdana", 9, 255, 0),
404404
])
405405

406-
compileargs = r'-Wi "[TARGETDIR]Lib\compileall.py" -f -x bad_coding|badsyntax|site-packages|py2_ "[TARGETDIR]Lib"'
406+
compileargs = r'-Wi "[TARGETDIR]Lib\compileall.py" -f -x "bad_coding|badsyntax|site-packages|py2_|lib2to3\\tests" "[TARGETDIR]Lib"'
407407
lib2to3args = r'-c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"'
408408
# See "CustomAction Table"
409409
add_data(db, "CustomAction", [

0 commit comments

Comments
 (0)