diff options
author | Matt Clay <mclay@redhat.com> | 2019-11-11 15:09:48 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-11 15:09:48 -0800 |
commit | 0586d2c6308aa53e0fd3dc2e6b97940317623702 (patch) | |
tree | 5db078424c3b7df601dcbe6fd0791b64f2b89089 | |
parent | 7c5e08c0599a7bedb0cc719519a2d207417fd138 (diff) | |
download | ansible-0586d2c6308aa53e0fd3dc2e6b97940317623702.tar.gz |
Merge pull request #63537 from mattclay/backport-d829a50-stable-2.9
[stable-2.9] Fix use of deprecated function in xml module.
-rw-r--r-- | changelogs/fragments/xml-deprecated-functions.yml | 2 | ||||
-rw-r--r-- | lib/ansible/modules/files/xml.py | 6 |
2 files changed, 5 insertions, 3 deletions
diff --git a/changelogs/fragments/xml-deprecated-functions.yml b/changelogs/fragments/xml-deprecated-functions.yml new file mode 100644 index 0000000000..b5d31575bf --- /dev/null +++ b/changelogs/fragments/xml-deprecated-functions.yml @@ -0,0 +1,2 @@ +bugfixes: + - Fix the ``xml`` module to use ``list(elem)`` instead of ``elem.getchildren()`` since it is being removed in Python 3.9 diff --git a/lib/ansible/modules/files/xml.py b/lib/ansible/modules/files/xml.py index ab69d8ef57..c71b3c1778 100644 --- a/lib/ansible/modules/files/xml.py +++ b/lib/ansible/modules/files/xml.py @@ -441,7 +441,7 @@ def delete_xpath_target(module, tree, xpath, namespaces): def replace_children_of(children, match): - for element in match.getchildren(): + for element in list(match): match.remove(element) match.extend(children) @@ -458,8 +458,8 @@ def set_target_children_inner(module, tree, xpath, namespaces, children, in_type # xpaths always return matches as a list, so.... for match in matches: # Check if elements differ - if len(match.getchildren()) == len(children): - for idx, element in enumerate(match.getchildren()): + if len(list(match)) == len(children): + for idx, element in enumerate(list(match)): if etree.tostring(element) != children_as_string[idx]: replace_children_of(children, match) changed = True |