Skip to content
YosoiDocs

Document

yosoi.documents.Document

class Document(ImmutableModel):

Immutable document bytes with retained native parse ownership.

Attributes: id: Validated document identity, independent of any source URL. profile: Representation and schema interpretation of the retained bytes. data: Exact owned bytes; text inputs are UTF-8 encoded. Model dumps omit payload data by default.

Source: python/yosoi/documents.py:155

Members below are declared on this class. Inherited Pydantic methods and generated constructor signatures are not expanded.

id: DocumentId
profile: DocumentProfile
data: bytes = Field(repr=False, exclude=True)
def model_post_init(self, context: object) -> None:

Create or validate native ownership of these exact document inputs.

Source: python/yosoi/documents.py:170

@classmethod
def html(cls, id: str, content: str | bytes) -> Self:

Retain source bytes using the HTML5 interpretation.

Args: id: Authored document identity, independent of any acquisition URL. content: Exact bytes, or text to encode as UTF-8.

Returns: A document owning its payload without external acquisition.

Raises: pydantic.ValidationError: Identity or authoring fields are invalid. DocumentError: Native construction rejects the supplied inputs.

Source: python/yosoi/documents.py:192

@classmethod
def xml(cls, id: str, content: str | bytes) -> Self:

Retain source bytes using the XML 1.0 interpretation.

Args: id: Authored document identity, independent of any acquisition URL. content: Exact bytes, or text to encode as UTF-8.

Returns: A document owning its payload without external acquisition.

Raises: pydantic.ValidationError: Identity or authoring fields are invalid. DocumentError: Native construction rejects the supplied inputs.

Source: python/yosoi/documents.py:209

@classmethod
def from_json(cls, id: str, content: str | bytes) -> Self:

Retain source bytes using the RFC 8259 JSON interpretation.

Args: id: Authored document identity, independent of any acquisition URL. content: Exact bytes, or text to encode as UTF-8.

Returns: A document owning its payload without external acquisition.

Raises: pydantic.ValidationError: Identity or authoring fields are invalid. DocumentError: Native construction rejects the supplied inputs.

Source: python/yosoi/documents.py:226

@classmethod
def text(cls, id: str, content: str | bytes) -> Self:

Retain source bytes using the UTF-8 text interpretation.

Args: id: Authored document identity, independent of any acquisition URL. content: Exact bytes, or text to encode as UTF-8.

Returns: A document owning its payload without external acquisition.

Raises: pydantic.ValidationError: Identity or authoring fields are invalid. DocumentError: Native construction rejects the supplied inputs.

Source: python/yosoi/documents.py:243

@classmethod
def from_profile(cls, id: str, profile: DocumentProfile, content: str | bytes) -> Self:

Retain content using an explicit interpretation profile.

Args: id: Authored document identity. profile: Validated representation, syntax, schema, and epoch declaration. content: Exact bytes, or text to encode as UTF-8.

Returns: Immutable payload ownership without external acquisition.

Raises: pydantic.ValidationError: Identity or authoring fields are invalid. DocumentError: Native construction rejects the supplied inputs.

Source: python/yosoi/documents.py:260

@classmethod
def rendered_dom(cls, id: str, epoch: int | DocumentEpoch, content: str | bytes) -> Self:

Declare retained rendered DOM snapshot interpretation.

Args: id: Authored document identity. epoch: Positive immutable browser snapshot generation. content: JSON snapshot bytes or text in the supported version-1 schema.

Returns: A retained snapshot document without querying a live browser.

Raises: pydantic.ValidationError: Epoch or authoring fields are invalid. DocumentError: Native profile or document validation rejects the inputs.

Source: python/yosoi/documents.py:280

@classmethod
def accessibility_tree(cls, id: str, epoch: int | DocumentEpoch, content: str | bytes) -> Self:

Declare retained accessibility snapshot interpretation.

Args: id: Authored document identity. epoch: Positive immutable browser snapshot generation. content: JSON snapshot bytes or text in the supported version-1 schema.

Returns: A retained snapshot document without querying a live browser.

Raises: pydantic.ValidationError: Epoch or authoring fields are invalid. DocumentError: Native profile or document validation rejects the inputs.

Source: python/yosoi/documents.py:308

@property
def byte_len(self) -> int:

Return retained payload bytes, not decoded character count.

Source: python/yosoi/documents.py:336

@property
def document_class(self) -> DocumentClass:

Return the native capability class of the retained payload.

Source: python/yosoi/documents.py:341

def bind(self, policy: Policy) -> BoundDocument:

Snapshot a complete policy without acquiring new data.

Args: policy: Complete declaration to serialize now.

Returns: A document binding unaffected by later caller-policy edits.

Source: python/yosoi/documents.py:345

def locate(self, plan: Plan) -> LocateOutcome:

Execute a bounded locator plan against retained payload bytes.

Args: plan: Authored outputs, projections, and repeated regions.

Returns: Typed matches, complete absence, indeterminate evidence, or failure. No network acquisition occurs; empty convenience collections alone do not establish complete absence.

Source: python/yosoi/documents.py:356

def parse(self) -> ParsedDocument:

Create a reusable native parse using default resource policy.

Returns: A parse owner to close explicitly or use as a context manager.

Raises: ParseError: Parsing or resource checks reject the retained payload.

Source: python/yosoi/documents.py:369

def model_copy(self, *, update: Mapping[str, Any] | None=None, deep: bool=False) -> Self:

Copy authoring values while preserving valid native ownership.

Args: update: Optional replacement fields to revalidate. deep: Reconstruct through the public constructor when True.

Returns: A document copy. Unchanged shallow copies retain the native handle; updated or deep copies are reconstructed and revalidated.

Raises: pydantic.ValidationError: Updated authoring fields are invalid. DocumentError: Native reconstruction rejects the supplied inputs.

Source: python/yosoi/documents.py:380