diff options
author | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-10-18 14:43:38 (GMT) |
---|---|---|
committer | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-10-18 14:43:38 (GMT) |
commit | 4a98e3b6d06e5477e5d62f18e85056cbb7253f98 (patch) | |
tree | 0f2f3cc2fd70be8ef4930dbeb01fadf7034bc76e /Tools/scripts/reindent.py | |
parent | 016cec75bd43b29240370f81319ceccdab5cc771 (diff) | |
download | cpython-4a98e3b6d06e5477e5d62f18e85056cbb7253f98.zip cpython-4a98e3b6d06e5477e5d62f18e85056cbb7253f98.tar.gz cpython-4a98e3b6d06e5477e5d62f18e85056cbb7253f98.tar.bz2 |
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.
Diffstat (limited to 'Tools/scripts/reindent.py')
-rwxr-xr-x | Tools/scripts/reindent.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Tools/scripts/reindent.py b/Tools/scripts/reindent.py index cff9a06..bb41520 100755 --- a/Tools/scripts/reindent.py +++ b/Tools/scripts/reindent.py @@ -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) |