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

use condition rather than try/catch

This commit is contained in:
林檎 2017-03-06 13:42:00 +08:00
parent 6e3d4877ed
commit 4dfa157161
2 changed files with 7 additions and 5 deletions

View File

@ -245,9 +245,9 @@ def get_valid_filename(value, replace_whitespace=True):
value=value.replace(u'ß',u'ss')
value = unicodedata.normalize('NFKD', value)
re_slugify = re.compile('[\W\s-]', re.UNICODE)
try:
value = str(re_slugify.sub('', value).strip())
except UnicodeEncodeError as e: #will exception on Python2.7
if type(value) is str: #Python3 str, Python2 unicode
value = re_slugify.sub('', value).strip()
else:
value = unicode(re_slugify.sub('', value).strip())
if replace_whitespace:
#*+:\"/<>? werden durch _ ersetzt

View File

@ -1052,8 +1052,10 @@ def stats():
stdin=subprocess.PIPE)
p.wait()
for lines in p.stdout.readlines():
if re.search('Amazon kindlegen\(', str(lines)):
versions['KindlegenVersion'] = str(lines)
if type(lines) is bytes:
lines = lines.decode('utf-8')
if re.search('Amazon kindlegen\(', lines):
versions['KindlegenVersion'] = lines
versions['PythonVersion'] = sys.version
versions['babel'] = babelVersion
versions['sqlalchemy'] = sqlalchemyVersion