Ejemplo n.º 1
0
    def __validateBoundary(self, node, offset):
        """Make sure the node is a legal boundary"""

        if not hasattr(node, 'nodeType'):
            raise InvalidNodeTypeErr()

        #Check for proper node type
        curNode = node
        while curNode:
            if curNode.nodeType in [
                    Node.ENTITY_NODE,
                    Node.NOTATION_NODE,
                    Node.DOCUMENT_TYPE_NODE,
            ]:
                raise InvalidNodeTypeErr()
            curNode = curNode.parentNode

        #Check number of cild units
        if offset < 0:
            raise IndexSizeErr()

        if node.nodeType in [
                Node.TEXT_NODE, Node.COMMENT_NODE,
                Node.PROCESSING_INSTRUCTION_NODE
        ]:
            #Child units are characters
            if offset > len(node.data):
                raise IndexSizeErr()
        else:
            if offset > len(node.childNodes):
                raise IndexSizeErr()
Ejemplo n.º 2
0
 def deleteData(self, offset, count):
     if count < 0 or offset < 0 or offset > self._length:
         raise IndexSizeErr()
     data = self.__dict__['__nodeValue']
     data = data[:int(offset)] + data[int(offset + count):]
     self._set_data(data)
     self._4dom_fireMutationEvent('DOMSubtreeModified')
     return
Ejemplo n.º 3
0
 def replaceData(self, offset, count, arg):
     if not IsDOMString(arg):
         raise SyntaxErr()
     if count < 0 or offset < 0 or offset > self._length:
         raise IndexSizeErr()
     data = self.__dict__['__nodeValue']
     data = data[:int(offset)] + arg + data[int(offset + count):]
     self._set_data(data)
     self._4dom_fireMutationEvent('DOMSubtreeModified')
     return
Ejemplo n.º 4
0
 def insertRow(self,index):
     rows = self._get_rows()
     if index < 0 or index > len(rows):
         raise IndexSizeErr()
     rows = self._get_rows()
     newRow = self.ownerDocument.createElement('TR')
     if index == len(rows):
         ref = None
     else:
         ref = rows[index]
     return self.insertBefore(newRow, ref)
Ejemplo n.º 5
0
    def _set_selectedIndex(self,index):
        options = self._get_options()
        if index < 0 or index >= len(options):
            raise IndexSizeErr()

        for ctr in range(len(options)):
            node = options.item(ctr)
            if ctr == index:
                node._set_selected(1)
            else:
                node._set_selected(0)
Ejemplo n.º 6
0
 def insertCell(self, index):
     cells = self._get_cells()
     if index < 0 or index > len(cells):
         raise IndexSizeErr()
     cell = self.ownerDocument.createElement('TD')
     length = cells.length
     if index == len(cells):
         ref = None
     elif index < len(cells):
         ref = cells[index]
     return self.insertBefore(cell, ref)
Ejemplo n.º 7
0
 def splitText(self, offset):
     if not (0 < offset < self.length):
         raise IndexSizeErr()
     data = self.data
     first = data[:int(offset)]
     second = data[int(offset):]
     node = self.ownerDocument.createTextNode(second)
     self._set_data(first)
     parent = self.parentNode
     if parent:
         sibling = self.nextSibling
         if sibling:
             parent.insertBefore(node, self.nextSibling)
         else:
             parent.appendChild(node)
     return node
Ejemplo n.º 8
0
 def insertRow(self, index):
     rows = self._get_rows()
     if index < 0 or index > len(rows):
         raise IndexSizeErr()
     newRow = self.ownerDocument.createElement('TR')
     if not rows:
         # An empty table, create a body in which to insert the row
         body = self.ownerDocument.createElement('TBODY')
         # The body is the last element according to DTD
         self.appendChild(body)
         parent = body
         ref = None
     elif index == len(rows):
         parent = rows[-1].parentNode
         ref = None
     else:
         ref = rows[index]
         parent = ref.parentNode
     return parent.insertBefore(newRow, ref)
Ejemplo n.º 9
0
 def deleteRow(self,index):
     rows = self._get_rows()
     if index < 0 or index > len(rows):
         raise IndexSizeErr()
     rows[index].parentNode.removeChild(rows[index])
Ejemplo n.º 10
0
 def deleteCell(self, index):
     cells = self._get_cells()
     if index < 0 or index >= len(cells):
         raise IndexSizeErr()
     self.removeChild(cells[index])
Ejemplo n.º 11
0
 def substringData(self, offset, count):
     if count < 0 or offset < 0 or offset > self._length:
         raise IndexSizeErr()
     return self.data[int(offset):int(offset + count)]