[issue42893] Strange XPath search behavior of xml.etree.ElementTree.Element.find

2021-01-14 Thread robpats


robpats  added the comment:

Thanks for the pointer. I didn't notice this paragraph.
xml.etree.ElementTree.Element.find currently returns None if XPath expression 
is invalid or unsupported. I think it should also return None if position 
predicates are not preceded by a tag name. It would be even better to emit 
warnings or raise exceptions to indicate any errors.

--

___
Python tracker 
<https://bugs.python.org/issue42893>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42893] Strange XPath search behavior of xml.etree.ElementTree.Element.find

2021-01-11 Thread robpats


New submission from robpats :

Python 3.6.8 / 3.7.9 / 3.8.7

>>> import xml.etree.ElementTree
>>> e = xml.etree.ElementTree.fromstring('>> class="row"/>')
>>> list(e)
[, , 
, , 
, ]
>>> e.find("./div[1]")

>>> e.find("./div[2]")

>>> e.find("./div[3]")

>>> e.find("./hr[1]")

>>> e.find("./hr[2]")




# The following different from XPath implementation in Firefox
# https://developer.mozilla.org/en-US/docs/Web/XPath/Snippets

>>> list(e.iterfind("./*"))
[, , 
, , 
, ]
>>> e.find("./*[1]")

>>> e.find("./*[2]")
   <-- should be 'hr', same as 
e.find("./div[2]") instead of e[2]
>>> e.find("./*[3]")
   <-- same as e.find("./div[3]") instead 
of e[3]
>>> e.find("./*[4]")


>>> list(e.iterfind("./*[@class='row']"))
[, ]
>>> e.find("./*[@class='row'][1]")

>>> e.find("./*[@class='row'][2]")
>>> e.find("./*[@class='row'][3]")
   <--- cannot find element at [2] but 
found at [3]

--
components: Library (Lib)
messages: 384851
nosy: robpats
priority: normal
severity: normal
status: open
title: Strange XPath search behavior of xml.etree.ElementTree.Element.find
type: behavior
versions: Python 3.8

___
Python tracker 
<https://bugs.python.org/issue42893>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com