c3a3cb50c9
Adds the port/adapter pair that lets the release domain consume parsing knowledge without importing infrastructure or loading YAML at import time. - alfred/domain/release/ports/knowledge.py declares the read-only query surface: token sets (resolutions, sources, codecs, language_tokens, forbidden_chars, hdr_extra), structured dicts (audio, video_meta, editions, media_type_tokens), separators list, file-extension sets, and sanitize_for_fs(text). - alfred/infrastructure/knowledge/release_kb.py loads every YAML once at construction and exposes them as attributes, with an immutable str.maketrans table backing sanitize_for_fs. No domain code is wired to the port yet — that lands in the next commit.
53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
"""ReleaseKnowledge port — the read-only query surface that
|
|
``parse_release`` and ``ParsedRelease`` need from the release knowledge
|
|
base, expressed as a structural Protocol so the domain never imports any
|
|
concrete loader.
|
|
|
|
The concrete YAML-backed implementation lives in
|
|
``alfred/infrastructure/knowledge/release_kb.py``. Tests can supply any
|
|
object that satisfies this shape (e.g. a simple dataclass).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Protocol
|
|
|
|
|
|
class ReleaseKnowledge(Protocol):
|
|
"""Read-only snapshot of release-name parsing knowledge."""
|
|
|
|
# --- Token sets used by the tokenizer / matchers ---
|
|
|
|
resolutions: set[str]
|
|
sources: set[str]
|
|
codecs: set[str]
|
|
language_tokens: set[str]
|
|
forbidden_chars: set[str]
|
|
hdr_extra: set[str]
|
|
|
|
# --- Structured knowledge (loaded from YAML as dicts) ---
|
|
|
|
audio: dict
|
|
video_meta: dict
|
|
editions: dict
|
|
media_type_tokens: dict
|
|
|
|
# --- Tokenizer separators ---
|
|
|
|
separators: list[str]
|
|
|
|
# --- File-extension sets (used by application/infra modules that work
|
|
# directly with filesystem paths, e.g. media-type detection, video
|
|
# lookup). Domain parsing itself doesn't touch these. ---
|
|
|
|
video_extensions: set[str]
|
|
non_video_extensions: set[str]
|
|
subtitle_extensions: set[str]
|
|
metadata_extensions: set[str]
|
|
|
|
# --- Filesystem sanitization (Option B: pre-sanitize at parse time) ---
|
|
|
|
def sanitize_for_fs(self, text: str) -> str:
|
|
"""Strip filesystem-forbidden characters from ``text``."""
|
|
...
|