How to use the defusedxml.ElementTree.SubElement function in defusedxml

To help you get started, we’ve selected a few defusedxml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Metaswitch / crest / src / metaswitch / crest / tools / utils.py View on Github external
def local_identity(uri, tag):
    """
    Create an XML element representing the "local" identity (i.e. the owner of
    the call list).
    """
    top_elem = ET.Element(tag)
    uri_elem = ET.SubElement(top_elem, "URI")
    # Omit the name element (as it would often not be present in the underlying
    # SIP signaling).
    uri_elem.text = uri
    return top_elem
github Metaswitch / crest / src / metaswitch / crest / tools / utils.py View on Github external
2002-05-30T09:30:20 
          2002-05-30T09:35:00 
        

    """

    call_elem = ET.Element('call')

    if outgoing:
        call_elem.append(local_identity(uri, 'from'))
        call_elem.append(remote_identity('to'))
    else:
        call_elem.append(local_identity(uri, 'to'))
        call_elem.append(remote_identity('from'))

    answered_elem = ET.SubElement(call_elem, 'answered')
    answered_elem.text = '1' if answered else '0'

    outgoing_elem = ET.SubElement(call_elem, 'outgoing')
    outgoing_elem.text = '1' if outgoing else '0'

    start_time_elem = ET.SubElement(call_elem, 'start-time')
    start_time_elem.text = call_list_timestamp(timestamp)

    if answered:
        answered_time_elem = ET.SubElement(call_elem, 'answered-time')
        answered_time_elem.text = call_list_timestamp(timestamp + 10)

        end_time_elem = ET.SubElement(call_elem, 'end-time')
        end_time_elem.text = call_list_timestamp(timestamp + 60)

    return ET.tostring(call_elem)
github Metaswitch / crest / src / metaswitch / crest / tools / utils.py View on Github external
"""

    call_elem = ET.Element('call')

    if outgoing:
        call_elem.append(local_identity(uri, 'from'))
        call_elem.append(remote_identity('to'))
    else:
        call_elem.append(local_identity(uri, 'to'))
        call_elem.append(remote_identity('from'))

    answered_elem = ET.SubElement(call_elem, 'answered')
    answered_elem.text = '1' if answered else '0'

    outgoing_elem = ET.SubElement(call_elem, 'outgoing')
    outgoing_elem.text = '1' if outgoing else '0'

    start_time_elem = ET.SubElement(call_elem, 'start-time')
    start_time_elem.text = call_list_timestamp(timestamp)

    if answered:
        answered_time_elem = ET.SubElement(call_elem, 'answered-time')
        answered_time_elem.text = call_list_timestamp(timestamp + 10)

        end_time_elem = ET.SubElement(call_elem, 'end-time')
        end_time_elem.text = call_list_timestamp(timestamp + 60)

    return ET.tostring(call_elem)
github mar10 / wsgidav / wsgidav / xml_tools.py View on Github external
# lxml with safe defaults
    from defusedxml.lxml import _etree as etree

    use_lxml = True
    _ElementType = etree._Element
except ImportError:
    # warnings.warn("Could not import lxml")  # , ImportWarning)
    # Try xml module (Python 2.5 or later) with safe defaults
    from defusedxml import ElementTree as etree

    # defusedxml doesn't define these non-parsing related objects
    from xml.etree.ElementTree import Element, SubElement, tostring

    etree.Element = _ElementType = Element
    etree.SubElement = SubElement
    etree.tostring = tostring


# ========================================================================
# XML
# ========================================================================


def is_etree_element(obj):
    return isinstance(obj, _ElementType)


def string_to_xml(text):
    """Convert XML string into etree.Element."""
    try:
        return etree.XML(text)
github StevenLooman / async_upnp_client / contrib / dummy_tv.py View on Github external
result = yield from state_var.do_command(command, **args)
    if result is None:
        return web.Response(status=404)

    LOGGER.debug('Result: %s', result)

    # return result
    response_base = '' \
           '' \
           '' \
           ''
    el_envelope = ET.fromstring(response_base)
    el_body = el_envelope.find('./envelope:Body', NS)
    el_response = ET.SubElement(el_body, '{' + xml_ns + '}' + command + 'Response')
    for key, value in result.items():
        el_arg = ET.SubElement(el_response, key)
        el_arg.text = str(value)

    text = ET.tostring(el_envelope)
    return web.Response(status=200, body=text)
github Metaswitch / crest / src / metaswitch / crest / tools / utils.py View on Github external
call_elem = ET.Element('call')

    if outgoing:
        call_elem.append(local_identity(uri, 'from'))
        call_elem.append(remote_identity('to'))
    else:
        call_elem.append(local_identity(uri, 'to'))
        call_elem.append(remote_identity('from'))

    answered_elem = ET.SubElement(call_elem, 'answered')
    answered_elem.text = '1' if answered else '0'

    outgoing_elem = ET.SubElement(call_elem, 'outgoing')
    outgoing_elem.text = '1' if outgoing else '0'

    start_time_elem = ET.SubElement(call_elem, 'start-time')
    start_time_elem.text = call_list_timestamp(timestamp)

    if answered:
        answered_time_elem = ET.SubElement(call_elem, 'answered-time')
        answered_time_elem.text = call_list_timestamp(timestamp + 10)

        end_time_elem = ET.SubElement(call_elem, 'end-time')
        end_time_elem.text = call_list_timestamp(timestamp + 60)

    return ET.tostring(call_elem)
github Metaswitch / crest / src / metaswitch / homestead_prov / provisioning / models.py View on Github external
def build_imssubscription_xml(self):
        """Create an IMS subscription document for this IRS"""

        # Create an IMS subscription mode with a dummy private ID node.
        root = ET.Element("IMSSubscription")
        root.set("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
        root.set("xsi:noNamespaceSchemaLocation", "CxDataType.xsd")

        priv_elem = ET.SubElement(root, "PrivateID")
        priv_elem.text = "Unspecified"

        found_sip_uri = False

        sp_uuids = yield self.get_associated_service_profiles()

        for sp_uuid in sp_uuids:
            # Add a ServiceProfile node for each profile in this IRS with iFCs.
            #
            # Note that the IFC XML contains a wrapping  tag.
            try:
                ifc_xml = yield ServiceProfile(sp_uuid).get_ifc()
            except NotFoundException:
                ifc_xml = ""

            sp_elem = ET.fromstring(ifc_xml)