From 6c82307975430086c480d1f46f63d484729ff73a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 18 Apr 2014 21:50:28 +0530 Subject: [PATCH] Import dictionary: Fix import of some .oxt files failing if their xcu manifest use a different syntax --- src/calibre/spell/import_from.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/calibre/spell/import_from.py b/src/calibre/spell/import_from.py index 683bbd0b27..19f6ee73fa 100644 --- a/src/calibre/spell/import_from.py +++ b/src/calibre/spell/import_from.py @@ -28,7 +28,13 @@ def parse_xcu(raw, origin='%origin%'): root = etree.fromstring(raw) for node in XPath('//prop[@oor:name="Format"]/value[text()="DICT_SPELL"]/../..')(root): - paths = ''.join(XPath('descendant::prop[@oor:name="Locations"]/value/text()')(node)).replace('%origin%', origin).split() + value = XPath('descendant::prop[@oor:name="Locations"]/value')(node) + if len(value[0]) == 0: + # The value node has no children, use its text + paths = ''.join(XPath('descendant::prop[@oor:name="Locations"]/value/text()')(node)).replace('%origin%', origin).split() + else: + # Use the text of the value nodes children + paths = [c.text.replace('%origin%', origin) for v in value for c in v.iterchildren('*') if c.text] aff, dic = paths if paths[0].endswith('.aff') else reversed(paths) locales = ''.join(XPath('descendant::prop[@oor:name="Locales"]/value/text()')(node)).split() ans[(dic, aff)] = locales