Skip to content

Commit 8a14842

Browse files
committed
Zen update xml.py to also patch fromstring/fromstringlist
1 parent 3c427fb commit 8a14842

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

  • aikido_zen/sources/xml_sources

aikido_zen/sources/xml_sources/xml.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,25 @@
66

77

88
@after
9-
def _feed(func, instance, args, kwargs, return_value):
10-
# Fetches XML data, this should just return an internal attribute
11-
# and not close a stream or something that is noticable by the end-user
12-
parsed_xml = instance.target.close()
13-
data = get_argument(args, kwargs, 0, "data")
14-
extract_data_from_xml_body(user_input=data, root_element=parsed_xml)
9+
def _fromstring(func, instance, args, kwargs, return_value):
10+
text = get_argument(args, kwargs, 0, "text")
11+
extract_data_from_xml_body(user_input=text, root_element=return_value)
12+
13+
14+
@after
15+
def _fromstringlist(func, instance, args, kwargs, return_value):
16+
strings = get_argument(args, kwargs, 0, "sequence")
17+
for text in strings:
18+
extract_data_from_xml_body(user_input=text, root_element=return_value)
1519

1620

1721
@on_import("xml.etree.ElementTree")
1822
def patch(m):
19-
patch_function(m, "XMLParser.feed", _feed)
23+
"""
24+
patching module xml.etree.ElementTree
25+
- patches function fromstring(text, ...)
26+
- patches function fromstringlist(sequence, ...)
27+
(src: https://github.com/python/cpython/blob/bc1a6ecfab02075acea79f8460a2dce70c61b2fd/Lib/xml/etree/ElementTree.py#L1370)
28+
"""
29+
patch_function(m, "fromstring", _fromstring)
30+
patch_function(m, "fromstringlist", _fromstringlist)

0 commit comments

Comments
 (0)