From 7b0a27ce76ab178faade2ed8aeb29383c9c0687c Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 15 May 2018 23:29:04 +0200 Subject: [PATCH] Don't process unsupported filenames with a known mimetype --- src/parser_factory.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 @@ +import os import mimetypes import importlib import pkgutil @@ -26,8 +27,14 @@ def _get_parsers() -> list: def get_parser(filename: str) -> (T, str): - mtype, _ = mimetypes.guess_type(filename) + # A set of extension that aren't supported, despite matching a known mimetype + unknown_extensions = set(['bat', 'c', 'h', 'ksh', 'pl', 'txt', 'asc', + 'text', 'pot', 'brf', 'srt', 'rdf', 'wsdl', 'xpdl', 'xsl', 'xsd']) + _, extension = os.path.splitext(filename) + if extension in unknown_extensions: + return None, mtype + mtype, _ = mimetypes.guess_type(filename) for c in _get_parsers(): if mtype in c.mimetypes: try: