[Python-checkins] r86303 - in python/branches/py3k: Lib/trace.py Misc/NEWS

victor.stinner python-checkins at python.org
Sun Nov 7 16:47:36 CET 2010


Author: victor.stinner
Date: Sun Nov  7 16:47:36 2010
New Revision: 86303

Log:
Issue #10329: The trace module writes reports using the input Python script
encoding, instead of the locale encoding. Patch written by Alexander
Belopolsky.


Modified:
   python/branches/py3k/Lib/trace.py
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Lib/trace.py
==============================================================================
--- python/branches/py3k/Lib/trace.py	(original)
+++ python/branches/py3k/Lib/trace.py	Sun Nov  7 16:47:36 2010
@@ -330,9 +330,10 @@
 
             source = linecache.getlines(filename)
             coverpath = os.path.join(dir, modulename + ".cover")
+            with open(filename, 'rb') as fp:
+                encoding, _ = tokenize.detect_encoding(fp.readline)
             n_hits, n_lines = self.write_results_file(coverpath, source,
-                                                      lnotab, count)
-
+                                                      lnotab, count, encoding)
             if summary and n_lines:
                 percent = int(100 * n_hits / n_lines)
                 sums[modulename] = n_lines, percent, modulename, filename
@@ -351,11 +352,11 @@
             except IOError as err:
                 print("Can't save counts files because %s" % err, file=sys.stderr)
 
-    def write_results_file(self, path, lines, lnotab, lines_hit):
+    def write_results_file(self, path, lines, lnotab, lines_hit, encoding=None):
         """Return a coverage results file in path."""
 
         try:
-            outfile = open(path, "w")
+            outfile = open(path, "w", encoding=encoding)
         except IOError as err:
             print(("trace: Could not open %r for writing: %s"
                                   "- skipping" % (path, err)), file=sys.stderr)

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Sun Nov  7 16:47:36 2010
@@ -65,6 +65,10 @@
 Library
 -------
 
+- Issue #10329: The trace module writes reports using the input Python script
+  encoding, instead of the locale encoding. Patch written by Alexander
+  Belopolsky.
+
 - Issue #10126: Fix distutils' test_build when Python was built with
   --enable-shared.
 


More information about the Python-checkins mailing list