Files
omniread/omniread/csv/parser_base.py

56 lines
1.3 KiB
Python

"""
# Summary
CSV parser base implementation for OmniRead.
This module defines the **CSV-specific parser contract**, extending the
format-agnostic `BaseParser` with constraints appropriate for
comma-separated-value documents.
"""
from abc import abstractmethod
from typing import Generic, TypeVar
from omniread.core.content import ContentType
from omniread.core.parser import BaseParser
T = TypeVar("T")
class CsvParserBase(BaseParser[T], Generic[T]):
"""
Base csv parser.
Notes:
**Responsibilities:**
- This class enforces csv content-type compatibility and provides
the extension point for implementing concrete csv parsing
strategies.
**Constraints:**
- Concrete implementations must define the output type `T` and
implement the `parse()` method.
"""
supported_types = {ContentType.CSV}
"""
Set of content types supported by this parser (CSV only).
"""
@abstractmethod
def parse(self) -> T:
"""
Parse csv content into a structured output.
Returns:
T:
Parsed representation of type `T`.
Raises:
Exception:
Parsing-specific errors as defined by the implementation.
"""
raise NotImplementedError