Issue #10335: Add tokenize.open(), detect the file encoding using

tokenize.detect_encoding() and open it in read only mode.
This commit is contained in:
Victor Stinner 2010-11-09 01:08:59 +00:00
parent ae4836df6d
commit 58c0752a33
8 changed files with 54 additions and 22 deletions

View file

@ -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)