Mercurial > libervia-backend
diff sat/tools/xml_tools.py @ 3967:f461f11ea176
plugin XEP-0384: Implementation of Automatic Trust Management:
- Implementation of Trust Messages (XEP-0434)
- Implementation of Automatic Trust Management (XEP-0450)
- Implementations directly as part of the OMEMO plugin, since omemo:2 is the only protocol supported by ATM at the moment
- Trust system selection updated to allow choice between manual trust with ATM and BTBV
- dev-requirements.txt updated to include additional requirements for the e2e tests
fix 376
author | Syndace <me@syndace.dev> |
---|---|
date | Fri, 28 Oct 2022 18:50:06 +0200 |
parents | 323017a4e4d2 |
children | 818db4ca3717 |
line wrap: on
line diff
--- a/sat/tools/xml_tools.py Sun Oct 30 01:06:58 2022 +0200 +++ b/sat/tools/xml_tools.py Fri Oct 28 18:50:06 2022 +0200 @@ -20,7 +20,7 @@ from collections import OrderedDict import html.entities import re -from typing import Optional, Tuple, Union, Literal, overload +from typing import Dict, Optional, Tuple, Union, Literal, overload from xml.dom import NotFoundErr, minidom import xml.etree.ElementTree as ET from lxml import etree @@ -2030,3 +2030,37 @@ for child in elt.elements(): et_elt.append(domish_elt_2_et_elt(child, lxml=lxml)) return et_elt + + +def domish_elt_2_et_elt2(element: domish.Element) -> ET.Element: + """ + WIP, originally from the OMEMO plugin + """ + + element_name = element.name + if element.uri is not None: + element_name = "{" + element.uri + "}" + element_name + + attrib: Dict[str, str] = {} + for qname, value in element.attributes.items(): + attribute_name = qname[1] if isinstance(qname, tuple) else qname + attribute_namespace = qname[0] if isinstance(qname, tuple) else None + if attribute_namespace is not None: + attribute_name = "{" + attribute_namespace + "}" + attribute_name + + attrib[attribute_name] = value + + result = ET.Element(element_name, attrib) + + last_child: Optional[ET.Element] = None + for child in element.children: + if isinstance(child, str): + if last_child is None: + result.text = child + else: + last_child.tail = child + else: + last_child = domish_elt_2_et_elt2(child) + result.append(last_child) + + return result