This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Unclear xpath caching for custom namespaces
Type: behavior Stage: resolved
Components: XML Versions: Python 3.3
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: eli.bendersky, scoder, valeriy.nov
Priority: normal Keywords:

Created on 2013-12-02 15:18 by valeriy.nov, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg205015 - (view) Author: Валерий (valeriy.nov) Date: 2013-12-02 15:18
Consider repeated executions of a code like this:
>tree = xml.etree.ElementTree.parse( full_name ) # many different files
>report_type = tree.getroot().attrib['Name'] # something changing
>tree.getroot().find( ".//t:Detail", {'t' : report_type} )

There is a _cache variable in \Lib\xml\etree\ElementPath.py:
>def iterfind(elem, path, namespaces=None):
>    // ...
>    try:
>        selector = _cache[path]
>    except KeyError:
>    // ...

In my code I use the same path (".//t:Detail"), so no KeyError exception is raised and cached (the same) value is used, but full path should be different ('.//{url_one}Detail', './/{url_two}Detail', etc) depending on namespaces dictionary.
msg205145 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2013-12-03 20:28
This is a duplicate of issue17011.
History
Date User Action Args
2022-04-11 14:57:54adminsetgithub: 64061
2013-12-06 17:38:49eric.araujosetstatus: open -> closed
resolution: duplicate
stage: resolved
2013-12-03 20:28:58scodersetmessages: + msg205145
2013-12-02 18:57:33pitrousetnosy: + scoder, eli.bendersky
2013-12-02 15:18:46valeriy.novcreate