Renamed the exception UnknownFormat to UnkownFileFormat and updated all

backends get_page_count method to raise it, having the api's get_page_count
function decide how to handle the exception
This commit is contained in:
Roberto Rosario
2011-08-05 03:24:01 -04:00
parent eaea853391
commit cd0b1577a7
7 changed files with 25 additions and 25 deletions
@@ -3,7 +3,7 @@ import re
from converter.conf.settings import GM_PATH
from converter.conf.settings import GM_SETTINGS
from converter.exceptions import ConvertError, UnknownFormat, \
from converter.exceptions import ConvertError, UnknownFileFormat, \
IdentifyError
from converter.backends import ConverterBase
from converter.literals import TRANSFORMATION_RESIZE, \
@@ -79,7 +79,7 @@ class ConverterClass(ConverterBase):
error_line = proc.stderr.readline()
if (CONVERTER_ERROR_STRING_NO_DECODER in error_line) or (CONVERTER_ERROR_STARTS_WITH in error_line):
#Try to determine from error message which class of error is it
raise UnknownFormat
raise UnknownFileFormat
else:
raise ConvertError(error_line)
@@ -116,6 +116,5 @@ class ConverterClass(ConverterBase):
def get_page_count(self, input_filepath):
try:
return len(self.identify_file(unicode(input_filepath)).splitlines())
except:
#TODO: send to other page number identifying program
return 1
except IdentifyError:
raise UnknownFileFormat
+4 -5
View File
@@ -3,7 +3,7 @@ import re
from converter.conf.settings import IM_IDENTIFY_PATH
from converter.conf.settings import IM_CONVERT_PATH
from converter.exceptions import ConvertError, UnknownFormat, \
from converter.exceptions import ConvertError, UnknownFileFormat, \
IdentifyError
from converter.backends import ConverterBase
from converter.literals import TRANSFORMATION_RESIZE, \
@@ -75,7 +75,7 @@ class ConverterClass(ConverterBase):
error_line = proc.stderr.readline()
if CONVERTER_ERROR_STRING_NO_DECODER in error_line:
#Try to determine from error message which class of error is it
raise UnknownFormat
raise UnknownFileFormat
else:
raise ConvertError(error_line)
@@ -114,6 +114,5 @@ class ConverterClass(ConverterBase):
def get_page_count(self, input_filepath):
try:
return len(self.identify_file(unicode(input_filepath)).splitlines())
except:
#TODO: send to other page number identifying program
return 1
except IdentifyError:
raise UnknownFileFormat
+3 -5
View File
@@ -14,7 +14,7 @@ from django.utils.translation import ugettext_lazy as _
from mimetype.api import get_mimetype
from converter.exceptions import ConvertError, UnknownFormat, IdentifyError
from converter.exceptions import ConvertError, UnknownFileFormat, IdentifyError
from converter.backends import ConverterBase
from converter.literals import TRANSFORMATION_RESIZE, \
TRANSFORMATION_ROTATE, TRANSFORMATION_ZOOM
@@ -38,9 +38,7 @@ class ConverterClass(ConverterBase):
try:
im = Image.open(input_filepath)
except IOError: #cannot identify image file
# Return a page count of 1, to atleast allow the document
# to be created
return 1
return UnknownFileFormat
try:
while 1:
@@ -87,7 +85,7 @@ class ConverterClass(ConverterBase):
try:
im = Image.open(input_filepath)
except Exception: # Python Imaging Library doesn't recognize it as an image
raise UnknownFormat
raise UnknownFileFormat
finally:
if tmpfile:
cleanup(tmpfile)