1from collections.abc
import Iterator
2from typing
import Union
4from .ArrayMap
import ArrayMap
5from .LineReader
import _to_unix
6from .SnapshotValue
import SnapshotValue
12 subject: SnapshotValue,
13 facet_data: ArrayMap[str, SnapshotValue] = ArrayMap.empty(),
23 def facets(self) -> ArrayMap[str, SnapshotValue]:
26 def __eq__(self, other: object) -> bool:
27 if not isinstance(other, Snapshot):
35 self, key: str, value: Union[bytes, str, SnapshotValue]
38 raise ValueError(
"The empty string is reserved for the subject.")
41 self.
_facet_data.plus(_to_unix(key), SnapshotValue.of(value)),
45 self, key: str, value: Union[bytes, str, SnapshotValue]
53 _to_unix(key), SnapshotValue.of(value)
63 raise KeyError(f
"'{key}' not found in snapshot.")
67 def of(data: Union[bytes, str, SnapshotValue]) ->
"Snapshot":
68 if not isinstance(data, SnapshotValue):
69 data = SnapshotValue.of(data)
70 return Snapshot(data, ArrayMap.empty())
73 def of_items(items: Iterator[tuple[str, SnapshotValue]]) ->
"Snapshot":
75 facets = ArrayMap.empty()
79 if subject
is not None:
81 "Duplicate root snapshot value.\n first: ${subject}\n second: ${value}"
85 facets = facets.plus(key, value)
86 return Snapshot(subject
if subject
else SnapshotValue.of(
""), facets)
88 def items(self) -> Iterator[tuple[str, SnapshotValue]]:
93 pieces = [f
"Snapshot.of({self.subject.value_string()!r})"]
95 pieces.append(f
"\n .plus_facet({e[0]!r}, {e[1].value_string()!r})")
96 return "".join(pieces)
"Snapshot" plus_or_replace(self, str key, Union[bytes, str, SnapshotValue] value)
SnapshotValue subject(self)
Iterator[tuple[str, SnapshotValue]] items(self)
SnapshotValue subject_or_facet(self, str key)
__init__(self, SnapshotValue subject, ArrayMap[str, SnapshotValue] facet_data=ArrayMap.empty())
"Snapshot" of(Union[bytes, str, SnapshotValue] data)
ArrayMap[str, SnapshotValue] facets(self)
"Snapshot" of_items(Iterator[tuple[str, SnapshotValue]] items)
bool __eq__(self, object other)
"Snapshot" plus_facet(self, str key, Union[bytes, str, SnapshotValue] value)
Union[SnapshotValue, None] subject_or_facet_maybe(self, str key)