From 9bb44184877d65e1ccd3b7ad05a63762019536c2 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Sun, 17 Jun 2012 14:57:35 +0100 Subject: [PATCH 1/2] A fix for issue 507. http://support.openlp.org/issues/507 The opensong database file contained verses containing sub-elements such as tags. lxml considders the text of an element up until the first sub element. --- openlp/plugins/bibles/lib/opensong.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/opensong.py index 856e9057e..b6c6008a9 100644 --- a/openlp/plugins/bibles/lib/opensong.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -26,7 +26,7 @@ ############################################################################### import logging -from lxml import objectify +from lxml import objectify, etree from openlp.core.lib import Receiver, translate from openlp.plugins.bibles.lib.db import BibleDB, BiblesResourcesDB @@ -46,6 +46,17 @@ class OpenSongBible(BibleDB): BibleDB.__init__(self, parent, **kwargs) self.filename = kwargs['filename'] + def get_text(self, element): + verse_text = u'' + if element.text: + verse_text = element.text + for sub_element in element.iterchildren(): + verse_text += self.get_text(sub_element) + if element.tail: + verse_text += element.tail + return verse_text + + def do_import(self, bible_name=None): """ Loads a Bible from file. @@ -89,7 +100,7 @@ class OpenSongBible(BibleDB): db_book.id, int(chapter.attrib[u'n'].split()[-1]), int(verse.attrib[u'n']), - unicode(verse.text)) + unicode(self.get_text(verse))) self.wizard.incrementProgressBar(unicode(translate( 'BiblesPlugin.Opensong', 'Importing %s %s...', 'Importing ...')) % From 0e363942561e5b83ef8b067ff7c7d088c8a9cec0 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Mon, 18 Jun 2012 17:37:03 +0100 Subject: [PATCH 2/2] Removed unused import, added doc string and removed double new line. --- openlp/plugins/bibles/lib/opensong.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/bibles/lib/opensong.py b/openlp/plugins/bibles/lib/opensong.py index b6c6008a9..33c7f610e 100644 --- a/openlp/plugins/bibles/lib/opensong.py +++ b/openlp/plugins/bibles/lib/opensong.py @@ -26,7 +26,7 @@ ############################################################################### import logging -from lxml import objectify, etree +from lxml import objectify from openlp.core.lib import Receiver, translate from openlp.plugins.bibles.lib.db import BibleDB, BiblesResourcesDB @@ -47,6 +47,12 @@ class OpenSongBible(BibleDB): self.filename = kwargs['filename'] def get_text(self, element): + """ + Recursively get all text in an objectify element and its child elements. + + ``element`` + An objectify element to get the text from + """ verse_text = u'' if element.text: verse_text = element.text @@ -54,8 +60,7 @@ class OpenSongBible(BibleDB): verse_text += self.get_text(sub_element) if element.tail: verse_text += element.tail - return verse_text - + return verse_text def do_import(self, bible_name=None): """