1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-25 09:30:31 +00:00

Fix except clause

except: will catch specific error.
This commit is contained in:
林檎 2017-03-06 11:44:54 +08:00
parent cf4816fc13
commit 0bc4f52783
4 changed files with 12 additions and 11 deletions

View File

@ -44,7 +44,7 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
try:#maybe description isn't present
comments = tree.xpath("//*[local-name() = 'description']/text()")[0]
epub_metadata['comments'] = comments
except:
except IndexError as e:
epub_metadata['comments'] = ""
for s in ['title', 'description', 'creator']:
@ -64,7 +64,7 @@ def get_epub_info(tmp_file_path, original_file_name, original_file_extension):
epub_metadata['languages'] = isoLanguages.get(part3=lang).name
else:
epub_metadata['languages'] = ""
except:
except IndexError as e:
epub_metadata['languages'] = ""
coversection = tree.xpath("/pkg:package/pkg:manifest/pkg:item[@id='cover-image']/@href", namespaces=ns)

View File

@ -5,9 +5,9 @@ from lxml import etree
import os
import uploader
try:
import StringIO
except:
from io import StringIO
except ImportError as e:
import StringIO
def get_fb2_info(tmp_file_path, original_file_extension):

View File

@ -14,15 +14,15 @@ import traceback
import re
import unicodedata
try:
from StringIO import StringIO
from email.MIMEBase import MIMEBase
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
except ImportError:
from io import StringIO
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
except ImportError as e:
from StringIO import StringIO
from email.MIMEBase import MIMEBase
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email import encoders
from email.generator import Generator
from email.utils import formatdate
@ -247,8 +247,9 @@ def get_valid_filename(value, replace_whitespace=True):
re_slugify = re.compile('[\W\s-]', re.UNICODE)
try:
value = str(re_slugify.sub('', value).strip())
except: #will exception on Python2.7
except UnicodeEncodeError as e: #will exception on Python2.7
value = unicode(re_slugify.sub('', value).strip())
raise
if replace_whitespace:
#*+:\"/<>? werden durch _ ersetzt
value = re.sub('[\*\+:\\\"/<>\?]+', u'_', value, flags=re.U)

View File

@ -53,7 +53,7 @@ try:
from urllib.parse import quote
from imp import reload
from past.builtins import xrange
except:
except ImportError as e:
from urllib import quote
try: