diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-08-28 16:25:15 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-08-28 16:25:54 -0400 |
commit | b4b8fa4899fcde9983f66a6310878ea47186e5eb (patch) | |
tree | 4e5b5ba1cc0220ba2255c63904fc91170be72fc9 /scripts | |
parent | 6da8c6e9a544922c3e04ac460ca7fcbdc8a6eaf3 (diff) | |
download | tor-b4b8fa4899fcde9983f66a6310878ea47186e5eb.tar.gz tor-b4b8fa4899fcde9983f66a6310878ea47186e5eb.zip |
Set the file encoding in checkIncludes.py with Python3
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/maint/checkIncludes.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/scripts/maint/checkIncludes.py b/scripts/maint/checkIncludes.py index d13ff565cb..46a3f39638 100755 --- a/scripts/maint/checkIncludes.py +++ b/scripts/maint/checkIncludes.py @@ -26,6 +26,13 @@ import sys # Global: Have there been any errors? trouble = False +if sys.version_info[0] <= 2: + def open_file(fname): + return open(fname, 'r') +else: + def open_file(fname): + return open(fname, 'r', encoding='utf-8') + def err(msg): """ Declare that an error has happened, and remember that there has been an error. """ @@ -70,7 +77,7 @@ class Rules(object): include, lineno, context)) def applyToFile(self, fname): - with open(fname, 'r') as f: + with open_file(fname) as f: #print(fname) self.applyToLines(iter(f), " of {}".format(fname)) @@ -82,7 +89,7 @@ class Rules(object): def load_include_rules(fname): """ Read a rules file from 'fname', and return it as a Rules object. """ result = Rules(os.path.split(fname)[0]) - with open(fname, 'r') as f: + with open_file(fname) as f: for line in f: line = line.strip() if line.startswith("#") or not line: |