diff options
author | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-11-30 17:30:43 (GMT) |
---|---|---|
committer | Alexander Belopolsky <alexander.belopolsky@gmail.com> | 2010-11-30 17:30:43 (GMT) |
commit | 73f382de1cf6e7a0c31ac8fb7b50126b780d4e21 (patch) | |
tree | c19148e27c7efff9f8a613389654d6e15a69a1b3 /Tools/scripts | |
parent | ff2a4ba78ce724032808ebf3e4c006b831980e7d (diff) | |
download | cpython-73f382de1cf6e7a0c31ac8fb7b50126b780d4e21.zip cpython-73f382de1cf6e7a0c31ac8fb7b50126b780d4e21.tar.gz cpython-73f382de1cf6e7a0c31ac8fb7b50126b780d4e21.tar.bz2 |
Issue #9598: untabify.py will now respect encoding cookie in the files it processes
Diffstat (limited to 'Tools/scripts')
-rwxr-xr-x | Tools/scripts/untabify.py | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Tools/scripts/untabify.py b/Tools/scripts/untabify.py index ef63c41..4b67c15 100755 --- a/Tools/scripts/untabify.py +++ b/Tools/scripts/untabify.py @@ -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) |