Skip to content

Commit 96d7400

Browse files
committed
etc: use codecs in featureck
this asserts that source is valid utf8 on both python3 and python2
1 parent d1082aa commit 96d7400

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/etc/featureck.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
# since the same version
1919
# * Prints information about features
2020

21-
import sys, os, re
21+
import sys
22+
import os
23+
import re
24+
import codecs
2225

2326
if len(sys.argv) < 2:
2427
print("usage: featureck.py <src-dir>")
@@ -78,15 +81,8 @@
7881
if not filename.endswith(".rs"):
7982
continue
8083

81-
if sys.version_info.major == 2:
82-
_open = lambda f: open(f, 'r')
83-
elif sys.version_info.major == 3:
84-
_open = lambda f: open(f, 'r', encoding="utf-8")
85-
else:
86-
raise RuntimeError("Unsupported python version: %s" % (repr(sys.version_info)))
87-
8884
path = os.path.join(dirpath, filename)
89-
with _open(path) as f:
85+
with codecs.open(filename=path, mode='r', encoding="utf-8") as f:
9086
line_num = 0
9187
for line in f:
9288
line_num += 1

0 commit comments

Comments
 (0)