]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hwdb/parse_hwdb.py: open files with UTF-8 mode 4772/head
authorMartin Pitt <martin.pitt@ubuntu.com>
Thu, 24 Nov 2016 09:38:01 +0000 (10:38 +0100)
committerMartin Pitt <martin.pitt@ubuntu.com>
Wed, 30 Nov 2016 08:25:09 +0000 (09:25 +0100)
pyparsing uses the system locale by default, which in the case of 'C' (in lots
of build environment) will fail with a UnicodeDecodeError. Explicitly open it
with UTF-8 encoding to guard against this.

hwdb/parse_hwdb.py

index 5856d12af7f84d482e94fa2bb07a9c6d1cd663a1..d94d8d13d8f70a4245f7c1a1d69100c08f6c81c5 100755 (executable)
@@ -133,7 +133,8 @@ def convert_properties(group):
 def parse(fname):
     grammar = hwdb_grammar()
     try:
-        parsed = grammar.parseFile(fname)
+        with open(fname, 'r', encoding='UTF-8') as f:
+            parsed = grammar.parseFile(f)
     except ParseBaseException as e:
         error('Cannot parse {}: {}', fname, e)
         return []