Plumbing functions powering our validation facilities.
parselglossy.validation_plumbing.
check_keyword
(keyword: Dict[str, Any], *, address: Tuple = ()) → List[parselglossy.exceptions.Error][source]¶Checks that a template keyword is well-formed.
In this function, a template keyword is well-formed if it has:
An allowed type.
A non-empty docstring.
The two additional criteria:
A default callable that is valid Python, if present.
Predicates that are valid Python, if present.
can only be checked meaningfully later, as they might depend on keyword(s)/section(s) of the input that are only known after merging.
template (JSONDict) –
address (Tuple) –
errors
List[Error]
parselglossy.validation_plumbing.
run_callable
(f: str, d: Dict[str, Any], *, t: str) → Tuple[str, Optional[Any]][source]¶Run a callable encoded as a string.
A callable is any function of the input tree.
f (str) – Callable to checked as a string
d (JSONDict) – The input dict.
t (str) – Expected type.
retval – The error message, if any, and the result of the callable, if any.
Tuple[str, Optional[Any]]
Notes
The input tree is called user
.
The callable is turned into a lambda function and executed using eval
,
to ensure that the syntax of callable actions is correct and that the
callable returns correctly.
We need to pass the full incoming
dictionary as argument to
eval
, because we allow indexing in the global dict
. That is,
since it is allowed to define defaults in a given section based on
defaults in other section we must be able to access the full input at
any point.
parselglossy.validation_plumbing.
run_predicate
(predicate: str, where: str, user: Dict[str, Any]) → Tuple[str, bool][source]¶Run a predicate to check whether it is satisfied.
predicate (str) –
where (str) –
user (JSONDict) –
Notes
We replace the convenience placeholder “value” with its full “address” in user
.