"""技术验证共用:样本定位、格式识别。样本是不可信输入,只读取,不执行。""" from __future__ import annotations import pathlib ROOT = pathlib.Path(__file__).resolve().parent.parent SAMPLES = ROOT / "samples" / "tenders" IDS = [f"S{i:02d}" for i in range(1, 11)] def sample_file(sid: str) -> pathlib.Path: files = [p for p in (SAMPLES / sid).iterdir() if p.suffix.lower() in (".doc", ".docx")] assert len(files) == 1, (sid, files) return files[0] def sniff(path: pathlib.Path) -> str: """按文件头识别真实格式(FR-M2-01),不看扩展名。""" head = path.read_bytes()[:8] if head.startswith(b"PK\x03\x04"): return "docx" if head.startswith(bytes.fromhex("D0CF11E0A1B11AE1")): return "doc" if head.startswith(b"%PDF"): return "pdf" return "unknown"