Code style cleanups
Add keyword arguments. Sort arguments and models. Move literals to their own module. Prepend handler_ to signal handlers. Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -23,12 +23,18 @@ class Parser(object):
|
||||
_registry = {}
|
||||
|
||||
@classmethod
|
||||
def register(cls, mimetypes, parser_classes):
|
||||
for mimetype in mimetypes:
|
||||
for parser_class in parser_classes:
|
||||
cls._registry.setdefault(
|
||||
mimetype, []
|
||||
).append(parser_class)
|
||||
def parse_document_page(cls, document_page):
|
||||
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
|
||||
|
||||
@classmethod
|
||||
def parse_document_version(cls, document_version):
|
||||
@@ -45,18 +51,12 @@ class Parser(object):
|
||||
return
|
||||
|
||||
@classmethod
|
||||
def parse_document_page(cls, document_page):
|
||||
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 register(cls, mimetypes, parser_classes):
|
||||
for mimetype in mimetypes:
|
||||
for parser_class in parser_classes:
|
||||
cls._registry.setdefault(
|
||||
mimetype, []
|
||||
).append(parser_class)
|
||||
|
||||
def process_document_version(self, document_version):
|
||||
logger.info(
|
||||
|
||||
Reference in New Issue
Block a user