Commit 40af53d1 authored by Alexander Belopolsky's avatar Alexander Belopolsky

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.
parent f261d2c7
...@@ -493,6 +493,7 @@ class Trace: ...@@ -493,6 +493,7 @@ class Trace:
threading.settrace(self.globaltrace) threading.settrace(self.globaltrace)
sys.settrace(self.globaltrace) sys.settrace(self.globaltrace)
try: try:
del sys.modules['pickle']
exec(cmd, globals, locals) exec(cmd, globals, locals)
finally: finally:
if not self.donothing: if not self.donothing:
......
...@@ -111,6 +111,10 @@ C-API ...@@ -111,6 +111,10 @@ C-API
Tools/Demos Tools/Demos
----------- -----------
- 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.
- Issue #7287: Demo/imputil/knee.py was removed. - Issue #7287: Demo/imputil/knee.py was removed.
Tests Tests
......
...@@ -109,8 +109,10 @@ def check(file): ...@@ -109,8 +109,10 @@ def check(file):
if verbose: if verbose:
print("checking", file, "...", end=' ') print("checking", file, "...", end=' ')
with open(file, 'rb') as f:
encoding, _ = tokenize.detect_encoding(f.readline)
try: try:
with open(file) as f: with open(file, encoding=encoding) as f:
r = Reindenter(f) r = Reindenter(f)
except IOError as msg: except IOError as msg:
errprint("%s: I/O Error: %s" % (file, str(msg))) errprint("%s: I/O Error: %s" % (file, str(msg)))
...@@ -127,7 +129,7 @@ def check(file): ...@@ -127,7 +129,7 @@ def check(file):
shutil.copyfile(file, bak) shutil.copyfile(file, bak)
if verbose: if verbose:
print("backed up", file, "to", bak) print("backed up", file, "to", bak)
with open(file, "w") as f: with open(file, "w", encoding=encoding) as f:
r.write(f) r.write(f)
if verbose: if verbose:
print("wrote new", file) print("wrote new", file)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment