import logging
from lxml import etree
from lxml.builder import ElementMaker
from q2_sdk.models.cores.queries.base_query import BaseQuery
[docs]
class EplSoapBase(BaseQuery):
def __init__(self, logger: logging.Logger):
super().__init__(logger)
[docs]
@staticmethod
def wrap_in_soap(message_nodes: list) -> str:
"""
wraps message nodes in soap body and envelope
:param message_nodes: A list of xml nodes
:return: The full soap shape to be sent to the core
"""
soap_env = "http://schemas.xmlsoap.org/soap/envelope/"
xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsd = "http://www.w3.org/2001/XMLSchema"
soap = ElementMaker(namespace=soap_env, nsmap={"soap": soap_env})
body_nsmap = {"xsi": xsi, "xsd": xsd}
soap_body = ElementMaker(namespace=soap_env, nsmap=body_nsmap)
xml = soap.Envelope(soap_body.Body(*message_nodes))
return etree.tostring(xml, encoding="unicode")