✨ feat(extract): parse RSS and Atom feeds#562
Merged
Conversation
Add turbohtml.extract.feed(xml) and Document.feed(), normalizing an RSS 2.0, Atom 1.0, or RDF/RSS-1.0 document into one frozen, typed Feed of Entry records. The format is detected from the root element and each dialect's spelling of a field is mapped onto one shape in a C walk of the parsed tree, following the structured-data extractor pattern: the walk lives in the C core and a thin Python facade defines the records. Field precedence follows feedparser (content:encoded/content over summary/description, guid-as-permalink link, Atom rel="alternate" link selection), kept to the minimal typed shape htmlparser2's parseFeed models. Timestamps come back verbatim. The HTML tree builder handles the feed XML: it lowercases and keeps namespaced element names, and the walk works with the void <link> (its URL is the next text sibling in RSS/RDF) rather than around it. Closes tox-dev#530
for more information, see https://pre-commit.ci
Merging this PR will not alter performance
Performance Changes
Comparing Footnotes
|
The feed() docstring and the feedparser migration guide linked Feed and Entry NamedTuple fields with :attr:, but those fields are documented via :param: in the class docstrings, not emitted as py:attribute targets, so the -W docs build failed on 15 unresolved references. Match the record convention used by PublicationDate and Paragraph: refer to the fields as plain literals and keep :class: links to the records themselves. Also folds in the clang-format comment rewrap and ruff-format reflow that prek --all-files flags on the feed C walk and its tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a feed parser to the extract surface:
turbohtml.extract.feed(xml)andDocument.feed()normalize an RSS 2.0, Atom 1.0, or RDF/RSS-1.0 document into one frozen, typedFeedofEntryrecords.The format is detected from the root element and each dialect's spelling of a field is mapped onto one shape in a C walk of the parsed tree, following the established structured-data extractor pattern: the walk lives in the C core (
_c/features/feed.c) and a thin Python facade (_feed.py) defines theFeed/EntryNamedTuples and registers them.Field precedence follows
feedparser—content:encoded/contentoversummary/description, a permalink<guid>as the link fallback, Atomrel="alternate"link selection — kept to the minimal typed shapehtmlparser2'sparseFeedmodels. Timestamps are returned verbatim. turbohtml reuses the HTML tree builder rather than adding a parser: it lowercases and keeps namespaced element names (dc:creator,content:encoded), and the walk works with the void<link>(whose URL lands as the next text sibling in RSS/RDF) rather than around it.Includes reference/how-to/explanation docs, a
feedparsermigration guide, asyndicationbenchmark op againstfeedparser, and a changelog fragment.Closes #530