diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-11-09 01:08:59 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-11-09 01:08:59 (GMT) |
commit | 58c0752a33253641c1423fac2d4ef3f623fbcb46 (patch) | |
tree | 2e2ada02342f78d3cc58a4fe23082818c4025b1b /Lib/trace.py | |
parent | ae4836df6d0ea92d778ef30bd37417d048fc37fc (diff) | |
download | cpython-58c0752a33253641c1423fac2d4ef3f623fbcb46.zip cpython-58c0752a33253641c1423fac2d4ef3f623fbcb46.tar.gz cpython-58c0752a33253641c1423fac2d4ef3f623fbcb46.tar.bz2 |
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.py | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/Lib/trace.py b/Lib/trace.py index 8ea4b89..b50aa02 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) |