mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-02-09 12:55:23 +01:00
Allow passing ElementTree to Select()
This commit is contained in:
parent
ee214d6df5
commit
3c8984d2a5
1 changed files with 3 additions and 1 deletions
|
|
@ -125,6 +125,8 @@ class Select(object):
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, root, default_lang=None, dispatch_map=None, trace=False):
|
def __init__(self, root, default_lang=None, dispatch_map=None, trace=False):
|
||||||
|
if hasattr(root, 'getroot'):
|
||||||
|
root = root.getroot()
|
||||||
self.root = root
|
self.root = root
|
||||||
self.dispatch_map = dispatch_map or default_dispatch_map
|
self.dispatch_map = dispatch_map or default_dispatch_map
|
||||||
self.invalidate_caches()
|
self.invalidate_caches()
|
||||||
|
|
@ -568,4 +570,4 @@ def select_empty(cache, elem):
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
root = etree.fromstring('<body xmlns="xxx" xml:lang="en"><p id="p" class="one two" lang="fr"><a id="a"/><b/><c/><d/></p></body>')
|
root = etree.fromstring('<body xmlns="xxx" xml:lang="en"><p id="p" class="one two" lang="fr"><a id="a"/><b/><c/><d/></p></body>')
|
||||||
select = Select(root, trace=True)
|
select = Select(root, trace=True)
|
||||||
pprint(list(select('p *:root')))
|
pprint(list(select('p')))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue