[tor-commits] [tor/maint-0.4.3] practracker: Read unicode files when using Python 2

nickm at torproject.org nickm at torproject.org
Thu Feb 20 15:45:01 UTC 2020


commit 57ff8d4a5323356a8d879caf8226c934f2e82260
Author: teor <teor at torproject.org>
Date:   Wed Feb 19 08:22:01 2020 +1000

    practracker: Read unicode files when using Python 2
    
    Allow the "practracker" coding best practices checking script to read
    unicode files, when using Python 2.
    
    We made the script use unicode literals in 0.4.3.1-alpha, but didn't
    change the codec for opening files.
    
    Fixes bug 33374; bugfix on 0.4.3.1-alpha.
---
 changes/bug33374                         |  5 +++++
 scripts/maint/practracker/practracker.py | 10 +++-------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/changes/bug33374 b/changes/bug33374
new file mode 100644
index 000000000..d1141faf7
--- /dev/null
+++ b/changes/bug33374
@@ -0,0 +1,5 @@
+  o Minor bugfixes (coding best practices checks):
+    - Allow the "practracker" coding best practices checking script to read
+      unicode files, when using Python 2. We made the script use unicode
+      literals in 0.4.3.1-alpha, but didn't change the codec for opening files.
+      Fixes bug 33374; bugfix on 0.4.3.1-alpha.
diff --git a/scripts/maint/practracker/practracker.py b/scripts/maint/practracker/practracker.py
index 6149fb79c..79b13cb05 100755
--- a/scripts/maint/practracker/practracker.py
+++ b/scripts/maint/practracker/practracker.py
@@ -24,7 +24,7 @@ from __future__ import division
 from __future__ import print_function
 from __future__ import unicode_literals
 
-import os, sys
+import codecs, os, sys
 
 import metrics
 import util
@@ -63,12 +63,8 @@ TOR_TOPDIR = None
 
 #######################################################
 
-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 open_file(fname):
+    return codecs.open(fname, 'r', encoding='utf-8')
 
 def consider_file_size(fname, f):
     """Consider the size of 'f' and yield an FileSizeItem for it.





More information about the tor-commits mailing list