From: Zbigniew Jędrzejewski-Szmek Date: Thu, 3 Nov 2016 02:48:08 +0000 (-0400) Subject: parse_hwdb: add import fallback for python2 X-Git-Tag: v232~4^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1258f088981ac62efd846de91922eef033302e76;p=thirdparty%2Fsystemd.git parse_hwdb: add import fallback for python2 --- diff --git a/hwdb/parse_hwdb.py b/hwdb/parse_hwdb.py index 2540c8c2f63..5d4c5ea64df 100755 --- a/hwdb/parse_hwdb.py +++ b/hwdb/parse_hwdb.py @@ -49,6 +49,12 @@ except ImportError: ecodes = None print('WARNING: evdev is not available') +try: + from functools import lru_cache +except ImportError: + # don't do caching on old python + lru_cache = lambda: (lambda f: f) + EOL = LineEnd().suppress() EMPTYLINE = LineStart() + LineEnd() COMMENTLINE = pythonStyleComment + EOL @@ -62,7 +68,7 @@ TYPES = {'mouse': ('usb', 'bluetooth', 'ps2', '*'), 'keyboard': ('name', ), } -@functools.lru_cache() +@lru_cache() def hwdb_grammar(): ParserElement.setDefaultWhitespaceChars('') @@ -83,7 +89,7 @@ def hwdb_grammar(): return grammar -@functools.lru_cache() +@lru_cache() def property_grammar(): ParserElement.setDefaultWhitespaceChars(' ')