1
- from typing import ClassVar , Optional , Type
1
+ from typing import Optional , Type
2
2
3
3
from xmltodict import parse
4
4
5
5
from rss_parser .models import XMLBaseModel
6
+ from rss_parser .models .atom import Atom
6
7
from rss_parser .models .rss import RSS
7
8
8
9
# >>> FUTURE
9
10
# TODO: May be support generator based approach for big rss feeds
10
11
# TODO: Add cli to parse to json
11
12
# TODO: Possibly bundle as deb/rpm/exe
12
- # TODO: Atom support
13
- # TODO: Older RSS versions?
13
+ # TODO: Older Atom versions
14
+ # TODO: Older RSS versions
14
15
15
16
16
17
class Parser :
17
18
"""Parser for rss files."""
18
19
19
- schema : ClassVar [Type [XMLBaseModel ]] = RSS
20
-
21
20
@staticmethod
22
- def _check_atom (root : dict ):
21
+ def check_schema (root : dict ) -> tuple [ dict , type [ XMLBaseModel ]] :
23
22
if "feed" in root :
24
- raise NotImplementedError ("ATOM feed is not currently supported" )
23
+ return root , Atom
24
+ return root ["rss" ], RSS
25
25
26
26
@staticmethod
27
27
def to_xml (data : str , * args , ** kwargs ):
@@ -36,8 +36,6 @@ def parse(cls, data: str, *, schema: Optional[Type[XMLBaseModel]] = None) -> XML
36
36
:return: "schema" object
37
37
"""
38
38
root = cls .to_xml (data )
39
- cls ._check_atom (root )
40
-
41
- schema = schema or cls .schema
39
+ root , schema = cls .check_schema (root )
42
40
43
- return schema .parse_obj (root [ "rss" ] )
41
+ return schema .parse_obj (root )
0 commit comments