예제 #1
0
def create_element(name, **attrs):
    # copy.deepcopy() is an order of magnitude faster than creating a new Element() every time
    if ':' in name:
        ns, name = name.split(':')
        name = '{%s}%s' % (ns_translation[ns], name)
    elem = RestrictedElement(**attrs)
    elem.tag = name
    return elem
예제 #2
0
def create_element(name, **attrs):
    # copy.deepcopy() is an order of magnitude faster than creating a new Element() every time
    if ':' in name:
        ns, name = name.split(':')
        name = '{%s}%s' % (ns_translation[ns], name)
    elem = RestrictedElement(**attrs)
    elem.tag = name
    return elem
예제 #3
0
def create_element(name, attrs=None, nsmap=None):
    # Python versions prior to 3.6 do not preserve dict or kwarg ordering, so we cannot pull in attrs as **kwargs if we
    # also want stable XML attribute output. Instead, let callers supply us with an OrderedDict instance.
    if ':' in name:
        ns, name = name.split(':')
        name = '{%s}%s' % (ns_translation[ns], name)
    elem = RestrictedElement(attrib=attrs, nsmap=nsmap)
    elem.tag = name
    return elem
예제 #4
0
def create_element(name, attrs=None, nsmap=None):
    # Python versions prior to 3.6 do not preserve dict or kwarg ordering, so we cannot pull in attrs as **kwargs if we
    # also want stable XML attribute output. Instead, let callers supply us with an OrderedDict instance.
    if ':' in name:
        ns, name = name.split(':')
        name = '{%s}%s' % (ns_translation[ns], name)
    elem = RestrictedElement(nsmap=nsmap)
    if attrs:
        # Try hard to keep attribute order, to ensure deterministic output. This simplifies testing.
        for k, v in attrs.items():
            elem.set(k, v)
    elem.tag = name
    return elem