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()
def substringData(self, offset, count): if offset < 0: raise IndexSizeErr("offset cannot be negative") if offset >= len(self.data): raise IndexSizeErr("offset cannot be beyond end of data") if count < 0: raise IndexSizeErr("count cannot be negative") return self.data[offset:offset+count]
def insertData(self, offset, arg): if offset < 0: raise IndexSizeErr("offset cannot be negative") if offset >= len(self.data): raise IndexSizeErr("offset cannot be beyond end of data") if arg: self.data = "%s%s%s" % ( self.data[:offset], arg, self.data[offset:]) return
def deleteData(self, offset, count): if offset < 0: raise IndexSizeErr("offset cannot be negative") if offset >= len(self.data): raise IndexSizeErr("offset cannot be beyond end of data") if count < 0: raise IndexSizeErr("count cannot be negative") if count: self.data = self.data[:offset] + self.data[offset+count:] return
def replaceData(self, offset, count, arg): if offset < 0: raise IndexSizeErr("offset cannot be negative") if offset >= len(self.data): raise IndexSizeErr("offset cannot be beyond end of data") if count < 0: raise IndexSizeErr("count cannot be negative") if count: self.data = "%s%s%s" % ( self.data[:offset], arg, self.data[offset+count:]) return
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
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
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)
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)
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)
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
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)
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)]
def deleteCell(self, index): cells = self._get_cells() if index < 0 or index >= len(cells): raise IndexSizeErr() self.removeChild(cells[index])
def deleteRow(self, index): rows = self._get_rows() if index < 0 or index > len(rows): raise IndexSizeErr() rows[index].parentNode.removeChild(rows[index])