● Zion Boggan
repos/Sightline/backend/app/services/parsers/base.py
zionboggan.com ↗
24 lines · python
History for this file →
1
from __future__ import annotations
2
 
3
from abc import ABC, abstractmethod
4
from dataclasses import dataclass, field
5
 
6
from app.services.normalize import RawRead
7
 
8
 
9
@dataclass
10
class ParseResult:
11
    headers: list[str]
12
    rows: list[RawRead] = field(default_factory=list)
13
    errors: list[str] = field(default_factory=list)
14
 
15
 
16
class BaseParser(ABC):
17
    """Every parser turns raw bytes into a ParseResult of RawRead rows + discovered headers.
18
    Normalization happens downstream so parsers stay format-specific and dumb."""
19
 
20
    name: str = "base"
21
 
22
    @abstractmethod
23
    def parse(self, data: bytes) -> ParseResult:
24
        ...