]> git.lizzy.rs Git - rust.git/commitdiff
etc: use codecs in featureck
authorRicho Healey <richo@psych0tik.net>
Tue, 26 May 2015 19:09:28 +0000 (12:09 -0700)
committerRicho Healey <richo@psych0tik.net>
Tue, 26 May 2015 19:11:46 +0000 (12:11 -0700)
this asserts that source is valid utf8 on both python3 and python2

src/etc/featureck.py

index ecb2e6db466d1854bcf0891ad8ea66aa78412448..e82f00f3e7df53b3fd222c67ac7ffa73375fc529 100644 (file)
 #     since the same version
 #   * Prints information about features
 
-import sys, os, re
+import sys
+import os
+import re
+import codecs
 
 if len(sys.argv) < 2:
     print("usage: featureck.py <src-dir>")
@@ -78,15 +81,8 @@ for (dirpath, dirnames, filenames) in os.walk(src_dir):
         if not filename.endswith(".rs"):
             continue
 
-        if sys.version_info.major == 2:
-            _open = lambda f: open(f, 'r')
-        elif sys.version_info.major == 3:
-            _open = lambda f: open(f, 'r', encoding="utf-8")
-        else:
-            raise RuntimeError("Unsupported python version: %s" % (repr(sys.version_info)))
-
         path = os.path.join(dirpath, filename)
-        with _open(path) as f:
+        with codecs.open(filename=path, mode='r', encoding="utf-8") as f:
             line_num = 0
             for line in f:
                 line_num += 1