1
0
mirror of synced 2024-12-28 07:31:32 +01:00

Don't process unsupported filenames with a known mimetype

This commit is contained in:
jvoisin 2018-05-15 23:29:04 +02:00
parent 94afdd970f
commit 7b0a27ce76

View File

@ -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: