summaryrefslogtreecommitdiffstats
path: root/Lib/xml/etree/ElementPath.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/xml/etree/ElementPath.py')
-rw-r--r--Lib/xml/etree/ElementPath.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/xml/etree/ElementPath.py b/Lib/xml/etree/ElementPath.py
index cfe72f2..d318e65 100644
--- a/Lib/xml/etree/ElementPath.py
+++ b/Lib/xml/etree/ElementPath.py
@@ -72,23 +72,27 @@ xpath_tokenizer_re = re.compile(
def xpath_tokenizer(pattern, namespaces=None):
default_namespace = namespaces.get('') if namespaces else None
+ parsing_attribute = False
for token in xpath_tokenizer_re.findall(pattern):
- tag = token[1]
+ ttype, tag = token
if tag and tag[0] != "{":
if ":" in tag:
prefix, uri = tag.split(":", 1)
try:
if not namespaces:
raise KeyError
- yield token[0], "{%s}%s" % (namespaces[prefix], uri)
+ yield ttype, "{%s}%s" % (namespaces[prefix], uri)
except KeyError:
raise SyntaxError("prefix %r not found in prefix map" % prefix) from None
- elif default_namespace:
- yield token[0], "{%s}%s" % (default_namespace, tag)
+ elif default_namespace and not parsing_attribute:
+ yield ttype, "{%s}%s" % (default_namespace, tag)
else:
yield token
+ parsing_attribute = False
else:
yield token
+ parsing_attribute = ttype == '@'
+
def get_parent_map(context):
parent_map = context.parent_map
@@ -100,7 +104,6 @@ def get_parent_map(context):
return parent_map
-
def _is_wildcard_tag(tag):
return tag[:3] == '{*}' or tag[-2:] == '}*'