]> granicus.if.org Git - python/commitdiff
Issue #10117: Tools/scripts/reindent.py now accepts source files that
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>
Mon, 18 Oct 2010 14:43:38 +0000 (14:43 +0000)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>
Mon, 18 Oct 2010 14:43:38 +0000 (14:43 +0000)
use encoding other than ASCII or UTF-8.  Source encoding is preserved
when reindented code is written to a file.

Lib/trace.py
Misc/NEWS
Tools/scripts/reindent.py

index fa24fc1cc35ff96147a9fcacfb131191c9b8a340..eb21fde387b887c0101be2e878404ea020dc6745 100644 (file)
@@ -493,6 +493,7 @@ class Trace:
             threading.settrace(self.globaltrace)
             sys.settrace(self.globaltrace)
         try:
+            del sys.modules['pickle']
             exec(cmd, globals, locals)
         finally:
             if not self.donothing:
index 768702c164b26c0f6f7b294673dec4b42e10cb67..2f030c37895083d3c617157ed91970d1304e7ca3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -111,6 +111,10 @@ C-API
 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.
 
 Tests
index cff9a068224705e5cb79c993a35e8cb090b373e3..bb4152076b7584d6906b7c7322709b5b909a9f4e 100755 (executable)
@@ -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)