cottax.consumers.json.format module¶
A graph as JSON: write_json and read_json.
- loaded(name: str)[source]¶
What module:qualname names, among the modules already imported: a file imports nothing unless a resolve handed in does.
- Return type:
object
- by_word[A: Spelling | PlaceCodec | LabelCodec](interface: type[A], word: str)[source]¶
Each registered interface answer by its word: what a file names it by.
- Return type:
dict[str,A]
- read_json(data: dict, resolve: Callable[[str], object] = loaded)[source]¶
The graph data spells, every rule asked of it: places and node names by the codecs registered under the file’s tags, each node by the spelling registered for its kind; a name resolved by resolve.
- Return type:
- check_codec[N: Label, V: Place](graph: NestingGraph[N, V], implementations: bool)[source]¶
One registered codec writes every node name, and one every place. A graph with no node has no place either, so it is refused once.
- Return type:
Iterator[Violation]
- check_nodes_write[N: Label, V: Place](graph: NestingGraph[N, V], implementations: bool)[source]¶
Each node writes: the check is the writing, so the two cannot disagree.
- Return type:
Iterator[Violation]
- write_json[N: Label, V: Place](graph: NestingGraph[N, V], implementations: bool = True)[source]¶
A graph written as JSON, ready for json.dump: each binding its name and its definition, places by the registered codecs. With implementations=False, the structure alone. Each node is written twice: once by the check, once here.
- Return type:
dict
- class NodeWriter[N: Label, V: Place](place_codec: PlaceCodec[V], label_codec: LabelCodec[N], implementations: bool, name: N)[source]¶
Bases:
Frozen,Generic[N,V]A Writer: the node bound at name, through the codecs.
- place_codec: PlaceCodec[V]¶
- label_codec: LabelCodec[N]¶
- implementations: bool¶
- name: N¶
- place(place: V)[source]¶
Through the codec; what it refuses is refused, anything else in a spelling raises.
- Return type:
- node(node: NodeDefinition[V])[source]¶
node by its final’s spelling; without implementations, a wrapped one as its node.
- Return type:
dict
- class NodeReader[N: Label, V: Place](place_codec: PlaceCodec[V], label_codec: LabelCodec[N], resolve: Callable[[str], object], name: N)[source]¶
Bases:
Frozen,Generic[N,V]A Reader: the node bound at name, through the place codec.
- place_codec: PlaceCodec[V]¶
- label_codec: LabelCodec[N]¶
- resolve: Callable[[str], object]¶
- name: N¶
- reference(obj: object)[source]¶
module:qualname if that finds obj again, else None: a lambda, a local, anything in __main__ or bound under another name.
- Return type:
str|None
- class FunctionSpelling[source]¶
-
- kind: AbstractClassVar[str] = 'function'¶
How it is referred to in the file.
- class DrivenSpelling[source]¶
-
The condition, the driver as a value, and each slot with its role’s name.
- kind: AbstractClassVar[str] = 'driven'¶
How it is referred to in the file.
- class ImplementedSpelling[source]¶
Bases:
Spelling[Implemented]The node and what runs it; the final is the node’s level’s (implemented_as).
- kind: AbstractClassVar[str] = 'implemented'¶
How it is referred to in the file.