summaryrefslogtreecommitdiffstats
path: root/Lib/xml
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2019-05-09 05:22:47 (GMT)
committerGitHub <noreply@github.com>2019-05-09 05:22:47 (GMT)
commit88db8bd0648588c67eeab16d0bc72ec5c206e3ad (patch)
tree2fa2a294a671bd7013649a8a0ca972ff3c64c48a /Lib/xml
parent3aca40d3cb4b9b6741cf3073d71fbfc682cab96d (diff)
downloadcpython-88db8bd0648588c67eeab16d0bc72ec5c206e3ad.zip
cpython-88db8bd0648588c67eeab16d0bc72ec5c206e3ad.tar.gz
cpython-88db8bd0648588c67eeab16d0bc72ec5c206e3ad.tar.bz2
bpo-36831: Do not apply default namespace to unprefixed attributes in ElementPath. (#13201)
Also provide better grouping of the tokenizer tests.
Diffstat (limited to 'Lib/xml')
-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:] == '}*'