Files
omniread/omniread/pdf/parser.py

63 lines
1.6 KiB
Python

"""
# Summary
PDF parser base implementations for OmniRead.
This module defines the **PDF-specific parser contract**, extending the
format-agnostic `BaseParser` with constraints appropriate for PDF content.
PDF parsers are responsible for interpreting binary PDF data and producing
structured representations suitable for downstream consumption.
"""
from typing import Generic, TypeVar
from abc import abstractmethod
from omniread.core.content import ContentType
from omniread.core.parser import BaseParser
T = TypeVar("T")
class PDFParser(BaseParser[T], Generic[T]):
"""
Base PDF parser.
Notes:
**Responsibilities:**
- This class enforces PDF content-type compatibility and provides
the extension point for implementing concrete PDF parsing strategies.
**Constraints:**
- Concrete implementations must define the output type `T` and
implement the `parse()` method.
"""
supported_types = {ContentType.PDF}
"""
Set of content types supported by this parser (PDF only).
"""
@abstractmethod
def parse(self) -> T:
"""
Parse PDF content into a structured output.
Returns:
T:
Parsed representation of type `T`.
Raises:
Exception:
Parsing-specific errors as defined by the implementation.
Notes:
**Responsibilities:**
- Implementations must fully interpret the PDF binary payload and
return a deterministic, structured output.
"""
raise NotImplementedError