[Python-checkins] r79250 - in python/branches/release31-maint: Lib/compileall.py Lib/test/test_compileall.py Misc/NEWS Tools/msi/msi.py

martin.v.loewis python-checkins at python.org
Sun Mar 21 23:02:42 CET 2010


Author: martin.v.loewis
Date: Sun Mar 21 23:02:42 2010
New Revision: 79250

Log:
Merged revisions 78991-78992,78994 via svnmerge from 
svn+ssh://pythondev@svn.python.org/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://pythondev@svn.python.org/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.
................


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Lib/compileall.py
   python/branches/release31-maint/Lib/test/test_compileall.py
   python/branches/release31-maint/Misc/NEWS
   python/branches/release31-maint/Tools/msi/msi.py

Modified: python/branches/release31-maint/Lib/compileall.py
==============================================================================
--- python/branches/release31-maint/Lib/compileall.py	(original)
+++ python/branches/release31-maint/Lib/compileall.py	Sun Mar 21 23:02:42 2010
@@ -77,7 +77,10 @@
                         print('*** Error compiling', fullname, '...')
                     else:
                         print('*** ', end='')
-                    print(err.msg)
+                    # escape non-printable characters in msg
+                    msg = err.msg.encode(sys.stdout.encoding, 'backslashreplace')
+                    msg = msg.decode(sys.stdout.encoding)
+                    print(msg)
                     success = 0
                 except (SyntaxError, UnicodeError, IOError) as e:
                     if quiet:

Modified: python/branches/release31-maint/Lib/test/test_compileall.py
==============================================================================
--- python/branches/release31-maint/Lib/test/test_compileall.py	(original)
+++ python/branches/release31-maint/Lib/test/test_compileall.py	Sun Mar 21 23:02:42 2010
@@ -1,3 +1,4 @@
+import sys
 import compileall
 import imp
 import os
@@ -9,6 +10,7 @@
 import time
 from test import support
 import unittest
+import io
 
 
 class CompileallTests(unittest.TestCase):
@@ -55,8 +57,30 @@
         self.recreation_check(b'\0\0\0\0')
 
 
+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():
-    support.run_unittest(CompileallTests)
+    support.run_unittest(CompileallTests,
+                         EncodingTest)
 
 
 if __name__ == "__main__":

Modified: python/branches/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS	(original)
+++ python/branches/release31-maint/Misc/NEWS	Sun Mar 21 23:02:42 2010
@@ -9,9 +9,17 @@
 
 *Release date: 20XX-XX-XX*
 
+Library
+-------
+
+- Issue #6716/2: Backslash-replace error output in compilall.
+
 Build
 -----
 
+- Issue #6716: Quote -x arguments of compileall in MSI installer.
+  Exclude 2to3 tests from compileall.
+
 - Issue #1628484: The Makefile doesn't ignore the CFLAGS environment
   variable anymore.  It also forwards the LDFLAGS settings to the linker
   when building a shared library.

Modified: python/branches/release31-maint/Tools/msi/msi.py
==============================================================================
--- python/branches/release31-maint/Tools/msi/msi.py	(original)
+++ python/branches/release31-maint/Tools/msi/msi.py	Sun Mar 21 23:02:42 2010
@@ -403,7 +403,7 @@
               ("VerdanaRed9", "Verdana", 9, 255, 0),
              ])
 
-    compileargs = r'-Wi "[TARGETDIR]Lib\compileall.py" -f -x bad_coding|badsyntax|site-packages|py2_ "[TARGETDIR]Lib"'
+    compileargs = r'-Wi "[TARGETDIR]Lib\compileall.py" -f -x "bad_coding|badsyntax|site-packages|py2_|lib2to3\\tests" "[TARGETDIR]Lib"'
     lib2to3args = r'-c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"'
     # See "CustomAction Table"
     add_data(db, "CustomAction", [


More information about the Python-checkins mailing list