diff options
author | Eli Bendersky <eliben@gmail.com> | 2013-08-03 17:47:47 -0700 |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2013-08-03 17:47:47 -0700 |
commit | e8ddf63f48b5a75cb61105283f2dbb5bc8885f73 (patch) | |
tree | 965b4574d466d6b21d5913df8f5d70a1abdea84d /Lib/xml | |
parent | 0078eae1aaafb10714a27ec691f4adc338906280 (diff) | |
download | cpython-e8ddf63f48b5a75cb61105283f2dbb5bc8885f73.tar.gz |
Issue #17011: Fix caching of xpath path when namespaces are present.
Thanks to Stefan Behnel for the report and proposed solution & test.
Diffstat (limited to 'Lib/xml')
-rw-r--r-- | Lib/xml/etree/ElementPath.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/xml/etree/ElementPath.py b/Lib/xml/etree/ElementPath.py index 52e65f063d..e7015c7c61 100644 --- a/Lib/xml/etree/ElementPath.py +++ b/Lib/xml/etree/ElementPath.py @@ -246,10 +246,12 @@ class _SelectorContext: def iterfind(elem, path, namespaces=None): # compile selector pattern + cache_key = (path, None if namespaces is None + else tuple(sorted(namespaces.items()))) if path[-1:] == "/": path = path + "*" # implicit all (FIXME: keep this?) try: - selector = _cache[path] + selector = _cache[cache_key] except KeyError: if len(_cache) > 100: _cache.clear() @@ -269,7 +271,7 @@ def iterfind(elem, path, namespaces=None): token = next() except StopIteration: break - _cache[path] = selector + _cache[cache_key] = selector # execute selector pattern result = [elem] context = _SelectorContext(elem) |