After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 554857 - Add a better XPath engine on top ET
Add a better XPath engine on top ET
Status: RESOLVED OBSOLETE
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2008-10-03 13:32 UTC by Johan (not receiving bugmail) Dahlin
Modified: 2015-02-07 16:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
use elementpath (6.31 KB, patch)
2008-10-07 17:34 UTC, Colin Walters
needs-work Details | Review

Description Johan (not receiving bugmail) Dahlin 2008-10-03 13:32:45 UTC
Our current XPath engine (minixpath) does not support attributes.
ElementTree 1.3 supports attributes, unfortunately it's only available in
Python 2.6 or newer. Until we can depend on Python 2.6 we should just
include its xpath implementation in our tree.

The implementation can be found here, it's one file and self contained:

http://svn.effbot.org/public/elementtree-1.3/elementtree/ElementPath.py
Comment 1 Colin Walters 2008-10-07 17:34:03 UTC
Created attachment 120138 [details] [review]
use elementpath
Comment 2 Johan (not receiving bugmail) Dahlin 2008-10-07 18:10:28 UTC
Comment on attachment 120138 [details] [review]
use elementpath

>diff --git a/tests/Makefile.am b/tests/Makefile.am

>+	@find $(top_srcdir)/giscanner -name \*.py | grep -v ElementPath | sort | uniq | xargs $(PYTHON) $(top_srcdir)/misc
>+	@find $(top_srcdir)/giscanner -name \*.py | grep -v ElementPath | sort | uniq | xargs $(PYTHON) $(top_srcdir)/misc

I'd prefer to just make ElementPath.py pep8/pyflakes error free instead.

>+import giscanner.ElementPath as ElementPath

This is the same as, which is easier to read:

from giscanner import ElementPath

A comment would probably make sense here too:

# Import a local copy of ElementPath.py from ElementTree 1.3 which
# supports xpath attribute matching. Remove this when we can
# add a hard dependency on Python 2.6.

>+def xpath_assert(node, path, attribs=[]):

attribs=[] is always a bug. Since it'll only be created once.
Never initialize default arguments to mutable types, instead just
set it to None and conditionally create a list.
Also, judging by the code below it should probably be an empty
dictionary and not a list.

>+    elt = ElementPath.find(node, path)
>+    if elt is None:
>+        raise AssertionError("Failed to find %r" % (path, ))
>+    for (name, expvalue) in attribs:
>+        value = elt.attrib.get(name)
>+        if not value:
>+            raise AssertionError("Failed to find attibute %r" +
>+                                 "in node %r" % (name, elt, ))
>+        if value != expvalue:
>+            raise AssertionError("Attibute %r in node %r has " +
>+                                 "unexpected value %r" % (name, elt, expvalue))

s/attrbute/attribute/

Don't you need to update any callsites for xpath_assert?
Comment 3 Colin Walters 2008-10-09 01:02:14 UTC
This one turns out to be harder than it looked, or at least more annoying because we'll have to prefix every element in the parsed xpath expression with 
{http://www.gtk.org/introspection/core/1.0} which is a lot less convenient.

Let's punt on this for now - I think ElementTree needs work to be convenient to use with XML namespaces.
Comment 4 Johan (not receiving bugmail) Dahlin 2008-10-22 07:43:21 UTC
Maybe we could add a layer on top of ElementTree's xpath engine to make the syntax for specifying xml namespaces a bit nicer.
For instance, replacing {C} with {http://www.gtk.org/introspection/core/1.0}.
Comment 5 Johan (not receiving bugmail) Dahlin 2010-09-06 04:51:14 UTC
We're not using xpath any more, so I'm closing this.
Comment 6 André Klapper 2015-02-07 16:48:33 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]