コード例 #1
0
    def bind(self, qname: str, text: NoneStr, tail: NoneStr, objects: List) -> bool:
        obj: Any = None
        if self.has_children:
            obj = AnyElement(
                qname=qname,
                text=ParserUtils.normalize_content(text),
                tail=ParserUtils.normalize_content(tail),
                attributes=ParserUtils.parse_any_attributes(self.attrs, self.ns_map),
                children=ParserUtils.fetch_any_children(self.position, objects),
            )
            objects.append((self.var.qname, obj))
        else:
            var = self.var
            ns_map = self.ns_map
            datatype = ParserUtils.data_type(self.attrs, self.ns_map)
            obj = ParserUtils.parse_value(text, [datatype.type], var.default, ns_map)

            if var.derived:
                obj = DerivedElement(qname=qname, value=obj)

            objects.append((qname, obj))

            if self.mixed:
                tail = ParserUtils.normalize_content(tail)
                if tail:
                    objects.append((None, tail))

        return True
コード例 #2
0
    def bind(self, qname: str, text: NoneStr, tail: NoneStr, objects: List) -> bool:
        obj = AnyElement(
            qname=qname,
            text=ParserUtils.normalize_content(text),
            tail=ParserUtils.normalize_content(tail),
            attributes=ParserUtils.parse_any_attributes(self.attrs, self.ns_map),
            children=ParserUtils.fetch_any_children(self.position, objects),
        )
        objects.append((self.var.qname, obj))

        return True
コード例 #3
0
    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
コード例 #4
0
    def bind(self, qname: str, text: NoneStr, tail: NoneStr,
             objects: List) -> bool:
        children = ParserUtils.fetch_any_children(self.position, objects)
        attributes = ParserUtils.parse_any_attributes(self.attrs, self.ns_map)
        derived = self.var.derived or qname != self.var.qname
        text = ParserUtils.normalize_content(text) if children else text
        text = "" if text is None and not self.var.nillable else text
        tail = ParserUtils.normalize_content(tail)

        if tail or attributes or children or self.var.wildcard or derived:
            obj = AnyElement(
                qname=qname,
                text=text,
                tail=tail,
                attributes=attributes,
                children=children,
            )
            objects.append((self.var.qname, obj))
        else:
            objects.append((self.var.qname, text))

        return True