# HG changeset patch # User Goffi # Date 1483465910 -3600 # Node ID 70f23bc7859bd7158acd55989aaaf9e363e9283c # Parent 2c31ddf633e56fb61d8862de26cd0b8b8e61a526 core (xml_tools): fixed findAll - names and namespases arguments haven been inverted to be in the same order as for domish.Element.elements - fixed bad copy of elements in recursions - check if childrens are IElements - namespaces and names can now be basestrings instead of iterables diff -r 2c31ddf633e5 -r 70f23bc7859b src/plugins/plugin_blog_import.py --- a/src/plugins/plugin_blog_import.py Sun Jan 01 16:39:26 2017 +0100 +++ b/src/plugins/plugin_blog_import.py Tue Jan 03 18:51:50 2017 +0100 @@ -282,7 +282,7 @@ tmp_dir = tempfile.mkdtemp() try: # TODO: would be nice to also update the hyperlinks to these images, e.g. when you have - for img_elt in xml_tools.findAll(top_elt, ['img']): + for img_elt in xml_tools.findAll(top_elt, names=[u'img']): yield self.imgFilters(client, img_elt, options, opt_host, tmp_dir) finally: os.rmdir(tmp_dir) # XXX: tmp_dir should be empty, or something went wrong diff -r 2c31ddf633e5 -r 70f23bc7859b src/tools/xml_tools.py --- a/src/tools/xml_tools.py Sun Jan 01 16:39:26 2017 +0100 +++ b/src/tools/xml_tools.py Tue Jan 03 18:51:50 2017 +0100 @@ -1405,19 +1405,25 @@ data.append(child.wholeText) return u"".join(data) -def findAll(elt, names=None, namespaces=None): +def findAll(elt, namespaces=None, names=None, ): """Find child element at any depth matching criteria @param elt(domish.Element): top parent of the elements to find - @param names(iterable, None): names to match + @param names(iterable[unicode], basestring, None): names to match None to accept every names - @param namespace(unicode): URIs to match + @param namespace(iterable[unicode], basestring, None): URIs to match None to accept every namespaces + @return ((G)domish.Element): found elements """ + if isinstance(namespaces, basestring): + namespaces=tuple((namespaces,)) + if isinstance(names, basestring): + names=tuple((names,)) for child in elt.elements(): - if ((not names or child.name in names) and + if (domish.IElement.providedBy(child) and + (not names or child.name in names) and (not namespaces or child.uri in namespaces)): yield child - for found in findAll(child, names): + for found in findAll(child, namespaces, names): yield found