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"]