Skip to content

Commit

Permalink
fix compatibility with Python 3.9
Browse files Browse the repository at this point in the history
getchildren() method was removed from the ElementTree and Element classes in
Python 3.9. This commit uses built-in iter() and list() methods instead of
the removed one. This fix was suggested in the Python 3.9 release notes:

https://docs.python.org/3.9/whatsnew/3.9.html#removed
  • Loading branch information
ondrejbudai committed Oct 2, 2020
1 parent 639edbe commit 34ab164
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion S3/Exceptions.py
Expand Up @@ -127,7 +127,7 @@ def parse_error_xml(tree):
if not error_node.tag == "Error":
error_node = tree.find(".//Error")
if error_node is not None:
for child in error_node.getchildren():
for child in iter(error_node):
if child.text != "":
debug("ErrorXML: " + child.tag + ": " + repr(child.text))
info[child.tag] = child.text
Expand Down
8 changes: 4 additions & 4 deletions S3/Utils.py
Expand Up @@ -65,9 +65,9 @@ def parseNodes(nodes):
retval = []
for node in nodes:
retval_item = {}
for child in node.getchildren():
for child in iter(node):
name = decode_from_s3(child.tag)
if child.getchildren():
if list(child):
retval_item[name] = parseNodes([child])
else:
found_text = node.findtext(".//%s" % child.tag)
Expand Down Expand Up @@ -124,8 +124,8 @@ def getListFromXml(xml, node):

def getDictFromTree(tree):
ret_dict = {}
for child in tree.getchildren():
if child.getchildren():
for child in iter(tree):
if list(child):
## Complex-type child. Recurse
content = getDictFromTree(child)
else:
Expand Down

0 comments on commit 34ab164

Please sign in to comment.