-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try-except extract data funtcion and add unit test
- Loading branch information
Wout Feys
committed
Nov 5, 2024
1 parent
39a2392
commit 6a16512
Showing
2 changed files
with
29 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
"""Exports extract_data_from_xml_body helper function""" | ||
|
||
import aikido_zen.context as ctx | ||
from aikido_zen.helpers.logging import logger | ||
|
||
|
||
def extract_data_from_xml_body(user_input, root_element): | ||
"""Extracts all attributes from the xml and adds them to context""" | ||
context = ctx.get_current_context() | ||
if not isinstance(context.body, str) or user_input != context.body: | ||
return | ||
try: | ||
context = ctx.get_current_context() | ||
if ( | ||
not context | ||
or not isinstance(context.body, str) | ||
or user_input != context.body | ||
): | ||
return | ||
|
||
extracted_xml_attrs = context.xml | ||
for el in root_element: | ||
for k, v in el.items(): | ||
if not extracted_xml_attrs.get(k): | ||
extracted_xml_attrs[k] = set() | ||
extracted_xml_attrs[k].add(v) | ||
context.set_as_current_context() | ||
extracted_xml_attrs = context.xml | ||
for el in root_element: | ||
for k, v in el.items(): | ||
if not extracted_xml_attrs.get(k): | ||
extracted_xml_attrs[k] = set() | ||
extracted_xml_attrs[k].add(v) | ||
context.set_as_current_context() | ||
except Exception as e: | ||
logger.debug("Exception occured when extracting XML: %s", e) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters