23 if self.metadata
is not None:
26 f
"š· {self.metadata[0]}",
28 SnapshotValue.of(self.metadata[1]),
31 for entry_key, entry_value
in self.
snapshots.items():
32 self.
writeEntry(valueWriter, entry_key,
None, entry_value.subject)
33 for facet_key, facet_value
in entry_value.facets.items():
34 self.
writeEntry(valueWriter, entry_key, facet_key, facet_value)
36 self.
writeEntry(valueWriter,
"",
"end of file", SnapshotValue.of(
""))
40 valueWriter: list[str], key: str, facet: Optional[str], value: SnapshotValue
42 valueWriter.append(
"āā ")
43 valueWriter.append(SnapshotValueReader.name_esc.escape(key))
45 valueWriter.append(
"[")
46 valueWriter.append(SnapshotValueReader.name_esc.escape(facet))
47 valueWriter.append(
"]")
48 valueWriter.append(
" āā")
50 valueWriter.append(
" base64 length ")
51 valueWriter.append(str(len(value.value_binary())))
52 valueWriter.append(
" bytes")
53 valueWriter.append(
"\n")
55 if not key
and facet ==
"end of file":
59 escaped = base64.b64encode(value.value_binary()).decode(
"utf-8")
60 valueWriter.append(escaped.replace(
"\r",
""))
62 escaped = SnapshotValueReader.body_esc.escape(value.value_string()).replace(
63 "\nā",
"\n\ud801\udf41"
65 valueWriter.append(escaped)
66 valueWriter.append(
"\n")
81 def parse(cls, value_reader: SnapshotValueReader) ->
"SnapshotFile":
83 result.unix_newlines = value_reader.unix_newlines
86 peek_key = reader.peek_key()
89 metadata_value = value_reader.next_value().value_string()
90 result.metadata = (metadata_name, metadata_value)
91 reader.next_snapshot()
94 peek_key = reader.peek_key()
99 next_snapshot = reader.next_snapshot()
100 result.snapshots = result.snapshots.plus(peek_key, next_snapshot)