Commit 2b112e21 authored by Alexander Belopolsky's avatar Alexander Belopolsky

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

parent 03d9aba8
......@@ -5,7 +5,7 @@
import os
import sys
import getopt
import tokenize
def main():
tabsize = 8
......@@ -27,8 +27,9 @@ def main():
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 @@ def process(filename, tabsize, verbose=True):
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)
......
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