diff --git a/mayan/apps/document_parsing/exceptions.py b/mayan/apps/document_parsing/exceptions.py index 76f872cabd..ebc1b0d0ca 100644 --- a/mayan/apps/document_parsing/exceptions.py +++ b/mayan/apps/document_parsing/exceptions.py @@ -6,10 +6,3 @@ class ParserError(Exception): Base exception for file parsers """ pass - - -class NoMIMETypeMatch(ParserError): - """ - There is no parser registered for the specified MIME type - """ - pass diff --git a/mayan/apps/document_parsing/parsers.py b/mayan/apps/document_parsing/parsers.py index 977b83f437..982dd2f105 100644 --- a/mayan/apps/document_parsing/parsers.py +++ b/mayan/apps/document_parsing/parsers.py @@ -9,7 +9,7 @@ from django.utils.translation import ugettext_lazy as _ from common.utils import copyfile, fs_cleanup, mkstemp -from .exceptions import ParserError, NoMIMETypeMatch +from .exceptions import ParserError from .settings import setting_pdftotext_path logger = logging.getLogger(__name__) @@ -32,40 +32,31 @@ class Parser(object): @classmethod def parse_document_version(cls, document_version): - try: - for parser_class in cls._registry[document_version.mimetype]: - try: - parser = parser_class() - parser.process_document_version(document_version) - except ParserError: - # If parser raises error, try next parser in the list - pass - else: - # If parser was successfull there is no need to try - # others in the list for this mimetype - return - - raise NoMIMETypeMatch('Parser MIME type list exhausted') - except KeyError: - raise NoMIMETypeMatch + for parser_class in cls._registry.get(document_version.mimetype, ()): + try: + parser = parser_class() + parser.process_document_version(document_version) + except ParserError: + # If parser raises error, try next parser in the list + pass + else: + # If parser was successfull there is no need to try + # others in the list for this mimetype + return @classmethod def parse_document_page(cls, document_page): - try: - for parser_class in cls._registry[document_page.document_version.mimetype]: - try: - parser = parser_class() - parser.process_document_page(document_page) - except ParserError: - # If parser raises error, try next parser in the list - pass - else: - # If parser was successfull there is no need to try - # others in the list for this mimetype - return - raise NoMIMETypeMatch('Parser MIME type list exhausted') - except KeyError: - raise NoMIMETypeMatch + for parser_class in cls._registry.get(document_page.document_version.mimetype, ()): + try: + parser = parser_class() + parser.process_document_page(document_page) + except ParserError: + # If parser raises error, try next parser in the list + pass + else: + # If parser was successfull there is no need to try + # others in the list for this mimetype + return def process_document_version(self, document_version): logger.info(