[Python-checkins] r86893 - python/branches/py3k/Tools/scripts/untabify.py

alexander.belopolsky python-checkins at python.org
Tue Nov 30 18:30:43 CET 2010


Author: alexander.belopolsky
Date: Tue Nov 30 18:30:43 2010
New Revision: 86893

Log:
Issue #9598: untabify.py will now respect encoding cookie in the files it processes

Modified:
   python/branches/py3k/Tools/scripts/untabify.py

Modified: python/branches/py3k/Tools/scripts/untabify.py
==============================================================================
--- python/branches/py3k/Tools/scripts/untabify.py	(original)
+++ python/branches/py3k/Tools/scripts/untabify.py	Tue Nov 30 18:30:43 2010
@@ -5,7 +5,7 @@
 import os
 import sys
 import getopt
-
+import tokenize
 
 def main():
     tabsize = 8
@@ -27,8 +27,9 @@
 
 def process(filename, tabsize, verbose=True):
     try:
-        with open(filename) as f:
+        with tokenize.open(filename) as f:
             text = f.read()
+            encoding = f.encoding
     except IOError as msg:
         print("%r: I/O error: %s" % (filename, msg))
         return
@@ -44,7 +45,7 @@
         os.rename(filename, backup)
     except os.error:
         pass
-    with open(filename, "w") as f:
+    with open(filename, "w", encoding=encoding) as f:
         f.write(newtext)
     if verbose:
         print(filename)


More information about the Python-checkins mailing list