Skip to content

Commit 73f382d

Browse files
committed
Issue python#9598: untabify.py will now respect encoding cookie in the files it processes
1 parent ff2a4ba commit 73f382d

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

Tools/scripts/untabify.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import sys
77
import getopt
8-
8+
import tokenize
99

1010
def main():
1111
tabsize = 8
@@ -27,8 +27,9 @@ def main():
2727

2828
def process(filename, tabsize, verbose=True):
2929
try:
30-
with open(filename) as f:
30+
with tokenize.open(filename) as f:
3131
text = f.read()
32+
encoding = f.encoding
3233
except IOError as msg:
3334
print("%r: I/O error: %s" % (filename, msg))
3435
return
@@ -44,7 +45,7 @@ def process(filename, tabsize, verbose=True):
4445
os.rename(filename, backup)
4546
except os.error:
4647
pass
47-
with open(filename, "w") as f:
48+
with open(filename, "w", encoding=encoding) as f:
4849
f.write(newtext)
4950
if verbose:
5051
print(filename)

0 commit comments

Comments
 (0)