prance.util.path

This module contains code for accessing values in nested data structures.

Functions

prance.util.path.path_get(obj, path, defaultvalue=None, path_of_obj=())[source]

Retrieve the value from obj indicated by path.

Like dict.get(), except:

  • Any Mapping or Sequence is supported.

  • Path is itself a Sequence; the first part is applied to the passed object, the second part to the value returned from this operation, and so forth recursively.

Parameters
  • obj (mixed) – The Sequence or Mapping from which to retrieve values.

  • path (Sequence) – A Sequence of zero or more key/index elements.

  • defaultvalue (mixed) – If the value at the path does not exist and this parameter is not None, it is returned. Otherwise an error is raised.

prance.util.path.path_set(obj, path, value, **options)[source]

Set the value in obj indicated by path.

Setter anologous to path_get() above.

As setting values is a write operation, this function optionally creates intermediate objects to ensure all elements of path can be dereferenced.

Parameters
  • obj (mixed) – The Sequence or Mapping from which to retrieve values.

  • path (Sequence) – A Sequence of zero or more key/index elements.

  • value (mixed) – The value to set.

  • create (bool) – [optional] Flag indicating whether to create intermediate values or not. Defaults to False.