Ejemplo n.º 1
0
    def removeChild(self, oldChild):
        # NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly
        if self.is_readonly(self):
            raise DOMException(DOMException.NO_MODIFICATION_ALLOWED)

        if not oldChild:
            raise DOMException(DOMException.NOT_FOUND_ERR)

        if not isinstance(oldChild, Node):
            raise DOMException(DOMException.NOT_FOUND_ERR)

        index = self.findChild(oldChild)
        if index < 0 and not self.is_text(oldChild):
            raise DOMException(DOMException.NOT_FOUND_ERR)

        if getattr(oldChild, 'tag',
                   None) and oldChild.tag in self.tag.contents:
            oldChildHash = hash(oldChild.tag._node)

            for p in self.tag.contents:
                if getattr(p, '_node', None) is None:
                    continue

                if oldChildHash == hash(p._node):
                    p.extract()
            #self.tag.contents.remove(oldChild.tag)

        return oldChild
Ejemplo n.º 2
0
    def appendChild(self, newChild):
        # NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly
        if self.is_readonly(self):
            raise DOMException(DOMException.NO_MODIFICATION_ALLOWED)

        if self.is_text(self):
            raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)

        if not newChild:
            raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)

        if not isinstance(newChild, Node):
            raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)

        # If the newChild is already in the tree, it is first removed
        if getattr(newChild, 'tag',
                   None) and newChild.tag in self.tag.contents:
            self.tag.contents.remove(newChild.tag)

        if self.is_text(newChild):
            self.tag.append(newChild.data.output_ready())
            return newChild

        if newChild.nodeType in (Node.DOCUMENT_FRAGMENT_NODE, ):
            #self.tag.append(newChild.tag.findChild())
            node = self.tag
            for p in newChild.tag.find_all_next():
                node.append(p)
                node = p

            return newChild

        self.tag.append(newChild.tag)
        return newChild
Ejemplo n.º 3
0
    def insertBefore(self, newChild, refChild):
        if not newChild:
            raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)

        if not isinstance(newChild, Node):
            raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)

        # If refChild is null, insert newChild at the end of the list
        # of children
        if not refChild:
            return self.appendChild(newChild)

        if not isinstance(refChild, Node):
            raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)

        #index = self.findChild(refChild)
        #if index < 0 and not self.is_text(refChild):
        #    raise DOMException(DOMException.NOT_FOUND_ERR)

        # If the newChild is already in the tree, it is first removed
        if getattr(newChild, 'tag',
                   None) and newChild.tag in self.tag.contents:
            newChildHash = hash(newChild.tag._node)

            for p in self.tag.contents:
                if getattr(p, '_node', None) is None:
                    continue

                if newChildHash == hash(p._node):
                    p.extract()

            #self.tag.contents.remove(newChild.tag)

        index = self.findChild(refChild)
        if index < 0 and not self.is_text(refChild):
            raise DOMException(DOMException.NOT_FOUND_ERR)

        if self.is_text(newChild):
            self.tag.insert(index,
                            newChild.data.output_ready(formatter=lambda x: x))
            return newChild

        if newChild.nodeType in (Node.DOCUMENT_FRAGMENT_NODE, ):
            # self.tag.insert(index, newChild.tag.findChild())
            node = None

            for p in newChild.tag.find_all_next():
                if node is None:
                    self.tag.insert(index, p)
                else:
                    node.append(p)

                node = p

            return newChild

        self.tag.insert(index, newChild.tag)
        return newChild
Ejemplo n.º 4
0
    def replaceChild(self, newChild, oldChild):
        # NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the parent of
        # the new node is readonly.
        if self.is_readonly(self):
            raise DOMException(DOMException.NO_MODIFICATION_ALLOWED)

        parent = getattr(newChild, 'parentNode', None)
        if parent:
            if self.is_readonly(parent):
                raise DOMException(DOMException.NO_MODIFICATION_ALLOWED)

        if not newChild or not oldChild:
            raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)

        if not isinstance(newChild, Node) or not isinstance(oldChild, Node):
            raise DOMException(DOMException.HIERARCHY_REQUEST_ERR)

        index = self.findChild(oldChild)
        if index < 0 and not self.is_text(refChild):
            raise DOMException(DOMException.NOT_FOUND_ERR)

        if self.is_text(newChild):
            self.tag.contents[index] = newChild.data.output_ready(
                formatter=lambda x: x)
            return oldChild

        if newChild.nodeType in (Node.DOCUMENT_FRAGMENT_NODE, ):
            #self.tag.contents[index] = newChild.tag.findChild()
            node = None

            for p in newChild.tag.find_all_next():
                if node is None:
                    self.tag.contents[index] = p
                else:
                    node.append(p)

                node = p

            return oldChild

        self.tag.contents[index] = newChild.tag
        return oldChild
Ejemplo n.º 5
0
    def removeChild(self, oldChild):
        # NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly
        if self.is_readonly(self):
            raise DOMException(DOMException.NO_MODIFICATION_ALLOWED)

        if not oldChild:
            raise DOMException(DOMException.NOT_FOUND_ERR)

        if not isinstance(oldChild, Node):
            raise DOMException(DOMException.NOT_FOUND_ERR)

        index = self.findChild(oldChild)
        if index < 0 and not self.is_text(oldChild):
            raise DOMException(DOMException.NOT_FOUND_ERR)

        if getattr(oldChild, 'tag',
                   None) and oldChild.tag in self.tag.contents:
            self.tag.contents.remove(oldChild.tag)

        return oldChild
Ejemplo n.º 6
0
 def splitText(self, offset):
     raise DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)
Ejemplo n.º 7
0
 def setLength(self):
     raise DOMException(DOMException.NOT_SUPPORTED_ERR)
Ejemplo n.º 8
0
 def replaceData(self, offset, count, arg):
     raise DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)
Ejemplo n.º 9
0
 def deleteData(self, offset, count):
     raise DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)
Ejemplo n.º 10
0
 def insertData(self, offset, arg):
     raise DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)
Ejemplo n.º 11
0
 def appendData(self, arg):
     raise DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)
Ejemplo n.º 12
0
 def setData(self, data):
     raise DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)
Ejemplo n.º 13
0
    def deleteCell(self, index):
        if index < -1 or index >= len(self.cells.nodes):
            raise DOMException(DOMException.INDEX_SIZE_ERR)

        del self.cells.nodes[index]
Ejemplo n.º 14
0
 def setNodeValue(self, value):
     raise DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR)
Ejemplo n.º 15
0
 def createEvent(self, eventType):
     raise DOMException(DOMException.NOT_SUPPORTED_ERR)