parselglossy.validation_plumbing module#

Plumbing functions powering our validation facilities.

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.

Parameters
  • f (str) – Callable to checked as a string

  • d (JSONDict) – The input dict.

  • t (str) – Expected type.

Returns

retval – The error message, if any, and the result of the callable, if any.

Return type

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.

Parameters
  • predicate (str) –

  • where (str) –

  • user (JSONDict) –

Notes

We replace the convenience placeholder “value” with its full “address” in user.