1
0
mirror of synced 2024-11-25 18:54:22 +01:00

get_parse needs to explore subclasses recusively

This commit is contained in:
Loic Dachary 2018-04-03 00:05:03 +02:00 committed by jvoisin
parent 04a0032e9f
commit 76f25212d1

View File

@ -18,7 +18,10 @@ for module_loader, name, ispkg in pkgutil.walk_packages('.src'):
def get_parser(filename: str) -> (T, str): def get_parser(filename: str) -> (T, str):
mtype, _ = mimetypes.guess_type(filename) mtype, _ = mimetypes.guess_type(filename)
for c in abstract.AbstractParser.__subclasses__(): def get_subclasses(cls):
return cls.__subclasses__() + \
[g for s in cls.__subclasses__() for g in get_subclasses(s)]
for c in get_subclasses(abstract.AbstractParser):
if mtype in c.mimetypes: if mtype in c.mimetypes:
return c(filename), mtype return c(filename), mtype
return None, mtype return None, mtype