Remove the NoMimetype match exception. Not needed now that this is

a separate app from the OCR app.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2017-08-24 20:19:43 -04:00
parent 8b9e605e0b
commit 9e40bbbcdc
2 changed files with 23 additions and 39 deletions

View File

@@ -6,10 +6,3 @@ class ParserError(Exception):
Base exception for file parsers Base exception for file parsers
""" """
pass pass
class NoMIMETypeMatch(ParserError):
"""
There is no parser registered for the specified MIME type
"""
pass

View File

@@ -9,7 +9,7 @@ from django.utils.translation import ugettext_lazy as _
from common.utils import copyfile, fs_cleanup, mkstemp from common.utils import copyfile, fs_cleanup, mkstemp
from .exceptions import ParserError, NoMIMETypeMatch from .exceptions import ParserError
from .settings import setting_pdftotext_path from .settings import setting_pdftotext_path
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@@ -32,40 +32,31 @@ class Parser(object):
@classmethod @classmethod
def parse_document_version(cls, document_version): def parse_document_version(cls, document_version):
try: for parser_class in cls._registry.get(document_version.mimetype, ()):
for parser_class in cls._registry[document_version.mimetype]: try:
try: parser = parser_class()
parser = parser_class() parser.process_document_version(document_version)
parser.process_document_version(document_version) except ParserError:
except ParserError: # If parser raises error, try next parser in the list
# If parser raises error, try next parser in the list pass
pass else:
else: # If parser was successfull there is no need to try
# If parser was successfull there is no need to try # others in the list for this mimetype
# others in the list for this mimetype return
return
raise NoMIMETypeMatch('Parser MIME type list exhausted')
except KeyError:
raise NoMIMETypeMatch
@classmethod @classmethod
def parse_document_page(cls, document_page): def parse_document_page(cls, document_page):
try: for parser_class in cls._registry.get(document_page.document_version.mimetype, ()):
for parser_class in cls._registry[document_page.document_version.mimetype]: try:
try: parser = parser_class()
parser = parser_class() parser.process_document_page(document_page)
parser.process_document_page(document_page) except ParserError:
except ParserError: # If parser raises error, try next parser in the list
# If parser raises error, try next parser in the list pass
pass else:
else: # If parser was successfull there is no need to try
# If parser was successfull there is no need to try # others in the list for this mimetype
# others in the list for this mimetype return
return
raise NoMIMETypeMatch('Parser MIME type list exhausted')
except KeyError:
raise NoMIMETypeMatch
def process_document_version(self, document_version): def process_document_version(self, document_version):
logger.info( logger.info(