From d1082aa3a1ec7d039b58eba994e32b79db778381 Mon Sep 17 00:00:00 2001 From: Richo Healey Date: Sun, 24 May 2015 05:41:38 -0700 Subject: [PATCH] etc: work around utf8 text in rust sources on py3 in featureck --- src/etc/featureck.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/etc/featureck.py b/src/etc/featureck.py index da140e9317d8..ecb2e6db466d 100644 --- a/src/etc/featureck.py +++ b/src/etc/featureck.py @@ -78,8 +78,15 @@ 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, 'r') as f: + with _open(path) as f: line_num = 0 for line in f: line_num += 1