Fixes for $protkey protfunc implementation
This commit is contained in:
parent
cb5830bbc5
commit
4db1a1e2e0
2 changed files with 39 additions and 17 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue