mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[PR #8169/b444e873 backport][stable-7] xml: make module work with lxml 5.1.1 (#8171)
xml: make module work with lxml 5.1.1 (#8169)
Make module work with lxml 5.1.1.
(cherry picked from commit b444e8739c
)
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
a7d8397449
commit
68eb07a900
2 changed files with 9 additions and 2 deletions
2
changelogs/fragments/8169-lxml.yml
Normal file
2
changelogs/fragments/8169-lxml.yml
Normal file
|
@ -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)."
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue