use condition rather than try/catch

pull/144/head
林檎 7 years ago
parent 6e3d4877ed
commit 4dfa157161

@ -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

@ -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

Loading…
Cancel
Save