hamyar_paygah.utils.xml_utils¶
Utility functions relate to XML.
Attributes¶
Functions¶
|
Return the text content of a direct child element. |
|
Return the integer value of a child element's text content. |
|
Return the boolean value of a child element's text content. |
|
Return the time value of a child element's text content. |
|
Extract an enum member from boolean SOAP flag elements. |
Module Contents¶
- hamyar_paygah.utils.xml_utils.E¶
- hamyar_paygah.utils.xml_utils.get_text(document, tag, namespaces, prefix='a')¶
Return the text content of a direct child element.
- Parameters:
- Returns:
The element text if found and valid. Returns None if - The element does not exist. - The element text is None. - The element text is “-” or “#”.
- Return type:
str | None
- hamyar_paygah.utils.xml_utils.get_integer(document, tag, namespaces)¶
Return the integer value of a child element’s text content.
The function retrieves the element text using
get_textand attempts to convert it to an integer. If direct conversion fails, it extracts the first integer sequence found in the text.- Parameters:
- Returns:
The parsed integer if found. Returns None if - The element does not exist. - The element text is None or empty. - No integer value can be extracted.
- Return type:
int | None
- hamyar_paygah.utils.xml_utils.get_bool(document, tag, namespaces)¶
Return the boolean value of a child element’s text content.
The function retrieves the element text using
get_textand returns True only if the text is exactly “true” (case-insensitive). All other values, including missing or empty elements, return False.- Parameters:
- Returns:
True if the element text equals “true” (case-insensitive). Otherwise, False.
- Return type:
- hamyar_paygah.utils.xml_utils.get_time(document, tag, namespaces)¶
Return the time value of a child element’s text content.
The function retrieves the element text using
get_textand attempts to parse it using the format “%H:%M:%S”.- Parameters:
- Returns:
A
datetime.timeobject if parsing succeeds. Returns None if: - The element does not exist. - The element text is None. - The text does not match the “%H:%M:%S” format.- Return type:
- hamyar_paygah.utils.xml_utils.get_enum_from_boolean_flags(document, namespaces, enum_type)¶
Extract an enum member from boolean SOAP flag elements.
Iterates over all members of
enum_typeand evaluates the XML element whose tag name matchesmember.valueusingget_bool().If one or more flags evaluate to
True, the last matching enum member in iteration order is returned. If no flags evaluate toTrue,Noneis returned.This function assumes that each enum member’s value corresponds to the XML tag name of a boolean flag element.