diff options
Diffstat (limited to 'src/parser_factory.py')
| -rw-r--r-- | src/parser_factory.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/parser_factory.py b/src/parser_factory.py index 770f17c..7ce4246 100644 --- a/src/parser_factory.py +++ b/src/parser_factory.py | |||
| @@ -16,12 +16,17 @@ for module_loader, name, ispkg in pkgutil.walk_packages('.src'): | |||
| 16 | continue | 16 | continue |
| 17 | importlib.import_module(name) | 17 | importlib.import_module(name) |
| 18 | 18 | ||
| 19 | def _get_parsers() -> list: | ||
| 20 | """ Get all our parsers!""" | ||
| 21 | def __get_parsers(cls): | ||
| 22 | return cls.__subclasses__() + \ | ||
| 23 | [g for s in cls.__subclasses__() for g in __get_parsers(s)] | ||
| 24 | return __get_parsers(abstract.AbstractParser) | ||
| 25 | |||
| 19 | def get_parser(filename: str) -> (T, str): | 26 | def get_parser(filename: str) -> (T, str): |
| 20 | mtype, _ = mimetypes.guess_type(filename) | 27 | mtype, _ = mimetypes.guess_type(filename) |
| 21 | def get_subclasses(cls): | 28 | |
| 22 | return cls.__subclasses__() + \ | 29 | for c in _get_parsers(): |
| 23 | [g for s in cls.__subclasses__() for g in get_subclasses(s)] | ||
| 24 | for c in get_subclasses(abstract.AbstractParser): | ||
| 25 | if mtype in c.mimetypes: | 30 | if mtype in c.mimetypes: |
| 26 | return c(filename), mtype | 31 | return c(filename), mtype |
| 27 | return None, mtype | 32 | return None, mtype |
