jinjyaml.functions module¶
- jinjyaml.functions.extract(obj: Any, loader_type: Type[_Loader | _CLoader], env: jinja2.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
Datainstances.It may be:
A mapping or sequence object returned by PyYAML Loader.
In this case, the function does:
Recursively search inside
objforDataobjects.Render
Data.sourceas string source ofjinja2.Templateof each foundDataobject.Parse the rendered string with the PyYAML Loader who loads
obj.Return the whole
objwithDataobjects replaced with corresponding parsed Python object.
A single
Dataobject.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
objwith noting changed.
loader_type (Type[Union[_Loader, _CLoader]]) – The PyYAML Loader who loads
objenv (Optional[jinja2.Environment]) – Jinja2 environment for template rendering.
context (Optional[Mapping[str, Any]]) – Variables name-value pairs for Jinja2 template rendering.
inplace (bool) –
Whether to make an in-place replacement on
Dataobjects insideobj.When
True: In-place replace everyDataobject with corresponding parsed Python object inside the passed-inobj.When
False(default): render and parse everyDataobject with corresponding parsed Python object, without modify the passed-in object.
Note
When the passed-in
objargument is an instance ofData, it won’t be changed, eveninplacewas set toTrue. But if there was a mutabledictorlistlike object pared by YAML loader, which has cascadeDatain it, the cascade part would be replaced. However, return value is just the parsed result.
- Returns:
Final extracted Python object
- Return type:
Any