diff --git a/checkbox-ng/plainbox/impl/new_resource.py b/checkbox-ng/plainbox/impl/new_resource.py index f0c851a82..c64997746 100644 --- a/checkbox-ng/plainbox/impl/new_resource.py +++ b/checkbox-ng/plainbox/impl/new_resource.py @@ -219,11 +219,25 @@ def __str__(self): legacy_getters = {} if sys.version_info[0] == 3 and sys.version_info[1] < 8: - # older version of python have + from collections import namedtuple + + # older version of python have slightly different nodes to parse + # constants. Here we wrap them for forward compatibility putting the old + # attribute where the ConstantGetter expects to find it + Wrapper = namedtuple("Wrapper", ["value"]) + + def wrapping(attr): + def _f(parsed_ast): + wrapped_parsed_ast = Wrapper(getattr(parsed_ast, attr)) + return ConstantGetter(wrapped_parsed_ast) + + return _f + legacy_getters = { - ast.Str: ConstantGetter, - ast.Num: ConstantGetter, - ast.Bytes: ConstantGetter, + ast.Str: wrapping("s"), + ast.Num: wrapping("n"), + ast.Bytes: wrapping("s"), + # this actually uses .value ast.NameConstant: ConstantGetter, }