parselglossy.validation module

Validation facilities.

parselglossy.validation.check_predicates(incoming: Dict[str, Any], *, predicates: Dict[str, Any]) → None[source]

Run predicates on input tree with fixed defaults.

Parameters:
  • incoming (JSONDict) – The input dict. This is supposed to be the result of fix_defaults().
  • predicates (JSONDict) – A view-by-predicates of the template dict.
Raises:

ParselglossyError

Notes

This is porcelain over recursive function rec_check_predicates().

parselglossy.validation.fix_defaults(incoming: Dict[str, Any], *, types: Dict[str, Any]) → Dict[str, Any][source]

Fixes defaults from a merge input dict.

Parameters:incoming (JSONDict) – The input dict. This is supposed to be the one obtained by merging user and template dict-s.
Returns:outgoing – A dictionary with all default values fixed.
Return type:JSONDict
Raises:ParselglossyError

Notes

This is porcelain over recursive function rec_fix_defaults().

parselglossy.validation.is_template_valid(template: Dict[str, Any]) → None[source]

Checks a template dict is well-formed.

Parameters:template (JSONDict) –
Raises:ParselglossyError

Notes

This is porcelain over the recursive rec_is_template_valid().

parselglossy.validation.merge_ours(*, theirs: Dict[str, Any], ours: Dict[str, Any]) → Dict[str, Any][source]

Recursively merge two dict-s with “ours” strategy.

Parameters:
  • theirs (JSONDict) –
  • ours (JSONDict) –
Returns:

outgoing

Return type:

JSONDict

Raises:

ParselglossyError

Notes

This is porcelain over the recursive function rec_merge_ours().

parselglossy.validation.validate_from_dicts(*, ir: Dict[str, Any], template: Dict[str, Any], fr_file: Union[str, pathlib.Path] = None) → Dict[str, Any][source]

Validate intermediate representation into final representation.

Parameters:
  • dumpir (bool) – Whether to serialize FR to JSON. Location and name of file are determined based on the input file.
  • ir (JSONDict) – Intermediate representation of the input file.
  • fr_file (Union[str, Path]) – File to write final representation to (JSON format). None by default, which means file is not written out.
Returns:

fr – The validated input.

Return type:

JSONDict

Raises:

ParselglossyError