Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 861fd6f

Browse files
committed
Fix xml.dom.minidom so it works again after the dict views introduction.
There are some methods in minidom that return dict.keys() directly. There were left alone since the tests passed without touching them, but it might be prudent to just wrap them in a 'list' call to be safe for people expecting a list.
1 parent ecca313 commit 861fd6f

3 files changed

Lines changed: 8 additions & 12 deletions

File tree

BROKEN

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
test_bsddb test_bsddb3 test_compile test_dumbdbm
2-
test_importhooks test_iter test_iterlen test_minidom
2+
test_importhooks test_iter test_iterlen

Lib/test/test_minidom.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,8 @@ def _setupCloneElement(deep):
565565
def _testCloneElementCopiesAttributes(e1, e2, test):
566566
attrs1 = e1.attributes
567567
attrs2 = e2.attributes
568-
keys1 = attrs1.keys()
569-
keys2 = attrs2.keys()
570-
keys1.sort()
571-
keys2.sort()
568+
keys1 = sorted(attrs1.keys())
569+
keys2 = sorted(attrs2.keys())
572570
confirm(keys1 == keys2, "clone of element has same attribute keys")
573571
for i in range(len(keys1)):
574572
a1 = attrs1.item(i)
@@ -1351,8 +1349,7 @@ def testPickledDocument():
13511349

13521350
# --- MAIN PROGRAM
13531351

1354-
names = globals().keys()
1355-
names.sort()
1352+
names = sorted(globals().keys())
13561353

13571354
failed = []
13581355

Lib/xml/dom/minidom.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def setUserData(self, key, data, handler):
256256

257257
def _call_user_data_handler(self, operation, src, dst):
258258
if hasattr(self, "_user_data"):
259-
for key, (data, handler) in self._user_data.items():
259+
for key, (data, handler) in list(self._user_data.items()):
260260
if handler is not None:
261261
handler.handle(operation, key, data, src, dst)
262262

@@ -480,7 +480,7 @@ def _get_length(self):
480480

481481
def item(self, index):
482482
try:
483-
return self[self._attrs.keys()[index]]
483+
return self[list(self._attrs.keys())[index]]
484484
except IndexError:
485485
return None
486486

@@ -672,7 +672,7 @@ def _get_tagName(self):
672672
return self.tagName
673673

674674
def unlink(self):
675-
for attr in self._attrs.values():
675+
for attr in list(self._attrs.values()):
676676
attr.unlink()
677677
self._attrs = None
678678
self._attrsNS = None
@@ -805,8 +805,7 @@ def writexml(self, writer, indent="", addindent="", newl=""):
805805
writer.write(indent+"<" + self.tagName)
806806

807807
attrs = self._get_attributes()
808-
a_names = attrs.keys()
809-
a_names.sort()
808+
a_names = sorted(attrs.keys())
810809

811810
for a_name in a_names:
812811
writer.write(" %s=\"" % a_name)

0 commit comments

Comments
 (0)