mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Issue #17011: Fix caching of xpath path when namespaces are present.
Thanks to Stefan Behnel for the report and proposed solution & test.
This commit is contained in:
parent
3ceaff0777
commit
2acc525a97
2 changed files with 18 additions and 2 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue