def bind(self, qname: str, text: NoneStr, tail: NoneStr, objects: List) -> bool: params: Dict = {} wild_node = False text_node = False ParserUtils.bind_attrs(params, self.meta, self.attrs, self.ns_map) wild_var = self.meta.find_var(mode=FindMode.WILDCARD) if wild_var and wild_var.mixed: ParserUtils.bind_mixed_objects(params, wild_var, self.position, objects) else: ParserUtils.bind_objects(params, self.meta, self.position, objects) text_node = ParserUtils.bind_content(params, self.meta, text, self.ns_map) if not text_node and wild_var: ParserUtils.bind_wild_content(params, wild_var, text, tail, self.attrs, self.ns_map) obj = self.meta.clazz(**params) if self.derived: obj = DerivedElement(qname=qname, value=obj, substituted=self.substituted) objects.append((qname, obj)) if not wild_var and self.mixed and not wild_node: tail = ParserUtils.normalize_content(tail) if tail: objects.append((None, tail)) return True
def test_bind_mixed_objects(self): generic = AnyElement(qname="foo") data_class = make_dataclass("A", fields=[]) derived = DerivedElement(qname="d", value=data_class) objects = [ ("a", 1), ("b", None), ("d", data_class), ("foo", generic), (None, "foo"), ] var = XmlVar(wildcard=True, name="foo", qname="{any}foo") params = {} ParserUtils.bind_mixed_objects(params, var, 1, objects) expected = {var.name: [AnyElement(qname="b", text=""), derived, generic, "foo"]} self.assertEqual(expected, params)