summaryrefslogtreecommitdiff
path: root/Lib/trace.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-11-09 01:08:59 +0000
committerVictor Stinner <victor.stinner@haypocalc.com>2010-11-09 01:08:59 +0000
commit58c0752a33253641c1423fac2d4ef3f623fbcb46 (patch)
tree2e2ada02342f78d3cc58a4fe23082818c4025b1b /Lib/trace.py
parentae4836df6d0ea92d778ef30bd37417d048fc37fc (diff)
downloadcpython-git-58c0752a33253641c1423fac2d4ef3f623fbcb46.tar.gz
Issue #10335: Add tokenize.open(), detect the file encoding using
tokenize.detect_encoding() and open it in read only mode.
Diffstat (limited to 'Lib/trace.py')
-rw-r--r--Lib/trace.py5
1 files changed, 2 insertions, 3 deletions
diff --git a/Lib/trace.py b/Lib/trace.py
index 8ea4b898fb..b50aa02d0b 100644
--- a/Lib/trace.py
+++ b/Lib/trace.py
@@ -432,10 +432,9 @@ def find_strings(filename, encoding=None):
def find_executable_linenos(filename):
"""Return dict where keys are line numbers in the line number table."""
try:
- with io.FileIO(filename, 'r') as file:
- encoding, lines = tokenize.detect_encoding(file.readline)
- with open(filename, "r", encoding=encoding) as f:
+ with tokenize.open(filename) as f:
prog = f.read()
+ encoding = f.encoding
except IOError as err:
print(("Not printing coverage data for %r: %s"
% (filename, err)), file=sys.stderr)