1"""
2The typed result classes behind :meth:`turbohtml.Document.feed` and :func:`turbohtml.extract.feed`.
3
4The walk that detects the feed format (RSS 2.0, Atom 1.0, or RDF/RSS-1.0) and normalizes an ``<item>``/``<entry>``/RDF
5item into one shape lives in the C core (``turbohtml._html``), exposed as :meth:`~turbohtml.Document.feed`. The C pass
6assembles the plain ``str``/``None`` fields and hands them to the :class:`Feed` and :class:`Entry` records defined here,
7so the typed, read-only result shapes live in Python while every walk stays in C. Importing this module registers both
8classes with the core.
9"""
10
11from __future__ import annotations
12
13from typing import NamedTuple
14
15from turbohtml._html import _register_feed
16
17__all__ = ["Entry", "Feed"]
18
19
20class Entry(NamedTuple):
21 """
22 One feed item, the normalized shape an RSS ``<item>``, an Atom ``<entry>``, and an RDF item share.
23
24 Every field is the first present value across the format's spellings, or ``None`` when the entry carries none.
25
26 :param title: the entry title.
27 :param link: the entry's permalink -- an Atom ``<link rel="alternate">`` href, an RSS/RDF ``<link>`` URL, or a
28 permalink ``<guid>`` when the entry has no ``<link>``.
29 :param id: the stable identifier: an RSS ``<guid>``, an Atom ``<id>``, or an RDF item's ``rdf:about``.
30 :param updated: the last-modified timestamp (Atom ``<updated>``, RSS ``<lastBuildDate>``), verbatim.
31 :param published: the publication timestamp (Atom ``<published>``, RSS ``<pubDate>``, RDF ``<dc:date>``), verbatim.
32 :param summary: the short description (Atom ``<summary>``, RSS ``<description>``, ``<dc:description>``).
33 :param content: the full body (RSS ``<content:encoded>``, Atom ``<content>``), preferred over ``summary``. Atom
34 content with a binary media type is decoded to bytes.
35 :param author: the author display name (an Atom ``<author><name>``, an RSS ``<author>``, or a ``<dc:creator>``).
36 """
37
38 title: str | None
39 link: str | None
40 id: str | None
41 updated: str | None
42 published: str | None
43 summary: str | None
44 content: str | bytes | None
45 author: str | None
46
47
48class Feed(NamedTuple):
49 """
50 A parsed syndication feed, the record :meth:`turbohtml.Document.feed` and :func:`turbohtml.extract.feed` return.
51
52 :param type: the detected format, one of ``"rss"``, ``"atom"``, or ``"rdf"``.
53 :param title: the feed title.
54 :param link: the feed's site link.
55 :param description: the feed description (RSS ``<description>``, Atom ``<subtitle>``).
56 :param updated: the feed's last-modified timestamp, verbatim.
57 :param entries: the feed's items in document order, or the channel's RDF sequence order for RSS 1.0.
58 """
59
60 type: str
61 title: str | None
62 link: str | None
63 description: str | None
64 updated: str | None
65 entries: tuple[Entry, ...]
66
67
68_register_feed(Feed, Entry)