diff options
| author | jvoisin | 2019-02-20 16:28:11 -0800 |
|---|---|---|
| committer | jvoisin | 2019-02-20 16:28:11 -0800 |
| commit | 02ff21b158c76fcd355a74ddb940e1c54fc2d7ed (patch) | |
| tree | 701c6f5e316265e5a95a162356965ecf2fb8d6b2 /libmat2/parser_factory.py | |
| parent | 6b45064c784d03bb21ffaf7e50c9ba684e6985a9 (diff) | |
Implement epub support
Diffstat (limited to 'libmat2/parser_factory.py')
| -rw-r--r-- | libmat2/parser_factory.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/libmat2/parser_factory.py b/libmat2/parser_factory.py index 30c3b52..e93ee4f 100644 --- a/libmat2/parser_factory.py +++ b/libmat2/parser_factory.py | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | import logging | ||
| 1 | import glob | 2 | import glob |
| 2 | import os | 3 | import os |
| 3 | import mimetypes | 4 | import mimetypes |
| @@ -10,6 +11,10 @@ assert Tuple # make pyflakes happy | |||
| 10 | 11 | ||
| 11 | T = TypeVar('T', bound='abstract.AbstractParser') | 12 | T = TypeVar('T', bound='abstract.AbstractParser') |
| 12 | 13 | ||
| 14 | mimetypes.add_type('application/epub+zip', '.epub') | ||
| 15 | # EPUB Navigation Control XML File | ||
| 16 | mimetypes.add_type('application/x-dtbncx+xml', '.ncx') | ||
| 17 | |||
| 13 | 18 | ||
| 14 | def __load_all_parsers(): | 19 | def __load_all_parsers(): |
| 15 | """ Loads every parser in a dynamic way """ | 20 | """ Loads every parser in a dynamic way """ |
| @@ -49,6 +54,8 @@ def get_parser(filename: str) -> Tuple[Optional[T], Optional[str]]: | |||
| 49 | if mtype in parser_class.mimetypes: | 54 | if mtype in parser_class.mimetypes: |
| 50 | try: | 55 | try: |
| 51 | return parser_class(filename), mtype | 56 | return parser_class(filename), mtype |
| 52 | except ValueError: | 57 | except ValueError as e: |
| 58 | logging.info("Got an exception when trying to instanciate " | ||
| 59 | "%s for %s: %s", parser_class, filename, e) | ||
| 53 | return None, mtype | 60 | return None, mtype |
| 54 | return None, mtype | 61 | return None, mtype |
