示例#1
0
 def test_set_attributes(self, mock_set_attribute):
     values = dict(a=1, b=2)
     SerializeUtils.set_attributes(self.element, values, self.namespaces)
     mock_set_attribute.assert_has_calls([
         mock.call(self.element, "a", 1, self.namespaces),
         mock.call(self.element, "b", 2, self.namespaces),
     ])
示例#2
0
文件: xml.py 项目: nimish/xsdata
    def render_wildcard_node(self, parent: Element, value: Any, var: XmlVar,
                             namespaces: Namespaces):
        if value.qname:
            sub_element = SubElement(parent, value.qname)
        else:
            sub_element = parent

        namespaces.add_all(value.ns_map)
        SerializeUtils.set_text(sub_element, value.text, namespaces)
        SerializeUtils.set_tail(sub_element, value.tail, namespaces)
        SerializeUtils.set_attributes(sub_element, value.attributes,
                                      namespaces)
        for child in value.children:
            self.render_sub_node(sub_element, child, var, namespaces)

        SerializeUtils.set_nil_attribute(sub_element, var.nillable, namespaces)
示例#3
0
文件: xml.py 项目: rmr1154/xsdata
    def render_wildcard_node(self, parent: Element, value: Any, var: XmlVar,
                             namespaces: Namespaces):
        """Render a child element for the given parent according to the
        wildcard field metadata."""
        if value.qname:
            sub_element = SubElement(parent, value.qname)
        else:
            sub_element = parent

        namespaces.add_all(value.ns_map)
        SerializeUtils.set_text(sub_element, value.text, namespaces)
        SerializeUtils.set_tail(sub_element, value.tail, namespaces)
        SerializeUtils.set_attributes(sub_element, value.attributes,
                                      namespaces)
        for child in value.children:
            self.render_sub_node(sub_element, child, var, namespaces)

        SerializeUtils.set_nil_attribute(sub_element, var.nillable, namespaces)
示例#4
0
文件: xml.py 项目: nimish/xsdata
    def render_complex_node(self, parent: Element, obj: Any,
                            namespaces: Namespaces):
        meta = self.context.build(obj.__class__, QName(parent).namespace)
        for var, value in self.next_value(meta, obj):
            if value is None:
                continue
            elif var.is_attribute:
                SerializeUtils.set_attribute(parent, var.qname, value,
                                             namespaces)
            elif var.is_attributes:
                SerializeUtils.set_attributes(parent, value, namespaces)
            elif var.is_text:
                namespaces.add(var.qname.namespace)
                SerializeUtils.set_text(parent, value, namespaces)
            elif isinstance(value, list):
                self.render_sub_nodes(parent, value, var, namespaces)
            else:
                self.render_sub_node(parent, value, var, namespaces)

        SerializeUtils.set_nil_attribute(parent, meta.nillable, namespaces)