[Python-checkins] r87526 - in python/branches/py3k: Lib/test/test_xml_etree.py Lib/xml/etree/ElementTree.py Misc/NEWS

georg.brandl python-checkins at python.org
Tue Dec 28 11:38:33 CET 2010


Author: georg.brandl
Date: Tue Dec 28 11:38:33 2010
New Revision: 87526

Log:
#10777: fix iteration over dict keys while mutating the dict.

Modified:
   python/branches/py3k/Lib/test/test_xml_etree.py
   python/branches/py3k/Lib/xml/etree/ElementTree.py
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Lib/test/test_xml_etree.py
==============================================================================
--- python/branches/py3k/Lib/test/test_xml_etree.py	(original)
+++ python/branches/py3k/Lib/test/test_xml_etree.py	Tue Dec 28 11:38:33 2010
@@ -1841,6 +1841,15 @@
 
     """
 
+def check_issue10777():
+    """
+    Registering a namespace twice caused a "dictionary changed size during
+    iteration" bug.
+
+    >>> ET.register_namespace('test10777', 'http://myuri/')
+    >>> ET.register_namespace('test10777', 'http://myuri/')
+    """
+
 # --------------------------------------------------------------------
 
 

Modified: python/branches/py3k/Lib/xml/etree/ElementTree.py
==============================================================================
--- python/branches/py3k/Lib/xml/etree/ElementTree.py	(original)
+++ python/branches/py3k/Lib/xml/etree/ElementTree.py	Tue Dec 28 11:38:33 2010
@@ -1068,7 +1068,7 @@
 def register_namespace(prefix, uri):
     if re.match("ns\d+$", prefix):
         raise ValueError("Prefix format reserved for internal use")
-    for k, v in _namespace_map.items():
+    for k, v in list(_namespace_map.items()):
         if k == uri or v == prefix:
             del _namespace_map[k]
     _namespace_map[uri] = prefix

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Tue Dec 28 11:38:33 2010
@@ -18,6 +18,9 @@
 Library
 -------
 
+- Issue #10777: Fix "dictionary changed size during iteration" bug in
+  ElementTree register_namespace().
+
 - Issue #10626: test_logging now preserves logger disabled states.
 
 - Issue #10774: test_logging now removes temp files created during tests.


More information about the Python-checkins mailing list