Upload frozen release files
Browse files- DATASET.md +25 -0
- LICENSE +21 -0
- README.md +23 -0
- data/coverage.json +14 -0
- data/offers.json +0 -0
- data/offers.jsonl +0 -0
- pyproject.toml +8 -0
- schema/offers.schema.json +26 -0
- scripts/build_index.py +43 -0
- scripts/extract_offers.py +119 -0
- scripts/fetch_notices.py +87 -0
- scripts/fetch_registry.py +93 -0
- tests/test_pipeline.py +106 -0
DATASET.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Dataset candidate
|
| 2 |
+
|
| 3 |
+
## Provenance
|
| 4 |
+
|
| 5 |
+
The candidate indexes factual fields mechanically extracted from the California Attorney General’s [data breach notice registry](https://oag.ca.gov/privacy/databreach/list) and its CSV export. The registry describes sample notices submitted for incidents affecting more than 500 California residents. The filer may not be the organization that experienced the incident.
|
| 6 |
+
|
| 7 |
+
Each build writes a local source manifest with source URL, access time, content type, byte count, and SHA-256. `data/coverage.json` is the committed receipt for the build included here. Source PDFs are inputs only: they are not committed, redistributed, or converted into published notice prose.
|
| 8 |
+
|
| 9 |
+
## Fields
|
| 10 |
+
|
| 11 |
+
Every row has: `id`, `organization`, `breach_dates`, `reported_date`, `data_exposed`, `remedy_type`, `remedy_provider`, `remedy_duration_months`, `remedy_duration_text`, `enrollment_deadline`, `enrollment_deadline_timezone`, `deadline_status`, `source_report_url`, `source_notice_url`, `source_notice_sha256`, `source_accessed_at`, and `extraction_confidence`.
|
| 12 |
+
|
| 13 |
+
`deadline_status` is `open`, `expired`, or `unknown`. It is calculated only from an explicit printed deadline and the recorded build timestamp. An ambiguous or absent deadline stays null and `unknown`; the builder does not infer a deadline from a letter date or the protection duration.
|
| 14 |
+
|
| 15 |
+
## Coverage and limitations
|
| 16 |
+
|
| 17 |
+
This candidate is partial. See `data/coverage.json` for its source-record denominator, report pages attempted, notice PDFs fetched, and resolved-row numerator. It does not claim complete registry coverage. Deterministic text extraction can miss a scanned notice or an unfamiliar deadline format. The index does not determine enrolment eligibility and must not be used as a substitute for a recipient’s notice.
|
| 18 |
+
|
| 19 |
+
The included receipt was updated 2026-07-30. To report a correction, write to hello@cybernative.ai.
|
| 20 |
+
|
| 21 |
+
## Dataset license and scope
|
| 22 |
+
|
| 23 |
+
The software in this repository is MIT-licensed under [LICENSE](LICENSE). CyberNative AI LLC dedicates its copyright and database rights, if any, in the selection and arrangement of the factual dataset in [`data/`](data/) to the public domain under [CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/legalcode).
|
| 24 |
+
|
| 25 |
+
This CC0 dedication applies only to `data/` and only to the extent CyberNative AI LLC holds those rights. It does not apply to linked or underlying notice PDFs, notice prose, third-party trademarks, or any other third-party material. The CC0 1.0 Universal legal code and disclaimer are available at https://creativecommons.org/publicdomain/zero/1.0/legalcode.
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 CyberNative AI LLC
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Breach Clock
|
| 2 |
+
|
| 3 |
+
Breach Clock builds a small, static index of protection offers and printed enrolment deadlines from California Attorney General data-breach notice filings. It is a search aid, not an eligibility decision: a person’s own letter and its activation code determine whether they can enrol.
|
| 4 |
+
|
| 5 |
+
## Run
|
| 6 |
+
|
| 7 |
+
Requires Python 3.11+ and `pdftotext` from Poppler. The scripts use only the Python standard library and make no metered API calls.
|
| 8 |
+
|
| 9 |
+
```sh
|
| 10 |
+
python scripts/fetch_registry.py
|
| 11 |
+
python scripts/fetch_notices.py --only-id sb24-626307 --max-reports 1
|
| 12 |
+
python scripts/extract_offers.py
|
| 13 |
+
python scripts/build_index.py
|
| 14 |
+
python -m unittest discover -s tests -v
|
| 15 |
+
```
|
| 16 |
+
|
| 17 |
+
The downloaded source inputs and `build/source-manifest.json` are local build inputs; they are intentionally not committed. Notice PDFs and notice prose are never published by this repository.
|
| 18 |
+
|
| 19 |
+
## Output
|
| 20 |
+
|
| 21 |
+
`data/offers.jsonl` is the line-oriented index. `data/offers.json` is the browser-ready equivalent. `data/coverage.json` describes the exact build scope and counts. Each row links to the original report and notice, and records the notice hash and access time.
|
| 22 |
+
|
| 23 |
+
The software is MIT-licensed. CyberNative AI LLC dedicates only its rights, if any, in the selection and arrangement of `data/` under CC0 1.0 Universal; linked or underlying notices, notice prose, third-party trademarks, and other third-party material are excluded. [DATASET.md](DATASET.md) governs the exact scope.
|
data/coverage.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"built_at": "2026-07-30T00:00:00Z",
|
| 3 |
+
"coverage_complete": false,
|
| 4 |
+
"extraction_failures": 0,
|
| 5 |
+
"pdfs_fetched": 138,
|
| 6 |
+
"report_pages_attempted": 138,
|
| 7 |
+
"resolved_record_count": 137,
|
| 8 |
+
"rows_expired": 0,
|
| 9 |
+
"rows_open": 20,
|
| 10 |
+
"rows_unknown": 117,
|
| 11 |
+
"rows_with_any_remedy": 128,
|
| 12 |
+
"rows_with_explicit_deadline": 20,
|
| 13 |
+
"source_record_count": 5232
|
| 14 |
+
}
|
data/offers.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
data/offers.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
pyproject.toml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "breach-clock"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = "Static index builder for California breach-notice protection offers."
|
| 5 |
+
requires-python = ">=3.11"
|
| 6 |
+
|
| 7 |
+
[tool.unittest]
|
| 8 |
+
start-directory = "tests"
|
schema/offers.schema.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
| 3 |
+
"title": "Breach Clock offer row",
|
| 4 |
+
"type": "object",
|
| 5 |
+
"additionalProperties": false,
|
| 6 |
+
"required": ["id", "organization", "breach_dates", "reported_date", "data_exposed", "remedy_type", "remedy_provider", "remedy_duration_months", "remedy_duration_text", "enrollment_deadline", "enrollment_deadline_timezone", "deadline_status", "source_report_url", "source_notice_url", "source_notice_sha256", "source_accessed_at", "extraction_confidence"],
|
| 7 |
+
"properties": {
|
| 8 |
+
"id": {"type": "string"},
|
| 9 |
+
"organization": {"type": ["string", "null"]},
|
| 10 |
+
"breach_dates": {"type": "array", "items": {"type": "string", "format": "date"}},
|
| 11 |
+
"reported_date": {"type": ["string", "null"], "format": "date"},
|
| 12 |
+
"data_exposed": {"type": "array", "items": {"type": "string"}},
|
| 13 |
+
"remedy_type": {"type": ["string", "null"]},
|
| 14 |
+
"remedy_provider": {"type": ["string", "null"]},
|
| 15 |
+
"remedy_duration_months": {"type": ["integer", "null"], "minimum": 0},
|
| 16 |
+
"remedy_duration_text": {"type": ["string", "null"]},
|
| 17 |
+
"enrollment_deadline": {"type": ["string", "null"], "format": "date"},
|
| 18 |
+
"enrollment_deadline_timezone": {"type": ["string", "null"]},
|
| 19 |
+
"deadline_status": {"enum": ["open", "expired", "unknown"]},
|
| 20 |
+
"source_report_url": {"type": "string", "format": "uri"},
|
| 21 |
+
"source_notice_url": {"type": "string", "format": "uri"},
|
| 22 |
+
"source_notice_sha256": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
|
| 23 |
+
"source_accessed_at": {"type": "string", "format": "date-time"},
|
| 24 |
+
"extraction_confidence": {"type": "number", "minimum": 0, "maximum": 1}
|
| 25 |
+
}
|
| 26 |
+
}
|
scripts/build_index.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Build publication JSON and a coverage receipt from extracted factual rows."""
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import json
|
| 7 |
+
from collections import Counter
|
| 8 |
+
from datetime import datetime, timezone
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def main() -> None:
|
| 13 |
+
parser = argparse.ArgumentParser()
|
| 14 |
+
parser.add_argument("--rows", default="build/extracted.jsonl")
|
| 15 |
+
parser.add_argument("--reports", default="build/reports.jsonl")
|
| 16 |
+
parser.add_argument("--notices", default="build/notices/manifest.jsonl")
|
| 17 |
+
parser.add_argument("--out-dir", default="data")
|
| 18 |
+
parser.add_argument("--built-at", default=datetime.now(timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z"))
|
| 19 |
+
parser.add_argument("--report-pages-attempted", type=int)
|
| 20 |
+
parser.add_argument("--pdfs-fetched", type=int)
|
| 21 |
+
args = parser.parse_args()
|
| 22 |
+
rows = [json.loads(line) for line in Path(args.rows).read_text(encoding="utf-8").splitlines() if line]
|
| 23 |
+
reports = [line for line in Path(args.reports).read_text(encoding="utf-8").splitlines() if line]
|
| 24 |
+
notices = [json.loads(line) for line in Path(args.notices).read_text(encoding="utf-8").splitlines() if line]
|
| 25 |
+
rows.sort(key=lambda row: (row["organization"] or "").casefold())
|
| 26 |
+
counts = Counter(row["deadline_status"] for row in rows)
|
| 27 |
+
out = Path(args.out_dir)
|
| 28 |
+
out.mkdir(parents=True, exist_ok=True)
|
| 29 |
+
(out / "offers.jsonl").write_text("".join(json.dumps(row, sort_keys=True) + "\n" for row in rows), encoding="utf-8")
|
| 30 |
+
(out / "offers.json").write_text(json.dumps(rows, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
| 31 |
+
coverage = {
|
| 32 |
+
"built_at": args.built_at, "source_record_count": len(reports), "report_pages_attempted": args.report_pages_attempted if args.report_pages_attempted is not None else len(notices),
|
| 33 |
+
"pdfs_fetched": args.pdfs_fetched if args.pdfs_fetched is not None else sum("pdf_path" in row for row in notices), "extraction_failures": sum("error" in row for row in notices) + sum("pdf_path" not in row for row in notices),
|
| 34 |
+
"resolved_record_count": len(rows), "rows_with_any_remedy": sum(bool(row["remedy_type"]) for row in rows),
|
| 35 |
+
"rows_with_explicit_deadline": sum(bool(row["enrollment_deadline"]) for row in rows), "rows_open": counts["open"],
|
| 36 |
+
"rows_expired": counts["expired"], "rows_unknown": counts["unknown"], "coverage_complete": len(rows) == len(reports),
|
| 37 |
+
}
|
| 38 |
+
(out / "coverage.json").write_text(json.dumps(coverage, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
| 39 |
+
print(json.dumps(coverage, sort_keys=True))
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
if __name__ == "__main__":
|
| 43 |
+
main()
|
scripts/extract_offers.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Deterministically extract factual offer fields without retaining notice prose."""
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import json
|
| 7 |
+
import re
|
| 8 |
+
import subprocess
|
| 9 |
+
from datetime import date, datetime, timezone
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
FORBIDDEN_KEYS = {"activation_code", "enrollment_code", "addressee", "address", "phone", "email", "mailing_address"}
|
| 13 |
+
MONTHS = "January|February|March|April|May|June|July|August|September|October|November|December"
|
| 14 |
+
PROVIDERS = ("Experian IdentityWorks", "Experian", "Equifax", "TransUnion", "Kroll", "IDX", "AllClear", "Cyberscout")
|
| 15 |
+
EXPOSURES = ((r"social security", "Social Security number"), (r"driver.?s license", "Driver's license number"), (r"financial account", "Financial account information"), (r"health information", "Health information"), (r"date of birth", "Date of birth"), (r"name", "Name"))
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def clean(value: str) -> str:
|
| 19 |
+
return re.sub(r"\s+", " ", value).strip()
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def text_from_pdf(path: str) -> str:
|
| 23 |
+
result = subprocess.run(["pdftotext", "-layout", path, "-"], check=True, capture_output=True, text=True)
|
| 24 |
+
return result.stdout
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def parse_date(value: str) -> str | None:
|
| 28 |
+
value = value.strip().replace(",", "")
|
| 29 |
+
for pattern in ("%B %d %Y", "%b %d %Y", "%m/%d/%Y"):
|
| 30 |
+
try:
|
| 31 |
+
return datetime.strptime(value, pattern).date().isoformat()
|
| 32 |
+
except ValueError:
|
| 33 |
+
pass
|
| 34 |
+
return None
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def deadline_from(text: str) -> tuple[str | None, str | None]:
|
| 38 |
+
pattern = rf"(?:enrol(?:l(?:ment)?)?|register|sign\s*up)\b.{{0,100}}?(?:by|before|until)\s+(({MONTHS})\s+\d{{1,2}},?\s+\d{{4}}|\d{{1,2}}/\d{{1,2}}/\d{{4}})"
|
| 39 |
+
matches = list(re.finditer(pattern, text, flags=re.I | re.S))
|
| 40 |
+
parsed = []
|
| 41 |
+
for match in matches:
|
| 42 |
+
iso = parse_date(match.group(1))
|
| 43 |
+
if iso:
|
| 44 |
+
zone = re.search(r"\b(UTC|PST|PDT|EST|EDT|CST|CDT|MST|MDT|Pacific Time|Eastern Time|Central Time|Mountain Time)\b", text[match.end():match.end() + 45], flags=re.I)
|
| 45 |
+
parsed.append((iso, zone.group(1).upper() if zone else None))
|
| 46 |
+
unique = {(item[0], item[1]) for item in parsed}
|
| 47 |
+
return next(iter(unique)) if len(unique) == 1 else (None, None)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def deadline_status(deadline: str | None, built_at: str) -> str:
|
| 51 |
+
if not deadline:
|
| 52 |
+
return "unknown"
|
| 53 |
+
today = datetime.fromisoformat(built_at.replace("Z", "+00:00")).date()
|
| 54 |
+
printed = date.fromisoformat(deadline)
|
| 55 |
+
if printed >= today:
|
| 56 |
+
return "open"
|
| 57 |
+
if printed < today:
|
| 58 |
+
return "expired"
|
| 59 |
+
return "unknown"
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def provider_from(text: str) -> str | None:
|
| 63 |
+
if re.search(r"enroll\.krollmonitoring\.com", text, flags=re.I):
|
| 64 |
+
return "Kroll"
|
| 65 |
+
enrollment_provider = re.search(r"Visit\s+(?:the\s+)?(Experian IdentityWorks|Experian|Equifax|TransUnion|Kroll|IDX|AllClear|Cyberscout)(?:\s+website)?\s+(?:to\s+)?enroll", text, flags=re.I)
|
| 66 |
+
if enrollment_provider:
|
| 67 |
+
return enrollment_provider.group(1)
|
| 68 |
+
return next((name for name in PROVIDERS if re.search(re.escape(name), text, flags=re.I)), None)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def extract(record: dict, text: str, built_at: str) -> dict:
|
| 72 |
+
deadline, zone = deadline_from(text)
|
| 73 |
+
provider = provider_from(text)
|
| 74 |
+
duration = re.search(r"\(?([0-9]{1,2})\)?\s*(months?)\b", text, flags=re.I)
|
| 75 |
+
months = None
|
| 76 |
+
duration_text = None
|
| 77 |
+
if duration:
|
| 78 |
+
raw_number, unit = duration.group(1), duration.group(2).lower()
|
| 79 |
+
months = int(raw_number) * (12 if unit.startswith("year") else 1)
|
| 80 |
+
duration_text = f"{raw_number} {unit}"
|
| 81 |
+
exposure_section = re.search(r"(?:what information was involved|information involved).*?(?:what we are doing|what you can do)", text, flags=re.I | re.S)
|
| 82 |
+
lower = exposure_section.group(0).lower() if exposure_section else ""
|
| 83 |
+
exposed = [label for needle, label in EXPOSURES if re.search(needle, lower)]
|
| 84 |
+
remedy_type = "identity protection" if provider else ("credit monitoring" if re.search(r"credit monitoring", text, flags=re.I) else None)
|
| 85 |
+
fields = {
|
| 86 |
+
"id": record["id"], "organization": record.get("organization"), "breach_dates": record.get("breach_dates", []),
|
| 87 |
+
"reported_date": record.get("reported_date"), "data_exposed": exposed, "remedy_type": remedy_type,
|
| 88 |
+
"remedy_provider": provider, "remedy_duration_months": months, "remedy_duration_text": duration_text,
|
| 89 |
+
"enrollment_deadline": deadline, "enrollment_deadline_timezone": zone,
|
| 90 |
+
"deadline_status": deadline_status(deadline, built_at), "source_report_url": record["report_url"],
|
| 91 |
+
"source_notice_url": record["source_notice_url"], "source_notice_sha256": record["source_notice_sha256"],
|
| 92 |
+
"source_accessed_at": record["source_accessed_at"],
|
| 93 |
+
}
|
| 94 |
+
fields["extraction_confidence"] = round((sum(value is not None and value != [] for value in (fields["organization"], provider, months, deadline)) / 4), 2)
|
| 95 |
+
return {key: value for key, value in fields.items() if key not in FORBIDDEN_KEYS}
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def main() -> None:
|
| 99 |
+
parser = argparse.ArgumentParser()
|
| 100 |
+
parser.add_argument("--notices", default="build/notices/manifest.jsonl")
|
| 101 |
+
parser.add_argument("--out", default="build/extracted.jsonl")
|
| 102 |
+
parser.add_argument("--built-at", default=datetime.now(timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z"))
|
| 103 |
+
args = parser.parse_args()
|
| 104 |
+
rows, failures = [], 0
|
| 105 |
+
for line in Path(args.notices).read_text(encoding="utf-8").splitlines():
|
| 106 |
+
record = json.loads(line)
|
| 107 |
+
if "pdf_path" not in record:
|
| 108 |
+
failures += 1
|
| 109 |
+
continue
|
| 110 |
+
try:
|
| 111 |
+
rows.append(extract(record, text_from_pdf(record["pdf_path"]), args.built_at))
|
| 112 |
+
except (OSError, subprocess.CalledProcessError):
|
| 113 |
+
failures += 1
|
| 114 |
+
Path(args.out).write_text("".join(json.dumps(row, sort_keys=True) + "\n" for row in rows), encoding="utf-8")
|
| 115 |
+
print(json.dumps({"rows": len(rows), "extraction_failures": failures, "built_at": args.built_at}, sort_keys=True))
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
if __name__ == "__main__":
|
| 119 |
+
main()
|
scripts/fetch_notices.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Fetch report pages and linked PDFs as local, uncommitted build inputs."""
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import hashlib
|
| 7 |
+
import json
|
| 8 |
+
import re
|
| 9 |
+
import subprocess
|
| 10 |
+
from datetime import datetime, timezone
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from extract_offers import deadline_from, text_from_pdf
|
| 13 |
+
from fetch_registry import fetch
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def utc_now() -> str:
|
| 17 |
+
return datetime.now(timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def receipt(url: str, payload: bytes, content_type: str, accessed_at: str, attempts: int) -> dict:
|
| 21 |
+
return {"url": url, "accessed_at": accessed_at, "size": len(payload), "content_type": content_type, "sha256": hashlib.sha256(payload).hexdigest(), "acquisition_attempts": attempts}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def notice_url(report_html: str) -> str | None:
|
| 25 |
+
match = re.search(r'href="(https://oag\.ca\.gov/system/files/[^"]+\.pdf[^"]*)"', report_html, flags=re.I)
|
| 26 |
+
return match.group(1) if match else None
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def main() -> None:
|
| 30 |
+
parser = argparse.ArgumentParser()
|
| 31 |
+
parser.add_argument("--reports", default="build/reports.jsonl")
|
| 32 |
+
parser.add_argument("--out-dir", default="build/notices")
|
| 33 |
+
parser.add_argument("--manifest", default="build/source-manifest.json")
|
| 34 |
+
parser.add_argument("--only-id")
|
| 35 |
+
parser.add_argument("--max-reports", type=int, default=25)
|
| 36 |
+
parser.add_argument("--start-index", type=int, default=0)
|
| 37 |
+
parser.add_argument("--min-explicit-deadlines", type=int, default=0)
|
| 38 |
+
parser.add_argument("--built-at", default=None)
|
| 39 |
+
args = parser.parse_args()
|
| 40 |
+
reports = [json.loads(line) for line in Path(args.reports).read_text(encoding="utf-8").splitlines() if line]
|
| 41 |
+
if args.only_id:
|
| 42 |
+
reports = [report for report in reports if report["id"] == args.only_id]
|
| 43 |
+
reports = reports[args.start_index:args.start_index + args.max_reports]
|
| 44 |
+
out_dir = Path(args.out_dir)
|
| 45 |
+
out_dir.mkdir(parents=True, exist_ok=True)
|
| 46 |
+
manifest_path = Path(args.manifest)
|
| 47 |
+
manifest = json.loads(manifest_path.read_text(encoding="utf-8")) if manifest_path.exists() else []
|
| 48 |
+
output = []
|
| 49 |
+
seen = set()
|
| 50 |
+
explicit_deadlines = 0
|
| 51 |
+
attempted = 0
|
| 52 |
+
for report in reports:
|
| 53 |
+
attempted += 1
|
| 54 |
+
accessed_at = utc_now()
|
| 55 |
+
try:
|
| 56 |
+
page, page_type, page_attempts = fetch(report["report_url"])
|
| 57 |
+
manifest.append(receipt(report["report_url"], page, page_type, accessed_at, page_attempts))
|
| 58 |
+
url = notice_url(page.decode("utf-8", errors="replace"))
|
| 59 |
+
if not url:
|
| 60 |
+
continue
|
| 61 |
+
pdf, pdf_type, pdf_attempts = fetch(url)
|
| 62 |
+
item = receipt(url, pdf, pdf_type, accessed_at, pdf_attempts)
|
| 63 |
+
manifest.append(item)
|
| 64 |
+
identity = (report["report_url"], item["sha256"])
|
| 65 |
+
if identity in seen:
|
| 66 |
+
continue
|
| 67 |
+
seen.add(identity)
|
| 68 |
+
path = out_dir / f'{report["id"]}.pdf'
|
| 69 |
+
path.write_bytes(pdf)
|
| 70 |
+
output.append({**report, "source_notice_url": url, "source_notice_sha256": item["sha256"], "source_accessed_at": accessed_at, "pdf_path": str(path)})
|
| 71 |
+
try:
|
| 72 |
+
explicit_deadlines += bool(deadline_from(text_from_pdf(str(path)))[0])
|
| 73 |
+
except (OSError, RuntimeError, subprocess.CalledProcessError):
|
| 74 |
+
pass
|
| 75 |
+
if args.min_explicit_deadlines and explicit_deadlines >= args.min_explicit_deadlines:
|
| 76 |
+
break
|
| 77 |
+
except Exception as exc:
|
| 78 |
+
output.append({**report, "error": type(exc).__name__})
|
| 79 |
+
with (out_dir / "manifest.jsonl").open("w", encoding="utf-8") as handle:
|
| 80 |
+
for item in output:
|
| 81 |
+
handle.write(json.dumps(item, sort_keys=True) + "\n")
|
| 82 |
+
manifest_path.write_text(json.dumps(manifest, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
| 83 |
+
print(json.dumps({"report_pages_attempted": attempted, "notice_rows": len(output), "pdfs_fetched": sum("pdf_path" in item for item in output), "explicit_deadline_candidates": explicit_deadlines}, sort_keys=True))
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
if __name__ == "__main__":
|
| 87 |
+
main()
|
scripts/fetch_registry.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Fetch the official registry and make a local, hashed source receipt."""
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import csv
|
| 7 |
+
import hashlib
|
| 8 |
+
import json
|
| 9 |
+
import re
|
| 10 |
+
from datetime import datetime, timezone
|
| 11 |
+
from http.client import IncompleteRead
|
| 12 |
+
from html import unescape
|
| 13 |
+
from time import sleep
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
from urllib.error import ContentTooShortError
|
| 16 |
+
from urllib.request import Request, urlopen
|
| 17 |
+
|
| 18 |
+
REGISTRY_URL = "https://oag.ca.gov/privacy/databreach/list"
|
| 19 |
+
CSV_URL = "https://oag.ca.gov/privacy/databreach/list-export"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def utc_now() -> str:
|
| 23 |
+
return datetime.now(timezone.utc).replace(microsecond=0).isoformat().replace("+00:00", "Z")
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def fetch(url: str, *, opener=urlopen, pause=sleep) -> tuple[bytes, str, int]:
|
| 27 |
+
"""Read a source completely, retrying only incomplete/truncated acquisition."""
|
| 28 |
+
request = Request(url, headers={"User-Agent": "BreachClock/0.1 (+https://cybernative.ai)"})
|
| 29 |
+
for attempt in range(1, 4):
|
| 30 |
+
try:
|
| 31 |
+
with opener(request, timeout=60) as response:
|
| 32 |
+
return response.read(), response.headers.get_content_type(), attempt
|
| 33 |
+
except (IncompleteRead, ContentTooShortError):
|
| 34 |
+
if attempt == 3:
|
| 35 |
+
raise
|
| 36 |
+
pause(0.2 * attempt)
|
| 37 |
+
raise AssertionError("unreachable")
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def receipt(url: str, payload: bytes, content_type: str, accessed_at: str, attempts: int) -> dict:
|
| 41 |
+
return {"url": url, "accessed_at": accessed_at, "size": len(payload), "content_type": content_type, "sha256": hashlib.sha256(payload).hexdigest(), "acquisition_attempts": attempts}
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def plain(value: str) -> str:
|
| 45 |
+
return re.sub(r"\s+", " ", unescape(re.sub(r"<[^>]+>", " ", value))).strip()
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def iso_date(value: str) -> str | None:
|
| 49 |
+
value = value.strip()
|
| 50 |
+
match = re.search(r"(\d{2})/(\d{2})/(\d{4})", value)
|
| 51 |
+
if not match:
|
| 52 |
+
return None
|
| 53 |
+
return f"{match.group(3)}-{match.group(1)}-{match.group(2)}"
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def parse_reports(html: str) -> list[dict]:
|
| 57 |
+
reports = []
|
| 58 |
+
for row in re.findall(r"<tr[^>]*>(.*?)</tr>", html, flags=re.S | re.I):
|
| 59 |
+
link = re.search(r'href="(https://oag\.ca\.gov/ecrime/databreach/reports/(sb24-\d+))"[^>]*>(.*?)</a>', row, flags=re.S | re.I)
|
| 60 |
+
if not link:
|
| 61 |
+
continue
|
| 62 |
+
cells = re.findall(r"<td[^>]*>(.*?)</td>", row, flags=re.S | re.I)
|
| 63 |
+
dates = [iso_date(value) for value in re.findall(r">([^<]*\d{2}/\d{2}/\d{4}[^<]*)<", row)]
|
| 64 |
+
reports.append({
|
| 65 |
+
"id": link.group(2), "report_url": link.group(1), "organization": plain(link.group(3)),
|
| 66 |
+
"breach_dates": [date for date in dates[:-1] if date], "reported_date": dates[-1] if dates else None,
|
| 67 |
+
})
|
| 68 |
+
return reports
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def main() -> None:
|
| 72 |
+
parser = argparse.ArgumentParser()
|
| 73 |
+
parser.add_argument("--build-dir", default="build")
|
| 74 |
+
args = parser.parse_args()
|
| 75 |
+
build = Path(args.build_dir)
|
| 76 |
+
build.mkdir(parents=True, exist_ok=True)
|
| 77 |
+
accessed_at = utc_now()
|
| 78 |
+
csv_bytes, csv_type, csv_attempts = fetch(CSV_URL)
|
| 79 |
+
html_bytes, html_type, html_attempts = fetch(REGISTRY_URL)
|
| 80 |
+
(build / "registry.csv").write_bytes(csv_bytes)
|
| 81 |
+
(build / "registry.html").write_bytes(html_bytes)
|
| 82 |
+
reports = parse_reports(html_bytes.decode("utf-8", errors="replace"))
|
| 83 |
+
with (build / "reports.jsonl").open("w", encoding="utf-8") as handle:
|
| 84 |
+
for report in reports:
|
| 85 |
+
handle.write(json.dumps(report, sort_keys=True) + "\n")
|
| 86 |
+
csv_rows = list(csv.DictReader(csv_bytes.decode("utf-8-sig").splitlines()))
|
| 87 |
+
manifest = [receipt(CSV_URL, csv_bytes, csv_type, accessed_at, csv_attempts), receipt(REGISTRY_URL, html_bytes, html_type, accessed_at, html_attempts)]
|
| 88 |
+
(build / "source-manifest.json").write_text(json.dumps(manifest, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
| 89 |
+
print(json.dumps({"csv_records": len(csv_rows), "report_links": len(reports), "manifest": str(build / "source-manifest.json")}, sort_keys=True))
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
if __name__ == "__main__":
|
| 93 |
+
main()
|
tests/test_pipeline.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib.util
|
| 2 |
+
from http.client import IncompleteRead
|
| 3 |
+
import json
|
| 4 |
+
import unittest
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def load(name):
|
| 11 |
+
spec = importlib.util.spec_from_file_location(name, ROOT / "scripts" / f"{name}.py")
|
| 12 |
+
module = importlib.util.module_from_spec(spec)
|
| 13 |
+
spec.loader.exec_module(module)
|
| 14 |
+
return module
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
extract = load("extract_offers")
|
| 18 |
+
transport = load("fetch_registry")
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class OfferExtractionTests(unittest.TestCase):
|
| 22 |
+
def record(self, identifier="sb24-626307", organization="Wilmer Cutler Pickering Hale and Dorr LLP"):
|
| 23 |
+
return {"id": identifier, "organization": organization, "breach_dates": ["2026-05-08"], "reported_date": "2026-07-10", "report_url": f"https://oag.ca.gov/ecrime/databreach/reports/{identifier}", "source_notice_url": "https://oag.ca.gov/system/files/example.pdf", "source_notice_sha256": "a" * 64, "source_accessed_at": "2026-07-30T00:00:00Z"}
|
| 24 |
+
|
| 25 |
+
def test_verified_fixture_values(self):
|
| 26 |
+
text = "Wilmer Cutler Pickering Hale and Dorr LLP offers Experian IdentityWorks for 24 months. Name and Social Security number were involved. You must enroll by October 30, 2026 at 23:59 UTC."
|
| 27 |
+
row = extract.extract(self.record(), text, "2026-07-30T00:00:00Z")
|
| 28 |
+
self.assertEqual(row["organization"], "Wilmer Cutler Pickering Hale and Dorr LLP")
|
| 29 |
+
self.assertEqual(row["breach_dates"], ["2026-05-08"])
|
| 30 |
+
self.assertEqual(row["remedy_provider"], "Experian IdentityWorks")
|
| 31 |
+
self.assertEqual(row["remedy_duration_months"], 24)
|
| 32 |
+
self.assertEqual(row["enrollment_deadline"], "2026-10-30")
|
| 33 |
+
self.assertEqual(row["enrollment_deadline_timezone"], "UTC")
|
| 34 |
+
self.assertEqual(row["deadline_status"], "open")
|
| 35 |
+
|
| 36 |
+
def test_ambiguous_deadlines_are_unknown(self):
|
| 37 |
+
row = extract.extract(self.record(), "Enroll by October 30, 2026. Register before November 1, 2026.", "2026-07-30T00:00:00Z")
|
| 38 |
+
self.assertIsNone(row["enrollment_deadline"])
|
| 39 |
+
self.assertEqual(row["deadline_status"], "unknown")
|
| 40 |
+
|
| 41 |
+
def test_missing_remedy_stays_null(self):
|
| 42 |
+
row = extract.extract(self.record(), "Enroll by October 30, 2026 UTC.", "2026-07-30T00:00:00Z")
|
| 43 |
+
self.assertIsNone(row["remedy_type"])
|
| 44 |
+
self.assertIsNone(row["remedy_provider"])
|
| 45 |
+
self.assertIsNone(row["remedy_duration_months"])
|
| 46 |
+
|
| 47 |
+
def test_multiple_breach_dates_are_preserved(self):
|
| 48 |
+
record = self.record()
|
| 49 |
+
record["breach_dates"] = ["2026-05-08", "2026-05-09"]
|
| 50 |
+
self.assertEqual(extract.extract(record, "", "2026-07-30T00:00:00Z")["breach_dates"], ["2026-05-08", "2026-05-09"])
|
| 51 |
+
|
| 52 |
+
def test_repeated_organizations_are_distinct_source_rows(self):
|
| 53 |
+
first = extract.extract(self.record("sb24-1", "Example Inc."), "", "2026-07-30T00:00:00Z")
|
| 54 |
+
second = extract.extract(self.record("sb24-2", "Example Inc."), "", "2026-07-30T00:00:00Z")
|
| 55 |
+
self.assertNotEqual(first["id"], second["id"])
|
| 56 |
+
self.assertEqual(first["organization"], second["organization"])
|
| 57 |
+
|
| 58 |
+
def test_explicit_timezone_and_person_fields_are_safe(self):
|
| 59 |
+
row = extract.extract(self.record(), "Enroll before 10/30/2026 PDT. Morgan Example lives at 10 Example Street.", "2026-07-30T00:00:00Z")
|
| 60 |
+
self.assertEqual(row["enrollment_deadline_timezone"], "PDT")
|
| 61 |
+
self.assertFalse({"activation_code", "enrollment_code", "addressee", "address", "phone", "email", "mailing_address"} & set(row))
|
| 62 |
+
self.assertNotIn("Morgan Example", json.dumps(row))
|
| 63 |
+
self.assertNotIn("10 Example Street", json.dumps(row))
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def test_same_day_explicit_deadline_is_open(self):
|
| 67 |
+
row = extract.extract(self.record(), "Enroll by July 30, 2026 UTC.", "2026-07-30T18:00:00Z")
|
| 68 |
+
self.assertEqual(row["deadline_status"], "open")
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
class TransportTests(unittest.TestCase):
|
| 72 |
+
def test_incomplete_read_retries_once_then_records_success(self):
|
| 73 |
+
calls = []
|
| 74 |
+
|
| 75 |
+
class Response:
|
| 76 |
+
headers = type("Headers", (), {"get_content_type": lambda self: "application/pdf"})()
|
| 77 |
+
|
| 78 |
+
def __init__(self, payload):
|
| 79 |
+
self.payload = payload
|
| 80 |
+
|
| 81 |
+
def __enter__(self):
|
| 82 |
+
return self
|
| 83 |
+
|
| 84 |
+
def __exit__(self, *_):
|
| 85 |
+
return False
|
| 86 |
+
|
| 87 |
+
def read(self):
|
| 88 |
+
if isinstance(self.payload, Exception):
|
| 89 |
+
raise self.payload
|
| 90 |
+
return self.payload
|
| 91 |
+
|
| 92 |
+
payloads = [IncompleteRead(b"partial", 12), b"complete notice"]
|
| 93 |
+
|
| 94 |
+
def opener(_request, timeout):
|
| 95 |
+
calls.append(timeout)
|
| 96 |
+
return Response(payloads.pop(0))
|
| 97 |
+
|
| 98 |
+
body, content_type, attempts = transport.fetch("https://example.test/notice.pdf", opener=opener, pause=lambda _: None)
|
| 99 |
+
self.assertEqual(body, b"complete notice")
|
| 100 |
+
self.assertEqual(content_type, "application/pdf")
|
| 101 |
+
self.assertEqual(attempts, 2)
|
| 102 |
+
self.assertEqual(calls, [60, 60])
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
if __name__ == "__main__":
|
| 106 |
+
unittest.main()
|