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

roboto.domain.triggers.query_templates

Module Contents

QUERY_FIELD

roboto.domain.triggers.query_templates.QUERY_FIELD = 'query'#View Source

Selector field holding a RoboQL query, the one field of an invocation input whose value is an expression rather than a value the expression compares against.

QueryPlaceholder

class roboto.domain.triggers.query_templates.QueryPlaceholder#View Source

Bases: NamedTuple

One {{placeholder}} found in a RoboQL query, and the literal enclosing it.

Attributes

QueryPlaceholder.end

end int = 0 #

Index one past the placeholder’s last character.

QueryPlaceholder.name

name str #

The placeholder’s dotted name, without the braces.

QueryPlaceholder.quote

quote str | None = None #

The quote character of the string literal the placeholder sits in, or None when it sits in expression text (a comment counts as expression text: a value could close it).

QueryPlaceholder.start

start int = 0 #

Index of the placeholder’s first character in the query.

escape_string_literal()

roboto.domain.triggers.query_templates.escape_string_literal(value, quote)#View Source

Return value escaped for splicing inside a quote-delimited RoboQL string literal.

Parameters

value str

The value to splice.

quote str

The literal’s delimiter, " or '.

Raises

ValueError

value holds a character the literal cannot carry under any escape, namely a carriage return or a newline.

Return type

str

iter_query_templates()

roboto.domain.triggers.query_templates.iter_query_templates(invocation_input)#View Source

Yield every RoboQL query in invocation_input, in document order.

Parameters

invocation_input collections.abc.Mapping[str, Any]

Return type

collections.abc.Iterator[str]

map_query_templates()

roboto.domain.triggers.query_templates.map_query_templates(invocation_input, transform)#View Source

Return invocation_input with transform applied to every RoboQL query it holds.

Parameters

invocation_input collections.abc.Mapping[str, Any]

An InvocationInput in its JSON form, whose top-level values are selectors or lists of them.

transform collections.abc.Callable[[str], str]

Called with each selector’s query; its result replaces that query.

Returns

dict[str, Any]

A copy, shallow below the selectors it rewrites.

placeholders_outside_string_literals()

roboto.domain.triggers.query_templates.placeholders_outside_string_literals(query)#View Source

Return the placeholders in query that do not sit inside a string literal.

A value spliced inside a literal can be escaped into it (see escape_string_literal()), so it can only ever be data. A value spliced anywhere else becomes query syntax: a tag or path carrying an operator would rewrite the query it was meant to be compared against.

Parameters

query str

A RoboQL query, possibly carrying {{placeholder}} templates.

Returns

list[str]

The names of those placeholders, in the order they appear.

scan_placeholders()

roboto.domain.triggers.query_templates.scan_placeholders(query)#View Source

Return every {{placeholder}} in query, each with the literal enclosing it.

Follows the lexical rules of the RoboQL grammar: both quote characters open a string literal, a backslash inside one escapes the next character, and // and slash-star comments run to their terminator.

Parameters

query str

A RoboQL query, possibly carrying {{placeholder}} templates.

Return type

substitute_query_template()

roboto.domain.triggers.query_templates.substitute_query_template(query, resolve)#View Source

Return query with each placeholder replaced by resolve’s value for it, escaped in place.

Each placeholder is substituted exactly once, and a value is escaped for the literal that encloses it, so a value that itself looks like a template or carries a quote stays data.

Parameters

query str

A RoboQL query carrying {{placeholder}} templates.

resolve collections.abc.Callable[[str], str]

Returns the value for a placeholder name.

Raises

ValueError

A placeholder sits outside a string literal, or a value cannot be escaped into the literal it lands in.

Return type

str

Was this page helpful?