~kf5jwc/sms-printer

ref: 72a9603961d1c8932a452cbf59e7e5cc6eb073e3 sms-printer/sms_broker_parsers/parsers/__init__.py -rw-r--r-- 763 bytes View raw
72a96039 — Kyle Jones A __main__ for this isn't *really* useful. 1 year, 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import automodinit
import logging
from typing import Any, Callable, Dict, List
from .. import types
from .. import errors

MIMETYPES: Dict[str, Any] = {}
__all__: List[str] = []


def get_mimetype_parser(mimetype) -> Callable[[str], List[types.sms]]:
    """Get the class of parser, so that we can ask it for the actual parser"""
    try:
        return MIMETYPES[mimetype]

    except KeyError:
        raise errors.NoParserForMimeType


# This sets our __all__ instead of returning a list
automodinit.automodinit(__name__, __file__, globals())

for module_name in __all__:
    mod = globals()[module_name]
    for mimetype in getattr(mod, "MIMETYPES"):
        MIMETYPES[mimetype] = getattr(mod, "parse_sms")

del automodinit

__all__ = ["get_mimetype_parser"]