]> granicus.if.org Git - python/commitdiff
bpo-30485: Change the prefix for defining the default namespace in ElementPath from...
authorStefan Behnel <stefan_ml@behnel.de>
Thu, 18 Apr 2019 17:05:03 +0000 (19:05 +0200)
committerGitHub <noreply@github.com>
Thu, 18 Apr 2019 17:05:03 +0000 (19:05 +0200)
Doc/library/xml.etree.elementtree.rst
Lib/test/test_xml_etree.py
Lib/xml/etree/ElementPath.py
Misc/NEWS.d/next/Library/2019-04-13-23-42-33.bpo-30485.JHhjJS.rst

index c83e719e959a29ead23a05b288b1460e87d708ba..9e2c295867ca3a0398d113561c0bef3effa3d0dd 100644 (file)
@@ -764,7 +764,7 @@ Element Objects
       Finds the first subelement matching *match*.  *match* may be a tag name
       or a :ref:`path <elementtree-xpath>`.  Returns an element instance
       or ``None``.  *namespaces* is an optional mapping from namespace prefix
-      to full name.  Pass ``None`` as prefix to move all unprefixed tag names
+      to full name.  Pass ``''`` as prefix to move all unprefixed tag names
       in the expression into the given namespace.
 
 
@@ -773,7 +773,7 @@ Element Objects
       Finds all matching subelements, by tag name or
       :ref:`path <elementtree-xpath>`.  Returns a list containing all matching
       elements in document order.  *namespaces* is an optional mapping from
-      namespace prefix to full name.  Pass ``None`` as prefix to move all
+      namespace prefix to full name.  Pass ``''`` as prefix to move all
       unprefixed tag names in the expression into the given namespace.
 
 
@@ -784,7 +784,7 @@ Element Objects
       of the first matching element, or *default* if no element was found.
       Note that if the matching element has no text content an empty string
       is returned. *namespaces* is an optional mapping from namespace prefix
-      to full name.  Pass ``None`` as prefix to move all unprefixed tag names
+      to full name.  Pass ``''`` as prefix to move all unprefixed tag names
       in the expression into the given namespace.
 
 
index f5b118b079ee3b59c742c65cfc7655fce0a0c005..14ce32af802624181741bd9bf376aad5f896ee11 100644 (file)
@@ -2463,7 +2463,7 @@ class ElementFindTest(unittest.TestCase):
         nsmap = {'xx': 'Y'}
         self.assertEqual(len(root.findall(".//xx:b", namespaces=nsmap)), 1)
         self.assertEqual(len(root.findall(".//b", namespaces=nsmap)), 2)
-        nsmap = {'xx': 'X', None: 'Y'}
+        nsmap = {'xx': 'X', '': 'Y'}
         self.assertEqual(len(root.findall(".//xx:b", namespaces=nsmap)), 2)
         self.assertEqual(len(root.findall(".//b", namespaces=nsmap)), 1)
 
index 4d231a7df65677e503ccfdccae5bc1cf32f517f4..b670d58f3f01214960508aa238e10559267d23a4 100644 (file)
@@ -71,7 +71,7 @@ xpath_tokenizer_re = re.compile(
     )
 
 def xpath_tokenizer(pattern, namespaces=None):
-    default_namespace = namespaces.get(None) if namespaces else None
+    default_namespace = namespaces.get('') if namespaces else None
     for token in xpath_tokenizer_re.findall(pattern):
         tag = token[1]
         if tag and tag[0] != "{":
@@ -275,11 +275,7 @@ def iterfind(elem, path, namespaces=None):
 
     cache_key = (path,)
     if namespaces:
-        if None in namespaces:
-            cache_key += (namespaces[None],) + tuple(sorted(
-                item for item in namespaces.items() if item[0] is not None))
-        else:
-            cache_key += tuple(sorted(namespaces.items()))
+        cache_key += tuple(sorted(namespaces.items()))
 
     try:
         selector = _cache[cache_key]
index 6c82efd3e0092209718db98602940757d2696169..900edf8c7553559e9a403fad602ee0f243910e5a 100644 (file)
@@ -1,3 +1,3 @@
 Path expressions in xml.etree.ElementTree can now avoid explicit namespace
 prefixes for tags (or the "{namespace}tag" notation) by passing a default
-namespace with a 'None' prefix.
+namespace with an empty string prefix.