|
6 | 6 |
|
7 | 7 |
|
8 | 8 | @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) |
15 | 19 |
|
16 | 20 |
|
17 | 21 | @on_import("xml.etree.ElementTree") |
18 | 22 | 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