[lxml-dev] ElementTree.find does not accept QName objects.

Since I was the one that complained about the find method on Elements not accepting QNames, it's probably not surprising that I expected them to work with the ElementTree find method as well. Instead an unsliceable error is thrown, due to the value being expected to be a string:
Though using e.getroot( ).find is working fine as a workaround for me. -- John Krukoff <jkrukoff@ltgc.com> Land Title Guarantee Company

On Sat, 2008-03-29 at 11:42 +0100, Stefan Behnel wrote:
Thanks for your always quick response. Yeah, ET has the same issue, but then it doesn't accept QNames for element.find either. Only one of many reasons I gave up on ET compatibility a long time ago. -- John Krukoff <jkrukoff@ltgc.com> Land Title Guarantee Company

Okay, that's weird. I knew that I'd been able to use QName's with ET in that past, but when I double checked I found that it didn't work for me. It looks like I just managed to hit some magic special case in ET to make this work at all, as this works: Python 2.5.1 (r251:54863, Jan 8 2008, 15:02:32) [GCC 4.1.2 (Gentoo 4.1.2)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
But this doesn't: Python 2.5.1 (r251:54863, Jan 8 2008, 15:02:32) [GCC 4.1.2 (Gentoo 4.1.2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. line 327, in find return ElementPath.find(self, path) File "/usr/lib/python2.5/site-packages/elementtree/ElementPath.py", line 183, in find return _compile(path).find(element) File "/usr/lib/python2.5/site-packages/elementtree/ElementPath.py", line 173, in _compile p = Path(path) File "/usr/lib/python2.5/site-packages/elementtree/ElementPath.py", line 69, in __init__ tokens = xpath_tokenizer(path) TypeError: expected string or buffer It looks like it only works when ET.find has already been called with the string value of the same name that a following QName find specifies. Some internal caching, perhaps? In any case, it does look like accepting QNames at all is a bug in ET, or at least an accident. Don't know what that means for lxml, but it would seem to me that strict compatibility would mean that find should be restricted to strings. As for my use case, I suppose I can always just wrap all my find parameters with str to make it work. On Sat, 2008-03-29 at 11:42 +0100, Stefan Behnel wrote:
-- John Krukoff <jkrukoff@ltgc.com> Land Title Guarantee Company

On Sat, 2008-03-29 at 11:42 +0100, Stefan Behnel wrote:
Thanks for your always quick response. Yeah, ET has the same issue, but then it doesn't accept QNames for element.find either. Only one of many reasons I gave up on ET compatibility a long time ago. -- John Krukoff <jkrukoff@ltgc.com> Land Title Guarantee Company

Okay, that's weird. I knew that I'd been able to use QName's with ET in that past, but when I double checked I found that it didn't work for me. It looks like I just managed to hit some magic special case in ET to make this work at all, as this works: Python 2.5.1 (r251:54863, Jan 8 2008, 15:02:32) [GCC 4.1.2 (Gentoo 4.1.2)] on linux2 Type "help", "copyright", "credits" or "license" for more information.
But this doesn't: Python 2.5.1 (r251:54863, Jan 8 2008, 15:02:32) [GCC 4.1.2 (Gentoo 4.1.2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. line 327, in find return ElementPath.find(self, path) File "/usr/lib/python2.5/site-packages/elementtree/ElementPath.py", line 183, in find return _compile(path).find(element) File "/usr/lib/python2.5/site-packages/elementtree/ElementPath.py", line 173, in _compile p = Path(path) File "/usr/lib/python2.5/site-packages/elementtree/ElementPath.py", line 69, in __init__ tokens = xpath_tokenizer(path) TypeError: expected string or buffer It looks like it only works when ET.find has already been called with the string value of the same name that a following QName find specifies. Some internal caching, perhaps? In any case, it does look like accepting QNames at all is a bug in ET, or at least an accident. Don't know what that means for lxml, but it would seem to me that strict compatibility would mean that find should be restricted to strings. As for my use case, I suppose I can always just wrap all my find parameters with str to make it work. On Sat, 2008-03-29 at 11:42 +0100, Stefan Behnel wrote:
-- John Krukoff <jkrukoff@ltgc.com> Land Title Guarantee Company
participants (2)
-
John Krukoff
-
Stefan Behnel