Reworked to return None rather than using exceptions as per Raoul's request

This commit is contained in:
phill-ridout 2013-02-03 20:02:58 +00:00
parent 635b207fb0
commit 59c6e00bf1
4 changed files with 15 additions and 24 deletions

View File

@ -584,7 +584,7 @@ def strip_rtf(text, default_encoding=None):
if encoding:
out.append(chr(charcode).decode(encoding))
else:
raise Exception(u'user_canceled')
return None
except UnicodeDecodeError:
failed = True
else:

View File

@ -180,13 +180,10 @@ class EasyWorshipSongImport(SongImport):
self.addAuthor(author_name.strip())
if words:
# Format the lyrics
try:
words, self.encoding = strip_rtf(words, self.encoding)
except Exception as info:
if unicode(info) == u'user_canceled':
return
else:
raise
words = strip_rtf(words, self.encoding)
if words is None:
return
words, self.encoding = words
verse_type = VerseType.Tags[VerseType.Verse]
for verse in SLIDE_BREAK_REGEX.split(words):
verse = verse.strip()

View File

@ -109,14 +109,11 @@ class SongProImport(SongImport):
self.finish()
return
if u'rtf1' in text:
try:
text, self.encoding = strip_rtf(text, self.encoding)
text = text.rstrip()
except Exception as info:
if unicode(info) == u'user_canceled':
return
else:
raise
text = strip_rtf(text, self.encoding)
if text is None:
return
text, self.encoding = text
text = text.rstrip()
if not text:
return
if tag == u'A':

View File

@ -150,14 +150,11 @@ class SundayPlusImport(SongImport):
verse_type = HOTKEY_TO_VERSE_TYPE[value]
if name == 'rtf':
value = self.unescape(value)
try:
verse, self.encoding = strip_rtf(value, self.encoding)
lines = verse.strip().split('\n')
except Exception as info:
if unicode(info) == u'user_canceled':
return
else:
raise
verse = strip_rtf(value, self.encoding)
if verse is None:
return
verse, self.encoding = verse
lines = verse.strip().split('\n')
# If any line inside any verse contains CCLI or
# only Public Domain, we treat this as special data:
# we remove that line and add data to specific field.