summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-12-28 10:38:33 (GMT)
committerGeorg Brandl <georg@python.org>2010-12-28 10:38:33 (GMT)
commit90b20675bd042a3262642232f9d3e133e56a130c (patch)
treeaf001288fae979c7e718e572bcc86b68835e8343 /Lib
parentff52f76019816be0fb590a294486a33cf1ee93f7 (diff)
downloadcpython-90b20675bd042a3262642232f9d3e133e56a130c.zip
cpython-90b20675bd042a3262642232f9d3e133e56a130c.tar.gz
cpython-90b20675bd042a3262642232f9d3e133e56a130c.tar.bz2
#10777: fix iteration over dict keys while mutating the dict.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_xml_etree.py9
-rw-r--r--Lib/xml/etree/ElementTree.py2
2 files changed, 10 insertions, 1 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 08f7988..22fafa9 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -1841,6 +1841,15 @@ def check_issue6565():
"""
+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/')
+ """
+
# --------------------------------------------------------------------
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
index 53aa9e7..ba33879 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -1068,7 +1068,7 @@ _serialize = {
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