jinjyaml.functions module#
- jinjyaml.functions.extract(obj: Any, loader_type: TYamlLoaderTypes, env: Environment | None = None, context: Mapping[str, Any] | None = None, inplace: bool = False) Any #
Recursively render and parse template tag objects in a YAML doc-tree.
- Parameters:
obj (Any) –
Object like list or dictionary contains
Data
instances.It may be:
A mapping or sequence object returned by PyYAML Loader.
In this case, the function does:
Recursively search inside
obj
forData
objects.Render
Data.source
as string source ofjinja2.Template
of each foundData
object.Parse the rendered string with the PyYAML Loader who loads
obj
.Return the whole
obj
withData
objects replaced with corresponding parsed Python object.
A single
Data
object.In this case, the function does:
Render it’s
Data.source()
as string source ofjinja2.Template
.Parse the rendered string with the PyYAML Loader who loads
obj
.Return the parsed Python object.
Other scalar objects returned by a PyYAML Loader:
In this case, the function directly returns
obj
with noting changed.
loader_type (TYamlLoaderTypes) – The PyYAML Loader who loads
obj
env (Environment | None) – Jinja2 environment for template rendering.
context (Mapping[str, Any] | None) – Variables name-value pairs for Jinja2 template rendering.
inplace (bool) –
Whether to make an in-place replacement on
Data
objects insideobj
.When
True
: In-place replace everyData
object with corresponding parsed Python object inside the passed-inobj
.When
False
(default): render and parse everyData
object with corresponding parsed Python object, without modify the passed-in object.
Note
When the passed-in
obj
argument is an instance ofData
, it won’t be changed, eveninplace
was set toTrue
. But if there was a mutabledict
orlist
like object pared by YAML loader, which has cascadeData
in it, the cascade part would be replaced. However, return value is just the parsed result.
- Returns:
Final extracted Python object
- Return type: