Updated the python conveter backend to use the new mimetype_only argument of get_mimetype and to accept a mimetype argument from the caller thus skipping mimetype detection at all resulting in another slight speedup

This commit is contained in:
Roberto Rosario
2011-11-21 05:45:55 -04:00
parent 7139989649
commit eacd7837b2

View File

@@ -25,7 +25,7 @@ class ConverterClass(ConverterBase):
def get_page_count(self, input_filepath):
page_count = 1
mimetype, encoding = get_mimetype(open(input_filepath, 'rb'), input_filepath)
mimetype, encoding = get_mimetype(open(input_filepath, 'rb'), input_filepath, mimetype_only=True)
if mimetype == 'application/pdf':
# If file is a PDF open it with slate to determine the page
# count
@@ -48,9 +48,12 @@ class ConverterClass(ConverterBase):
return page_count
def convert_file(self, input_filepath, output_filepath, transformations=None, page=DEFAULT_PAGE_NUMBER, file_format=DEFAULT_FILE_FORMAT):
def convert_file(self, input_filepath, output_filepath, transformations=None, page=DEFAULT_PAGE_NUMBER, file_format=DEFAULT_FILE_FORMAT, **kwargs):
tmpfile = None
mimetype, encoding = get_mimetype(open(input_filepath, 'rb'), input_filepath)
mimetype = kwargs.get('mimetype', None)
if not mimetype:
mimetype, encoding = get_mimetype(open(input_filepath, 'rb'), input_filepath, mimetype_only=True)
if mimetype == 'application/pdf' and USE_GHOSTSCRIPT:
# If file is a PDF open it with ghostscript and convert it to
# TIFF