From d829a50a5b7030b82ec2d15a33540225209453d4 Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 15 Oct 2019 14:57:23 -0700 Subject: [PATCH] Fix use of deprecated function in xml module. --- changelogs/fragments/xml-deprecated-functions.yml | 2 ++ lib/ansible/modules/files/xml.py | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/xml-deprecated-functions.yml diff --git a/changelogs/fragments/xml-deprecated-functions.yml b/changelogs/fragments/xml-deprecated-functions.yml new file mode 100644 index 00000000000..b5d31575bf8 --- /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 ab69d8ef57d..c71b3c1778e 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