bpo-30485: Change the prefix for defining the default namespace in El… · python/cpython@e8113f5 (original) (raw)

4 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -764,7 +764,7 @@ Element Objects
764 764 Finds the first subelement matching *match*. *match* may be a tag name
765 765 or a :ref:`path <elementtree-xpath>`. Returns an element instance
766 766 or ``None``. *namespaces* is an optional mapping from namespace prefix
767 - to full name. Pass ``None`` as prefix to move all unprefixed tag names
767 + to full name. Pass ``''`` as prefix to move all unprefixed tag names
768 768 in the expression into the given namespace.
769 769
770 770
@@ -773,7 +773,7 @@ Element Objects
773 773 Finds all matching subelements, by tag name or
774 774 :ref:`path <elementtree-xpath>`. Returns a list containing all matching
775 775 elements in document order. *namespaces* is an optional mapping from
776 - namespace prefix to full name. Pass ``None`` as prefix to move all
776 + namespace prefix to full name. Pass ``''`` as prefix to move all
777 777 unprefixed tag names in the expression into the given namespace.
778 778
779 779
@@ -784,7 +784,7 @@ Element Objects
784 784 of the first matching element, or *default* if no element was found.
785 785 Note that if the matching element has no text content an empty string
786 786 is returned. *namespaces* is an optional mapping from namespace prefix
787 - to full name. Pass ``None`` as prefix to move all unprefixed tag names
787 + to full name. Pass ``''`` as prefix to move all unprefixed tag names
788 788 in the expression into the given namespace.
789 789
790 790
Original file line number Diff line number Diff line change
@@ -2463,7 +2463,7 @@ def test_findall_different_nsmaps(self):
2463 2463 nsmap = {'xx': 'Y'}
2464 2464 self.assertEqual(len(root.findall(".//xx:b", namespaces=nsmap)), 1)
2465 2465 self.assertEqual(len(root.findall(".//b", namespaces=nsmap)), 2)
2466 -nsmap = {'xx': 'X', None: 'Y'}
2466 +nsmap = {'xx': 'X', '': 'Y'}
2467 2467 self.assertEqual(len(root.findall(".//xx:b", namespaces=nsmap)), 2)
2468 2468 self.assertEqual(len(root.findall(".//b", namespaces=nsmap)), 1)
2469 2469
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@
71 71 )
72 72
73 73 def xpath_tokenizer(pattern, namespaces=None):
74 -default_namespace = namespaces.get(None) if namespaces else None
74 +default_namespace = namespaces.get('') if namespaces else None
75 75 for token in xpath_tokenizer_re.findall(pattern):
76 76 tag = token[1]
77 77 if tag and tag[0] != "{":
@@ -275,11 +275,7 @@ def iterfind(elem, path, namespaces=None):
275 275
276 276 cache_key = (path,)
277 277 if namespaces:
278 -if None in namespaces:
279 -cache_key += (namespaces[None],) + tuple(sorted(
280 -item for item in namespaces.items() if item[0] is not None))
281 -else:
282 -cache_key += tuple(sorted(namespaces.items()))
278 +cache_key += tuple(sorted(namespaces.items()))
283 279
284 280 try:
285 281 selector = _cache[cache_key]
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
1 1 Path expressions in xml.etree.ElementTree can now avoid explicit namespace
2 2 prefixes for tags (or the "{namespace}tag" notation) by passing a default
3 -namespace with a 'None' prefix.
3 +namespace with an empty string prefix.