mirror of
https://github.com/python/cpython.git
synced 2025-08-27 04:05:34 +00:00
Issue #10117: Tools/scripts/reindent.py now accepts source files that
use encoding other than ASCII or UTF-8. Source encoding is preserved when reindented code is written to a file.
This commit is contained in:
parent
016cec75bd
commit
4a98e3b6d0
3 changed files with 9 additions and 2 deletions
|
@ -109,8 +109,10 @@ def check(file):
|
|||
|
||||
if verbose:
|
||||
print("checking", file, "...", end=' ')
|
||||
with open(file, 'rb') as f:
|
||||
encoding, _ = tokenize.detect_encoding(f.readline)
|
||||
try:
|
||||
with open(file) as f:
|
||||
with open(file, encoding=encoding) as f:
|
||||
r = Reindenter(f)
|
||||
except IOError as msg:
|
||||
errprint("%s: I/O Error: %s" % (file, str(msg)))
|
||||
|
@ -127,7 +129,7 @@ def check(file):
|
|||
shutil.copyfile(file, bak)
|
||||
if verbose:
|
||||
print("backed up", file, "to", bak)
|
||||
with open(file, "w") as f:
|
||||
with open(file, "w", encoding=encoding) as f:
|
||||
r.write(f)
|
||||
if verbose:
|
||||
print("wrote new", file)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue