def _4dom_raiseIfAncestor(self, node): "Helper function that raises if node is an ancestor of self or self." n = self if n is node: raise HierarchyRequestErr() if node.hasChildNodes(): while n is not None: n = n.parentNode if n is node: raise HierarchyRequestErr()
def appendChild(self, node): if hasattr(node, 'allowNoSvgChildNode'): if not self.allowAllSvgNodesAsChildNodes: if not (node.svgNodeType in self._allowedSvgChildNodes): raise HierarchyRequestErr("%s cannot be child of %s" % (repr(node), repr(self))) else: Element.appendChild(self, node) Element.appendChild(self, node)
def _4dom_addSingle(self, node): '''Make sure only one Element node is added to a Document''' if node.nodeType == Node.ELEMENT_NODE: self._4dom_validateNode(node) if node.parentNode != None: node.parentNode.removeChild(node) if self.__dict__['__documentElement']: raise HierarchyRequestErr() self.__dict__['__documentElement'] = node if self.__dict__['__doctype']: self.__dict__['__doctype']._4dom_setName(node.nodeName)
def replaceChild(self, newChild, oldChild): if newChild.nodeType != Node.DOCUMENT_FRAGMENT_NODE: root = self.__dict__['__documentElement'] if root in [oldChild, newChild]: self.__dict__['__documentElement'] = None else: raise HierarchyRequestErr() replaced = FtNode.replaceChild(self, newChild, oldChild) if newChild.nodeType == Node.ELEMENT_NODE: self.__dict__['__documentElement'] = newChild if self.__dict__['__doctype']: self.__dict__['__doctype']._4dom_setName(newChild.nodeName) return replaced
def appendChild(self, node): raise HierarchyRequestErr("%s does not support child node operations" % (repr(self)))
def replaceChild(self, newChild, oldChild): raise HierarchyRequestErr("%s does not support child node operations" % (repr(self)))
def appendChild(self, newChild): raise HierarchyRequestErr(self.nodeName + " nodes cannot have children")
def removeChild(self, oldChild): raise HierarchyRequestErr(self.nodeName + " nodes cannot have children")
def insertBefore(self, newChild, refChild): raise HierarchyRequestErr(self.nodeName + " nodes cannot have children")
def _4dom_validateNode(self, newNode): if not newNode.nodeType in self.__class__._allowedChildren: raise HierarchyRequestErr() self._4dom_raiseIfAncestor(newNode) if self.ownerDocument != newNode.ownerDocument: raise WrongDocumentErr()