Hi again, Stefan Behnel wrote:
Andrey Tatarinov wrote:
On Thu, 2006-05-11 at 12:59 +0200, Stefan Behnel wrote:
are there any substantial differences in the ElementTree Path syntax with respect to an XPath subset that should keep us from having findall() etc. call XPath directly? I've already implemented it some time ago in branch xpath-find.
you can take a look.
Right, the Clark notation. From what I see in your implementation, that's basically the same as the etree.ETXPath wrapper for the XPath class.
So I'll check if we can replace it and throw _elementpath.py out. Depends on the performance, though. ETXPath also uses RegExps to split up the path expression.
there were no failed tests, as far as I remember.
Yeah, well, that's not the surest thing for something as complex as XPath. We don't test expressions, just the API. Maybe the ET self-tests help out here.
... and they do: ------------------------------------------ ********************************************************************** File "/home/me/source/Python/lxml/lxml-HEAD/selftest.py", line 224, in selftest.bad_find Failed example: elem.findall("/tag") Expected: Traceback (most recent call last): SyntaxError: cannot use absolute path on element Got: [] ********************************************************************** File "/home/me/source/Python/lxml/lxml-HEAD/selftest.py", line 227, in selftest.bad_find Failed example: elem.findall("../tag") Expected: Traceback (most recent call last): SyntaxError: unsupported path syntax (..) Got: [] ********************************************************************** File "/home/me/source/Python/lxml/lxml-HEAD/selftest.py", line 230, in selftest.bad_find Failed example: elem.findall("section//") Expected: Traceback (most recent call last): SyntaxError: path cannot end with // Got: Traceback (most recent call last): File "/home/me/source/Python/lxml/lxml-HEAD/src/doctest.py", line 1256, in __run compileflags, 1) in test.globs File "<doctest selftest.bad_find[3]>", line 1, in ? elem.findall("section//") File "etree.pyx", line 909, in etree._Element.findall File "xpath.pxi", line 215, in etree.ETXPath.__init__ File "xpath.pxi", line 171, in etree.XPath.__init__ File "xpath.pxi", line 65, in etree.XPathEvaluatorBase._raise_parse_error XPathSyntaxError: Error in xpath expression. ********************************************************************** File "/home/me/source/Python/lxml/lxml-HEAD/selftest.py", line 233, in selftest.bad_find Failed example: elem.findall("tag[tag]") Expected: Traceback (most recent call last): SyntaxError: expected path separator ([) Got: [] ********************************************************************** 1 items had failures: 4 of 5 in selftest.bad_find ------------------------------------------ That's a pretty good rate... :) Hmm, everything else passes, but those are gonna be hard to emulate without a real pre-parser (which would cost us performance for compat-only). XPath is just too powerful to strip it down easily... Guess we should just leave it as is for now. Calling _elementpath is sufficiently fast by now, writing our own parser is not worth it. Stefan