Skip to content

comicbox.readinglists.sources ¶

Where reading lists are fetched from: URLs, Metron and the DieselTech catalog.

Network libraries are imported inside functions, so importing this package stays cheap; only a fetch pays for them.

FetchContext ¶

Bases: Protocol

What a source needs from the session that runs its fetch.

ReadingListSession is one. Sources name this rather than the session class, so the session can import them without a cycle.

Source code in comicbox/readinglists/sources/__init__.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class FetchContext(Protocol):
    """
    What a source needs from the session that runs its fetch.

    ``ReadingListSession`` is one. Sources name this rather than the session
    class, so the session can import them without a cycle.
    """

    @property
    def settings(self) -> ComicboxSettings:
        """The settings every fetch uses."""
        ...

    @property
    def credentials(self) -> OnlineCredentials | None:
        """The credentials the session was given, if any."""
        ...

    @property
    def cancelled(self) -> threading.Event:
        """Set once the session is cancelled."""
        ...

    def emit(self, event: Event) -> None:
        """Hand an event to the caller's handler, if any."""
        ...

    def check_cancelled(self) -> None:
        """Raise if the session was cancelled."""
        ...

    def http(self) -> httpx.Client:
        """Get the session's HTTP client."""
        ...

cancelled property ¶

Set once the session is cancelled.

credentials property ¶

The credentials the session was given, if any.

settings property ¶

The settings every fetch uses.

check_cancelled() ¶

Raise if the session was cancelled.

Source code in comicbox/readinglists/sources/__init__.py
53
54
55
def check_cancelled(self) -> None:
    """Raise if the session was cancelled."""
    ...

emit(event) ¶

Hand an event to the caller’s handler, if any.

Source code in comicbox/readinglists/sources/__init__.py
49
50
51
def emit(self, event: Event) -> None:
    """Hand an event to the caller's handler, if any."""
    ...

http() ¶

Get the session’s HTTP client.

Source code in comicbox/readinglists/sources/__init__.py
57
58
59
def http(self) -> httpx.Client:
    """Get the session's HTTP client."""
    ...

attach_source(reading_list, source) ¶

Record where a fetched list came from.

A file read gives its list a source of kind file; a fetched one came from source instead, so that one takes its place, keeping what it knew that source does not, such as a CBL’s curator. A list with no file source gets source first.

Source code in comicbox/readinglists/sources/__init__.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def attach_source(
    reading_list: Mapping[str, Any], source: Mapping[str, Any]
) -> dict[str, Any]:
    """
    Record where a fetched list came from.

    A file read gives its list a source of kind ``file``; a fetched one came
    from ``source`` instead, so that one takes its place, keeping what it
    knew that ``source`` does not, such as a CBL's curator. A list with no
    file source gets ``source`` first.
    """
    fetched = {key: value for key, value in source.items() if not is_empty(value)}
    sources = [dict(item) for item in reading_list.get(SOURCES_KEY) or ()]
    for index, item in enumerate(sources):
        if item.get(SOURCE_KIND_KEY) == SourceKind.FILE.value:
            del item[SOURCE_KIND_KEY]
            sources[index] = {**item, **fetched}
            break
    else:
        sources.insert(0, fetched)
    return {**reading_list, SOURCES_KEY: sources}