From ced5676aa16f6d92a6702bb64587151288f06f1d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 5 Jun 2013 14:02:29 +0530 Subject: [PATCH] DOCX: Remove dependency on lxml > 3 --- src/calibre/ebooks/docx/names.py | 5 ++--- src/calibre/ebooks/docx/to_html.py | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/calibre/ebooks/docx/names.py b/src/calibre/ebooks/docx/names.py index 0f4e6155b1..db033e6fd5 100644 --- a/src/calibre/ebooks/docx/names.py +++ b/src/calibre/ebooks/docx/names.py @@ -7,7 +7,6 @@ __license__ = 'GPL v3' __copyright__ = '2013, Kovid Goyal ' import re -from future_builtins import map from lxml.etree import XPath as X @@ -99,7 +98,7 @@ def generate_anchor(name, existing): return y def children(elem, *args): - return elem.iterchildren(*map(expand, args)) + return XPath('|'.join('child::%s' % a for a in args))(elem) def descendants(elem, *args): - return elem.iterdescendants(*map(expand, args)) + return XPath('|'.join('descendant::%s' % a for a in args))(elem) diff --git a/src/calibre/ebooks/docx/to_html.py b/src/calibre/ebooks/docx/to_html.py index 172af69601..e2c81edadb 100644 --- a/src/calibre/ebooks/docx/to_html.py +++ b/src/calibre/ebooks/docx/to_html.py @@ -16,7 +16,7 @@ from lxml.html.builder import ( from calibre.ebooks.docx.container import DOCX, fromstring from calibre.ebooks.docx.names import ( XPath, is_tag, XML, STYLES, NUMBERING, FONTS, get, generate_anchor, - descendants, ancestor, FOOTNOTES, ENDNOTES) + descendants, ancestor, FOOTNOTES, ENDNOTES, children) from calibre.ebooks.docx.styles import Styles, inherit, PageProperties from calibre.ebooks.docx.numbering import Numbering from calibre.ebooks.docx.fonts import Fonts @@ -148,7 +148,7 @@ class Convert(object): html_obj.set('class', cls) if notes_header is not None: - for h in self.body.iterchildren('h1', 'h2', 'h3'): + for h in children(self.body, 'h1', 'h2', 'h3'): notes_header.tag = h.tag cls = h.get('class', None) if cls and cls != 'notes-header': @@ -262,7 +262,7 @@ class Convert(object): elem.set('id', ans) return ans - for item in root.iterdescendants(*headings): + for item in descendants(root, *headings): lvl = plvl = item_level_map.get(item, None) if lvl is None: continue