39 lines
959 B
Python
39 lines
959 B
Python
"""Document loading: open a ``.docx`` package and parse it into a model.
|
|
|
|
This is the single choke point for reading a document. It opens the OPC
|
|
package and returns a :class:`~doced.ast.doc.DocumentModel` — the package plus
|
|
a parsed AST plus a locator index, ready for read + in-place mutation.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from ..ast.doc import DocumentModel
|
|
from ..package import (
|
|
NotAZipError,
|
|
Package,
|
|
PackageNotFound,
|
|
PackagePartMissing,
|
|
PartNotFoundError,
|
|
)
|
|
|
|
|
|
def open_document(path: str | Path) -> DocumentModel:
|
|
"""Open *path* and return a :class:`~doced.ast.doc.DocumentModel`.
|
|
|
|
Raises the package-level errors through so the CLI can map them to the
|
|
LLM contract's error codes.
|
|
"""
|
|
pkg = Package.open(path)
|
|
return DocumentModel(pkg)
|
|
|
|
|
|
__all__ = [
|
|
"open_document",
|
|
"PackageNotFound",
|
|
"PartNotFoundError",
|
|
"PackagePartMissing",
|
|
"NotAZipError",
|
|
]
|