diff options
| author | jvoisin | 2018-05-15 23:29:04 +0200 |
|---|---|---|
| committer | jvoisin | 2018-05-15 23:29:04 +0200 |
| commit | 7b0a27ce76ab178faade2ed8aeb29383c9c0687c (patch) | |
| tree | cdb1651fb7b150f5ff7e55ed9013382d01a53c3e /src/parser_factory.py | |
| parent | 94afdd970fe085de782221075956471dbc4fcb2a (diff) | |
Don't process unsupported filenames with a known mimetype
Diffstat (limited to '')
| -rw-r--r-- | src/parser_factory.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/parser_factory.py b/src/parser_factory.py index 80aedae..b403eb7 100644 --- a/src/parser_factory.py +++ b/src/parser_factory.py | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | import os | ||
| 1 | import mimetypes | 2 | import mimetypes |
| 2 | import importlib | 3 | import importlib |
| 3 | import pkgutil | 4 | import pkgutil |
| @@ -26,8 +27,14 @@ def _get_parsers() -> list: | |||
| 26 | 27 | ||
| 27 | 28 | ||
| 28 | def get_parser(filename: str) -> (T, str): | 29 | def get_parser(filename: str) -> (T, str): |
| 29 | mtype, _ = mimetypes.guess_type(filename) | 30 | # A set of extension that aren't supported, despite matching a known mimetype |
| 31 | unknown_extensions = set(['bat', 'c', 'h', 'ksh', 'pl', 'txt', 'asc', | ||
| 32 | 'text', 'pot', 'brf', 'srt', 'rdf', 'wsdl', 'xpdl', 'xsl', 'xsd']) | ||
| 33 | _, extension = os.path.splitext(filename) | ||
| 34 | if extension in unknown_extensions: | ||
| 35 | return None, mtype | ||
| 30 | 36 | ||
| 37 | mtype, _ = mimetypes.guess_type(filename) | ||
| 31 | for c in _get_parsers(): | 38 | for c in _get_parsers(): |
| 32 | if mtype in c.mimetypes: | 39 | if mtype in c.mimetypes: |
| 33 | try: | 40 | try: |
