Fixes bug1095699 by rasing an error when the user cancels the codepage selection dialog.

This commit is contained in:
phill-ridout 2013-02-03 17:13:01 +00:00
parent 8840df2fb2
commit 635b207fb0
4 changed files with 27 additions and 6 deletions

View File

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

View File

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

View File

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

View File

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