Fixes for $protkey protfunc implementation

This commit is contained in:
Griatch 2021-09-12 19:51:08 +02:00
parent cb5830bbc5
commit 4db1a1e2e0
2 changed files with 39 additions and 17 deletions

View file

@ -44,7 +44,22 @@ def protfunc_callable_protkey(*args, **kwargs):
return ""
prototype = kwargs.get("prototype", {})
prot_value = prototype[args[0]]
fieldname = args[0]
prot_value = None
if fieldname in prototype:
prot_value = prototype[fieldname]
else:
# check if it's an attribute
for attrtuple in prototype.get('attrs', []):
if attrtuple[0] == fieldname:
prot_value = attrtuple[1]
break
else:
raise AttributeError(f"{fieldname} not found in prototype\n{prototype}\n"
"(neither as prototype-field or as an Attribute")
if callable(prot_value):
raise RuntimeError(f"Error in prototype\n{prototype}\n$protkey can only reference static "
f"values/attributes (found {prot_value})")
try:
return funcparser.funcparser_callable_eval(prot_value, **kwargs)
except funcparser.ParsingError: