feat(consent-tester): Phase B — named CMP library + plugin architecture
cmp_extractor.py refactored to thin coordinator (123 LOC, was 223). Discovers all CMP modules via cmp_library/_registry.py:load_all() at import time. Restart consent-tester to pick up new modules. New cmp_library/ folder: - _registry.py: auto-discovers all modules with MATCHER + reconstruct() - epaas.py: BMW Group ePaaS (extracted from cmp_extractor) - onetrust.py: cdn.cookielaw.org Groups/Cookies schema - cookiebot.py: consent.cookiebot.com Categories schema - usercentrics.py: api.usercentrics.eu services schema - didomi.py: sdk.privacy-center.org notice + vendors + purposes - trustarc.py: consent.trustarc.com categories + vendors Each module: - MATCHER: re.Pattern matching the CMP JSON endpoint URL - reconstruct(d: dict) -> str: builds German Markdown cookie-policy text Phase E (self-improving) will write auto_*.py files into the same folder; _registry already picks those up via pkgutil.iter_modules.
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
"""TrustArc / TRUSTe CMP.
|
||||
|
||||
URLs:
|
||||
- consent.trustarc.com/v2/notice/<id>
|
||||
- cookie-pref.trustarc.com/...
|
||||
Schema varies; typically categories[] + vendors[]
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
MATCHER = re.compile(
|
||||
r"(?:consent|cookie-pref|tr-cdn)\.trustarc\.com/.+\.(?:json|js)(?:\?|$)", re.I,
|
||||
)
|
||||
|
||||
|
||||
def reconstruct(d: dict) -> str:
|
||||
parts: list[str] = ["# Cookie-Richtlinie (TrustArc)"]
|
||||
|
||||
for key in ("title", "summary", "description", "intro"):
|
||||
v = d.get(key)
|
||||
if v:
|
||||
parts.append("")
|
||||
parts.append(str(v))
|
||||
|
||||
cats = d.get("categories") or d.get("Categories") or []
|
||||
for c in cats:
|
||||
name = c.get("name") or c.get("Name") or ""
|
||||
desc = c.get("description") or c.get("Description") or ""
|
||||
parts.append("")
|
||||
parts.append(f"## {name}")
|
||||
if desc:
|
||||
parts.append(str(desc))
|
||||
cookies = c.get("cookies") or c.get("Cookies") or []
|
||||
for ck in cookies[:50]:
|
||||
cn = ck.get("name") or ck.get("Name") or ""
|
||||
cp = ck.get("purpose") or ck.get("Purpose") or ""
|
||||
ce = ck.get("expires") or ck.get("Expires") or ""
|
||||
line = f"- {cn}"
|
||||
if cp:
|
||||
line += f" — {cp[:120]}"
|
||||
if ce:
|
||||
line += f" — Speicherdauer: {ce}"
|
||||
parts.append(line)
|
||||
|
||||
vendors = d.get("vendors") or d.get("Vendors") or []
|
||||
if vendors:
|
||||
parts.append("")
|
||||
parts.append(f"## Anbieter ({len(vendors)})")
|
||||
for v in vendors[:80]:
|
||||
name = v.get("name") or v.get("Name") or ""
|
||||
parts.append(f"- {name}")
|
||||
|
||||
return "\n".join(parts)
|
||||
Reference in New Issue
Block a user