From f644a6da7a6f11d20116842e2ce1c7e9c0b0ad64 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 30 Nov 2016 09:20:15 +0100 Subject: [PATCH 1/2] parse_hwdb: fix to work with pyparsing 2.1.10 pyparsing 2.1.10 fixed the handling of LineStart to really just apply to line starts and not ignore whitespace and comments any more. Adjust EMPTYLINE to this. Many thanks to Paul McGuire for pointing this out! --- hwdb/parse_hwdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hwdb/parse_hwdb.py b/hwdb/parse_hwdb.py index 5d4c5ea64d..5856d12af7 100755 --- a/hwdb/parse_hwdb.py +++ b/hwdb/parse_hwdb.py @@ -56,7 +56,7 @@ except ImportError: lru_cache = lambda: (lambda f: f) EOL = LineEnd().suppress() -EMPTYLINE = LineStart() + LineEnd() +EMPTYLINE = LineEnd() COMMENTLINE = pythonStyleComment + EOL INTEGER = Word(nums) REAL = Combine((INTEGER + Optional('.' + Optional(INTEGER))) ^ ('.' + INTEGER)) From aeceb3901a5c36154321be78993ed68d537fc9b4 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Thu, 24 Nov 2016 10:38:01 +0100 Subject: [PATCH 2/2] hwdb/parse_hwdb.py: open files with UTF-8 mode 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 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hwdb/parse_hwdb.py b/hwdb/parse_hwdb.py index 5856d12af7..d94d8d13d8 100755 --- a/hwdb/parse_hwdb.py +++ b/hwdb/parse_hwdb.py @@ -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 []