mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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:
parent
ae4836df6d
commit
58c0752a33
8 changed files with 54 additions and 22 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue