Пример #1
0
    def start_element_handler(self, name, attributes):
        # All we want to do is construct our own Element instead of
        # minidom.Element, unfortunately the only way to do this is to
        # copy this whole function from expatbuilder.py
        if ' ' in name:
            uri, localname, prefix, qname = expatbuilder._parse_ns_name(
                self, name)
        else:
            uri = expatbuilder.EMPTY_NAMESPACE
            qname = name
            localname = None
            prefix = expatbuilder.EMPTY_PREFIX
        node = Element(qname, uri, prefix, localname)
        node.ownerDocument = self.document
        expatbuilder._append_child(self.curNode, node)
        self.curNode = node

        if self._ns_ordered_prefixes:
            for prefix, uri in self._ns_ordered_prefixes:
                if prefix:
                    a = minidom.Attr(
                        expatbuilder._intern(self, 'xmlns:' + prefix),
                        expatbuilder.XMLNS_NAMESPACE, prefix, "xmlns")
                else:
                    a = minidom.Attr("xmlns", expatbuilder.XMLNS_NAMESPACE,
                                     "xmlns", expatbuilder.EMPTY_PREFIX)
                d = a.childNodes[0].__dict__
                d['data'] = d['nodeValue'] = uri
                d = a.__dict__
                d['value'] = d['nodeValue'] = uri
                d['ownerDocument'] = self.document
                expatbuilder._set_attribute_node(node, a)
            del self._ns_ordered_prefixes[:]

        if attributes:
            _attrs = node._attrs
            _attrsNS = node._attrsNS
            for i in range(0, len(attributes), 2):
                aname = attributes[i]
                value = attributes[i + 1]
                if ' ' in aname:
                    uri, localname, prefix, qname = expatbuilder._parse_ns_name(
                        self, aname)
                    a = minidom.Attr(qname, uri, localname, prefix)
                    _attrs[qname] = a
                    _attrsNS[(uri, localname)] = a
                else:
                    a = minidom.Attr(aname, expatbuilder.EMPTY_NAMESPACE,
                                     aname, expatbuilder.EMPTY_PREFIX)
                    _attrs[aname] = a
                    _attrsNS[(expatbuilder.EMPTY_NAMESPACE, aname)] = a
                d = a.childNodes[0].__dict__
                d['data'] = d['nodeValue'] = value
                d = a.__dict__
                d['ownerDocument'] = self.document
                d['value'] = d['nodeValue'] = value
                d['ownerElement'] = node
Пример #2
0
    def start_element_handler(self, name, attributes):
        # All we want to do is construct our own Element instead of
        # minidom.Element, unfortunately the only way to do this is to
        # copy this whole function from expatbuilder.py
        if ' ' in name:
            uri, localname, prefix, qname = expatbuilder._parse_ns_name(self, name)
        else:
            uri = expatbuilder.EMPTY_NAMESPACE
            qname = name
            localname = None
            prefix = expatbuilder.EMPTY_PREFIX
        node = Element(qname, uri, prefix, localname)
        node.ownerDocument = self.document
        expatbuilder._append_child(self.curNode, node)
        self.curNode = node

        if self._ns_ordered_prefixes:
            for prefix, uri in self._ns_ordered_prefixes:
                if prefix:
                    a = minidom.Attr(expatbuilder._intern(self,
                                                          'xmlns:' + prefix),
                             expatbuilder.XMLNS_NAMESPACE, prefix, "xmlns")
                else:
                    a = minidom.Attr("xmlns", expatbuilder.XMLNS_NAMESPACE,
                             "xmlns", expatbuilder.EMPTY_PREFIX)
                d = a.childNodes[0].__dict__
                d['data'] = d['nodeValue'] = uri
                d = a.__dict__
                d['value'] = d['nodeValue'] = uri
                d['ownerDocument'] = self.document
                expatbuilder._set_attribute_node(node, a)
            del self._ns_ordered_prefixes[:]

        if attributes:
            _attrs = node._attrs
            _attrsNS = node._attrsNS
            for i in range(0, len(attributes), 2):
                aname = attributes[i]
                value = attributes[i+1]
                if ' ' in aname:
                    uri, localname, prefix, qname = expatbuilder._parse_ns_name(self, aname)
                    a = minidom.Attr(qname, uri, localname, prefix)
                    _attrs[qname] = a
                    _attrsNS[(uri, localname)] = a
                else:
                    a = minidom.Attr(aname, expatbuilder.EMPTY_NAMESPACE,
                             aname, expatbuilder.EMPTY_PREFIX)
                    _attrs[aname] = a
                    _attrsNS[(expatbuilder.EMPTY_NAMESPACE, aname)] = a
                d = a.childNodes[0].__dict__
                d['data'] = d['nodeValue'] = value
                d = a.__dict__
                d['ownerDocument'] = self.document
                d['value'] = d['nodeValue'] = value
                d['ownerElement'] = node
