ds_common_placeholder_py_lib.resolve

File: resolve.py Region: ds-common-placeholder-py-lib

Description

Walks a JSON value and resolves every placeholder (contract §8.1, §8.2).

Attributes

READ_DEPTH_MAX

How many context values can be read inside one another, each through a

Paths

paths, each a dotted string

Path

a dotted string (tasks.0.settings.'a.b') or a list

SECRET_PART_MIN

The shortest string in a function's result over a secret that is

Functions

pointer(path, key) → str

Append key to a JSON Pointer.

context_pointer(namespace, path) → str

The JSON Pointer of a value in the context: /<namespace>/<path…>.

is_verbatim(at, verbatim) → bool

Whether the value at the pointer at is, or is inside, a verbatim path.

verbatim_pointers(paths) → frozenset[str]

The JSON Pointers of the verbatim paths a caller passed.

path_keys(path) → tuple[str, ...]

The keys of path, array indexes as strings.

as_written(value) → Any

A verbatim value: a copy, with plain dict and list containers

parse_at(text, path) → list[ds_common_placeholder_py_lib.grammar.Segment]

parse() with path set on any error.

check_key(key, path) → Any

Reject a placeholder in an object key (contract §3).

is_missing(value) → bool

None and empty or blank strings are missing (contract §8.2).

as_text(value) → str

Render a value inside a longer string (contract §8.1).

json_text(value) → str

value as compact JSON text, non-ASCII escaped: lookup's json

check_arity(call, spec) → None

Check the argument count of a registered function.

check_params(call, spec, values) → None

Run each parameter's own check on its argument's value, a reference's

check_lazy_literals(call) → None

For coalesce: a literal must be last and not blank. A blank one is

Module Contents

ds_common_placeholder_py_lib.resolve.pointer(path: str, key: str | int) → str[source]

Append key to a JSON Pointer.

ds_common_placeholder_py_lib.resolve.context_pointer(namespace: str, path: tuple[str, ...]) → str[source]

The JSON Pointer of a value in the context: /<namespace>/<path…>.

ds_common_placeholder_py_lib.resolve.is_verbatim(at: str, verbatim: frozenset[str]) → bool[source]

Whether the value at the pointer at is, or is inside, a verbatim path.

ds_common_placeholder_py_lib.resolve.READ_DEPTH_MAX = 64

How many context values can be read inside one another, each through a placeholder the one before it holds.

ds_common_placeholder_py_lib.resolve.Paths

paths, each a dotted string (tasks.0.settings.'a.b') or a list of keys (["tasks", 0, "a.b"]).

Type:

The verbatim argument

ds_common_placeholder_py_lib.resolve.verbatim_pointers(paths: Paths) → frozenset[str][source]

The JSON Pointers of the verbatim paths a caller passed.

Raises:
  • TypeError – If paths is a single string, or a path is neither a string nor a list of keys.

  • ValueError – If a string path is not a path, or a list of keys is empty.

ds_common_placeholder_py_lib.resolve.Path

a dotted string (tasks.0.settings.'a.b') or a list of keys (["tasks", 0, "a.b"]).

Type:

A path to a value

ds_common_placeholder_py_lib.resolve.path_keys(path: Path) → tuple[str, ...][source]

The keys of path, array indexes as strings.

Raises:
  • TypeError – If path is neither a string nor a list of keys.

  • ValueError – If a string is not a path, or a list of keys is empty.

ds_common_placeholder_py_lib.resolve.as_written(value: Any) → Any[source]

A verbatim value: a copy, with plain dict and list containers as the rest of a resolved value has.

ds_common_placeholder_py_lib.resolve.parse_at(text: str, path: str) → list[ds_common_placeholder_py_lib.grammar.Segment][source]

parse() with path set on any error.

ds_common_placeholder_py_lib.resolve.check_key(key: Any, path: str) → Any[source]

Reject a placeholder in an object key (contract §3).

Returns:

The key.

Raises:

PlaceholderError – syntax.

ds_common_placeholder_py_lib.resolve.is_missing(value: Any) → bool[source]

None and empty or blank strings are missing (contract §8.2).

ds_common_placeholder_py_lib.resolve.as_text(value: Any) → str[source]

Render a value inside a longer string (contract §8.1).

Raises:

PlaceholderError – type for an object, array, or non-JSON value.

ds_common_placeholder_py_lib.resolve.json_text(value: Any) → str[source]

value as compact JSON text, non-ASCII escaped: lookup’s json format. A DataFrame, at any depth, is its rows, as dataframe_to_json_array gives them.

Raises:

PlaceholderError – type if the value, or a value in it, is not JSON.

ds_common_placeholder_py_lib.resolve.SECRET_PART_MIN = 6

The shortest string in a function’s result over a secret that is recorded as a secret.

ds_common_placeholder_py_lib.resolve.check_arity(call: ds_common_placeholder_py_lib.grammar.Call, spec: ds_common_placeholder_py_lib.functions.FunctionSpec) → None[source]

Check the argument count of a registered function.

Raises:

PlaceholderError – arity.

ds_common_placeholder_py_lib.resolve.check_params(call: ds_common_placeholder_py_lib.grammar.Call, spec: ds_common_placeholder_py_lib.functions.FunctionSpec, values: list[Any]) → None[source]

Run each parameter’s own check on its argument’s value, a reference’s value too, so a failure names the reference.

Raises:

PlaceholderError – argument.

ds_common_placeholder_py_lib.resolve.check_lazy_literals(call: ds_common_placeholder_py_lib.grammar.Call) → None[source]

For coalesce: a literal must be last and not blank. A blank one is never a value, and nothing after a literal is ever read.

Raises:

PlaceholderError – argument.