"""A record as a read found it or a write left it, which every record backend gives.""" import dataclasses import hashlib @dataclasses.dataclass(frozen=True) class Held: """A record's text as one read found it or one write left it, with its version: what a write over it names, so the write refuses where someone saved the record since. None for a backend whose writes check no version, as a file's.""" text: str version: str | None = None def digest_of(text: str) -> str: """A fingerprint of a record's text or document, for a version a write names.""" return hashlib.sha256(text.encode("utf-8")).hexdigest()