Repository navigation
Page sources: cite an HTML or XML page by id from a URL template (#179) - #191
Conversation
…break (#179) read_url(url, reference_id, config, *, declared_format=None) holds the download, PDF, bot-challenge, title and flatten steps, so a configured page source can read a page under its own reference id. _markup_format uses the declared format only when the response itself says nothing; never for SVG or drawio. url: output is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A sources: entry with format html or xml. url_template must use {id} and
nothing else; title is an optional template with the same rule. Problems
raise ValueError in __post_init__, as for JSONAPISourceConfig.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…#179) Page sources cache under their own prefix (e.g. CFR:) with content type url, so they share the url: stamp and are refreshed with url: pages. An unstamped non-url: entry with content type url is refetched once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PageSource builds the URL from {id}, reads it with URLSource.read_url,
applies the title template and records the page URL as full_text_url.
The loader sends non-JSON formats to PageSourceConfig, refuses JSON-only
keys, and skips an unknown format or bad template with a warning (an
unknown format used to load as JSON). Tests use a real eCFR renderer page
for 21 CFR 872.3275.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Claude finished @caufieldjh's task in 50s —— View job PR review: page sources (#179)
SummaryThe design holds up. Issues1. Formatting: three blank lines before 2. The identifier goes into the URL without URL-encoding (
3. Confusing error for 4. Literal braces in Performance
Cache stamp changeExtending the stamp check to Test coverageThe tests are good. Two gaps you might fill:
SecurityThere's no new attack surface beyond item 2. Downloads still go through VerdictReady to merge once item 1 is checked. Items 2–4 and the test gaps are optional improvements. |
- PageSource.url_for URL-encodes the id (keeping / and :), so an id can't
add a query parameter or fragment.
- url_template must be http(s) with a fixed host; {id} only in the path
or query.
- format is read without regard to case, so format: JSON stays JSON.
- Docs: literal braces in title, the host rule, id encoding.
- Tests: the above, a PDF answer (full_text_pdf, template title, no url
stamp), and 'CFR 872.3275' cached as CFR:872.3275.
- Drop an extra blank line in loader.py; ruff format the two new files.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks. Addressed in 1d4057f:
Tests added for each, plus the two gaps: a PDF answer (cached as Not changed: caching a |
|
Claude finished @caufieldjh's task in 24s —— View job PR review: follow-up commit
|
…se in config (#191 re-review) - PageSource.fetch refuses an id with a '.' or '..' path segment, since '/' is kept and the request could reach another path on the host. - url_template may not put {id} in the #fragment, which is never sent. - PageSourceConfig lower-cases format itself, so code-built configs take any case as YAML does. - Import order in models.py. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Re-review points addressed in d2e8d58:
Each has a test, and the docs mention 1 and 2. |
|
Claude finished @caufieldjh's task in 26s —— View job PR review: follow-up commit
|
Addresses the third ask in #179 (from the issue comments): a
sources:entry that builds a URL from{id}and reads the response the wayurl:does. Items 1 and 2 landed in #188 and #189. With this, #179 can be closed, unless entry-point discovery (the alternative raised in the issue) is still wanted.Change
A
sources:entry may now setformat: htmlorformat: xml:CFR:872.3275is then fetched from that URL. HTML is sanitized and XML flattened exactly as forurl:pages, and the cached entry keeps the idCFR:872.3275.format:json(the default, unchanged),htmlorxml, in any case. The declared format only settles a tie. If the response's content type or first bytes say what it is, the response wins. SVG and drawio are never read as XML.{id}is filled in, andurl_templatemust use it. The issue's sample used{part}, but eCFR doesn't need it:?section=872.3275redirects to the full path. A template with any other placeholder is skipped with a warning. The template must behttp(s)with a fixed host, and the id is URL-encoded (keeping/and:).title: an optional literal template with{id}. Without it, the page's<title>is used, or failing that the URL, as forurl:.fields,headers,store_raw_response,content_type) are refused on a page entry with a warning. A badPageSourceConfigbuilt in Python raisesValueError, asJSONAPISourceConfigdoes since Let a JSON API source quote several fields (#179, item 2) #189.urland the page URL asfull_text_url. They share theurl_source_versionstamp, so they are refreshed along withurl:pages.Commits
Split for review:
URLSource.read_urlsplit out offetch, with a declared format as tie-break.url:output is unchanged.PageSourceConfigand the template checks (models.py).url.PageSource, loader wiring, exports, tests and fixture.format, and more tests.{id}in the fragment, format case normalised in the config too.Behaviour changes (for release notes)
sources:entry with an unrecognisedformat(e.g.pdf) used to load quietly as a JSON source. Now it is skipped with a warning.url, nourl_source_versionstamp, and an id not startingurl:is refetched once. This likely includesCFR:entries made by a downstreamURLSourcesubclass.full_text_pdfwithout the stamp, asurl:does. The docs say so.Not in this PR
Tests
tests/test_page_sources.py(new) uses a real eCFR renderer response for 21 CFR 872.3275 (tests/fixtures/page_sources/, fetched 2026-12-03). It covers:full_text_url<em>id_patternsjust doctest(358),just mypyandjust format. The full suite was not run locally:test_url_fragment_cache.pyandtest_wikipedia_source.pytime out on and off on my machine connecting to their own127.0.0.1test servers. Leaving that to CI.CFR:872.3275:<em>is valid.Docs
docs/how-to/add-reference-source.mdhas a new "Page sources (HTML or XML)" section, and its config table listsformatandtitle.🤖 Generated with Claude Code