Issue #9598: untabify.py will now respect encoding cookie in the files it processes
This commit is contained in:
parent
ff2a4ba78c
commit
73f382de1c
|
@ -5,7 +5,7 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import getopt
|
import getopt
|
||||||
|
import tokenize
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
tabsize = 8
|
tabsize = 8
|
||||||
|
@ -27,8 +27,9 @@ def main():
|
||||||
|
|
||||||
def process(filename, tabsize, verbose=True):
|
def process(filename, tabsize, verbose=True):
|
||||||
try:
|
try:
|
||||||
with open(filename) as f:
|
with tokenize.open(filename) as f:
|
||||||
text = f.read()
|
text = f.read()
|
||||||
|
encoding = f.encoding
|
||||||
except IOError as msg:
|
except IOError as msg:
|
||||||
print("%r: I/O error: %s" % (filename, msg))
|
print("%r: I/O error: %s" % (filename, msg))
|
||||||
return
|
return
|
||||||
|
@ -44,7 +45,7 @@ def process(filename, tabsize, verbose=True):
|
||||||
os.rename(filename, backup)
|
os.rename(filename, backup)
|
||||||
except os.error:
|
except os.error:
|
||||||
pass
|
pass
|
||||||
with open(filename, "w") as f:
|
with open(filename, "w", encoding=encoding) as f:
|
||||||
f.write(newtext)
|
f.write(newtext)
|
||||||
if verbose:
|
if verbose:
|
||||||
print(filename)
|
print(filename)
|
||||||
|
|
Loading…
Reference in New Issue