Пример #3
0
 def end_element_handler(self, name):
     curNode = self.curNode
     if ' ' in name:
         uri, localname, prefix, qname = expatbuilder._parse_ns_name(self, name)
         assert (curNode.namespaceURI == uri
                 and curNode.localName == localname
                 and curNode.prefix == prefix), "element stack messed up! (namespace)"
     else:
         assert curNode.nodeName == name, \
             "element stack messed up - bad nodeName"
         assert curNode.namespaceURI == expatbuilder.EMPTY_NAMESPACE, \
             "element stack messed up - bad namespaceURI"
     self.curNode = curNode.parentNode
     self._finish_end_element(curNode)
Пример #4
0
 def end_element_handler(self, name):
     curNode = self.curNode
     if ' ' in name:
         uri, localname, prefix, qname = expatbuilder._parse_ns_name(self, name)
         assert (curNode.namespaceURI == uri
                 and curNode.localName == localname
                 and curNode.prefix == prefix), "element stack messed up! (namespace)"
     else:
         assert curNode.nodeName == name, \
             "element stack messed up - bad nodeName"
         assert curNode.namespaceURI == expatbuilder.EMPTY_NAMESPACE, \
             "element stack messed up - bad namespaceURI"
     self.curNode = curNode.parentNode
     self._finish_end_element(curNode)
Пример #5
0
    def start_element_handler(self, name, attributes):
        # All we want to do is construct our own Element instead of
        # minidom.Element, unfortunately the only way to do this is to
        # copy this whole function from expatbuilder.py
        if " " in name:
            uri, localname, prefix, qname = expatbuilder._parse_ns_name(self, name)
        else:
            uri = expatbuilder.EMPTY_NAMESPACE
            qname = name
            localname = None
            prefix = expatbuilder.EMPTY_PREFIX
        node = Element(qname, uri, prefix, localname)
        node.ownerDocument = self.document
        expatbuilder._append_child(self.curNode, node)
        self.curNode = node

        if self._ns_ordered_prefixes:
            for prefix, uri in self._ns_ordered_prefixes:
                if prefix:
                    a = minidom.Attr(
                        expatbuilder._intern(self, "xmlns:" + prefix),
                        expatbuilder.XMLNS_NAMESPACE,
                        prefix,
                        "xmlns",
                    )
                else:
                    a = minidom.Attr(
                        "xmlns",
                        expatbuilder.XMLNS_NAMESPACE,
                        "xmlns",
                        expatbuilder.EMPTY_PREFIX,
                    )
                a.value = uri
                a.ownerDocument = self.document
                expatbuilder._set_attribute_node(node, a)
            del self._ns_ordered_prefixes[:]

        if attributes:
            if hasattr(node, "_ensure_attributes"):
                node._ensure_attributes()  # Python 3 only
            _attrs = node._attrs
            _attrsNS = node._attrsNS
            for i in range(0, len(attributes), 2):
                aname = attributes[i]
                value = attributes[i + 1]
                if " " in aname:
                    uri, localname, prefix, qname = expatbuilder._parse_ns_name(
                        self, aname
                    )
                    a = minidom.Attr(qname, uri, localname, prefix)
                    _attrs[qname] = a
                    _attrsNS[(uri, localname)] = a
                else:
                    a = minidom.Attr(
                        aname,
                        expatbuilder.EMPTY_NAMESPACE,
                        aname,
                        expatbuilder.EMPTY_PREFIX,
                    )
                    _attrs[aname] = a
                    _attrsNS[(expatbuilder.EMPTY_NAMESPACE, aname)] = a
                a.ownerDocument = self.document
                a.value = value
                a.ownerElement = node