[Python-checkins] r85695 - in python/branches/py3k: Lib/trace.py Misc/NEWS Tools/scripts/reindent.py

alexander.belopolsky python-checkins at python.org
Mon Oct 18 16:43:39 CEST 2010


Author: alexander.belopolsky
Date: Mon Oct 18 16:43:38 2010
New Revision: 85695

Log:
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.


Modified:
   python/branches/py3k/Lib/trace.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Tools/scripts/reindent.py

Modified: python/branches/py3k/Lib/trace.py
==============================================================================
--- python/branches/py3k/Lib/trace.py	(original)
+++ python/branches/py3k/Lib/trace.py	Mon Oct 18 16:43:38 2010
@@ -493,6 +493,7 @@
             threading.settrace(self.globaltrace)
             sys.settrace(self.globaltrace)
         try:
+            del sys.modules['pickle']
             exec(cmd, globals, locals)
         finally:
             if not self.donothing:

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Mon Oct 18 16:43:38 2010
@@ -111,6 +111,10 @@
 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

Modified: python/branches/py3k/Tools/scripts/reindent.py
==============================================================================
--- python/branches/py3k/Tools/scripts/reindent.py	(original)
+++ python/branches/py3k/Tools/scripts/reindent.py	Mon Oct 18 16:43:38 2010
@@ -109,8 +109,10 @@
 
     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 @@
                 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)


More information about the Python-checkins mailing list