Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-2.9] Fix use of deprecated function in xml module. #63537

Merged
merged 1 commit into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/xml-deprecated-functions.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions lib/ansible/modules/files/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down