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

xml: make module work with lxml 5.1.1 #8169

Merged
merged 1 commit into from
Mar 30, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/8169-lxml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "xml - make module work with lxml 5.1.1, which removed some internals that the module was relying on (https://github.com/ansible-collections/community.general/pull/8169)."
9 changes: 7 additions & 2 deletions plugins/modules/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,16 @@ def is_attribute(tree, xpath, namespaces):
""" Test if a given xpath matches and that match is an attribute

An xpath attribute search will only match one item"""

# lxml 5.1.1 removed etree._ElementStringResult, so we can no longer simply assume it's there
# (https://github.com/lxml/lxml/commit/eba79343d0e7ad1ce40169f60460cdd4caa29eb3)
ElementStringResult = getattr(etree, '_ElementStringResult', None)

if xpath_matches(tree, xpath, namespaces):
match = tree.xpath(xpath, namespaces=namespaces)
if isinstance(match[0], etree._ElementStringResult):
if isinstance(match[0], etree._ElementUnicodeResult):
return True
elif isinstance(match[0], etree._ElementUnicodeResult):
elif ElementStringResult is not None and isinstance(match[0], ElementStringResult):
return True
return False

Expand Down