aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-11-07 15:47:36 +0000
committerVictor Stinner <victor.stinner@haypocalc.com>2010-11-07 15:47:36 +0000
commit64bc3b28a321b6026488f689fb125f31766d9730 (patch)
tree698be941679bae7bcdc6a6059ad27bbd9314f33f /Lib/trace.py
parentos module: remove nonbreaking space in a comment (diff)
downloadcpython-64bc3b28a321b6026488f689fb125f31766d9730.tar.gz
cpython-64bc3b28a321b6026488f689fb125f31766d9730.tar.bz2
cpython-64bc3b28a321b6026488f689fb125f31766d9730.zip
Issue #10329: The trace module writes reports using the input Python script
encoding, instead of the locale encoding. Patch written by Alexander Belopolsky.
Diffstat (limited to 'Lib/trace.py')
-rw-r--r--Lib/trace.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/Lib/trace.py b/Lib/trace.py
index b24d193d358..d460cf29fb6 100644
--- a/Lib/trace.py
+++ b/Lib/trace.py
@@ -330,9 +330,10 @@ class CoverageResults:
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 @@ class CoverageResults:
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)