Historique regroupé en un seul commit pour ne pas publier de données de production. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""Lecteur LDIF minimal pour les tests (fichiers anonymisés uniquement)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import base64
|
|
from pathlib import Path
|
|
|
|
|
|
def load_ldif(path: Path) -> list[tuple[str, dict[str, list[bytes]]]]:
|
|
text = Path(path).read_text(encoding="utf-8")
|
|
lines: list[str] = []
|
|
for line in text.splitlines():
|
|
if line.startswith(" ") and lines:
|
|
lines[-1] += line[1:]
|
|
else:
|
|
lines.append(line)
|
|
|
|
entries: list[tuple[str, dict[str, list[bytes]]]] = []
|
|
dn: str | None = None
|
|
attrs: dict[str, list[bytes]] = {}
|
|
for line in lines + [""]:
|
|
if not line.strip():
|
|
if dn is not None:
|
|
entries.append((dn, attrs))
|
|
dn, attrs = None, {}
|
|
continue
|
|
if line.startswith("#"):
|
|
continue
|
|
name, _, rest = line.partition(":")
|
|
if rest.startswith(":"):
|
|
value = base64.b64decode(rest[1:].strip())
|
|
else:
|
|
value = rest.strip().encode("utf-8")
|
|
name = name.split(";")[0]
|
|
if name == "dn":
|
|
dn = value.decode("utf-8")
|
|
else:
|
|
attrs.setdefault(name, []).append(value)
|
|
return entries
|