mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +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
|
@ -104,9 +104,7 @@ def compile(file, cfile=None, dfile=None, doraise=False):
|
|||
byte-compile all installed files (or all files in selected
|
||||
directories).
|
||||
"""
|
||||
with open(file, "rb") as f:
|
||||
encoding = tokenize.detect_encoding(f.readline)[0]
|
||||
with open(file, encoding=encoding) as f:
|
||||
with tokenize.open(file) as f:
|
||||
try:
|
||||
timestamp = int(os.fstat(f.fileno()).st_mtime)
|
||||
except AttributeError:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue