Skip to content
Roboto
Esc
↑↓navigate↵open⌘Jpreview
On this page

roboto.templating.substitution

Module Contents

MappingResolver

class roboto.templating.substitution.MappingResolver(values)#View Source

A VariableResolver backed by a flat name -> value mapping.

Values are coerced to str on access; a missing key or a None value resolves to None (leaving the placeholder unexpanded).

Parameters

values Mapping[str, Any]

MappingResolver.resolve()

resolve(name)#View Source

Parameters

name str

Return type

Optional[str]

PLACEHOLDER_RE

roboto.templating.substitution.PLACEHOLDER_RE#View Source

Recognizes {{name}} placeholders. Names start with a letter or underscore; dots are allowed so dotted names ({{dataset.id}}, {{action.name}}) work as a namespace convention for entity-bound expansion by a VariableResolver. The engine treats the full dotted string as one opaque key — the resolver decides what, if anything, it expands to.

VARIABLE_NAME_RE

roboto.templating.substitution.VARIABLE_NAME_RE#View Source

Mirrors PLACEHOLDER_RE so every declared variable name is referenceable by {{name}}.

VariableResolver

class roboto.templating.substitution.VariableResolver#View Source

Bases: Protocol

Decides what each {{name}} placeholder expands to during substitution.

Implementations bind placeholders to a source of values — a flat mapping for agent launch, or a lazily-hydrated event namespace for triggers — keeping the substitution engine itself agnostic to where values come from.

VariableResolver.resolve()

resolve(name)#View Source

Return the substitution string for placeholder name, or None.

Parameters

name str

The placeholder name written between {{ and }}, dots included (e.g. dataset.id).

Returns

Optional[str]

The string to splice in, or None to leave the literal {{name}} in place.

collect_placeholders()

roboto.templating.substitution.collect_placeholders(node)#View Source

Return every {{name}} placeholder found in the string leaves of node.

node is the JSON form of a template (nested dicts, lists, scalars). Only string values are scanned; placeholder syntax in dict keys is rejected so a templated key can’t silently collapse two entries into one.

Parameters

node Any

Raises

ValueError

A dict key contains {{...}} placeholder syntax.

Return type

set[str]

substitute()

roboto.templating.substitution.substitute(node, resolver)#View Source

Return a copy of node with each {{name}} in a string leaf expanded via resolver.

Embedded and repeated placeholders within one string are supported. A name the resolver returns None for is left as the literal {{name}}; callers that require full resolution validate the placeholder set up front with collect_placeholders().

Parameters

node Any

Return type

Any

Was this page helpful?