diff options
| -rw-r--r-- | src/parser_factory.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/parser_factory.py b/src/parser_factory.py index 226234b..812d95c 100644 --- a/src/parser_factory.py +++ b/src/parser_factory.py | |||
| @@ -4,6 +4,10 @@ import pkgutil | |||
| 4 | 4 | ||
| 5 | from . import abstract | 5 | from . import abstract |
| 6 | 6 | ||
| 7 | from typing import Type, TypeVar | ||
| 8 | |||
| 9 | T = TypeVar('T', bound='abstract.AbstractParser') | ||
| 10 | |||
| 7 | for module_loader, name, ispkg in pkgutil.walk_packages('.src'): | 11 | for module_loader, name, ispkg in pkgutil.walk_packages('.src'): |
| 8 | if not name.startswith('src.'): | 12 | if not name.startswith('src.'): |
| 9 | continue | 13 | continue |
| @@ -11,10 +15,9 @@ for module_loader, name, ispkg in pkgutil.walk_packages('.src'): | |||
| 11 | continue | 15 | continue |
| 12 | importlib.import_module(name) | 16 | importlib.import_module(name) |
| 13 | 17 | ||
| 14 | def get_parser(filename: str): | 18 | def get_parser(filename: str) -> (T, str): |
| 15 | mtype, _ = mimetypes.guess_type(filename) | 19 | mtype, _ = mimetypes.guess_type(filename) |
| 16 | for c in abstract.AbstractParser.__subclasses__(): | 20 | for c in abstract.AbstractParser.__subclasses__(): |
| 17 | if mtype in c.mimetypes: | 21 | if mtype in c.mimetypes: |
| 18 | return c(filename), mtype | 22 | return c(filename), mtype |
| 19 | print('factory: %s is not supported' % mtype) | ||
| 20 | return None, mtype | 23 | return None, mtype |
