[Python-checkins] CVS: python/dist/src/Lib/xml/dom minidom.py,1.15,1.16 pulldom.py,1.12,1.13

A.M. Kuchling python-dev@python.org
Wed, 20 Dec 2000 06:47:26 -0800


Update of /cvsroot/python/python/dist/src/Lib/xml/dom
In directory usw-pr-cvs1:/tmp/cvs-serv20506

Modified Files:
	minidom.py pulldom.py 
Log Message:
Patch #102492, fixing bug #116677:
    give minidom.py behaviour that complies with the DOM Level 1 REC,
    which says that when a node newChild is added to the tree, "if the
    newChild is already in the tree, it is first removed."

    pulldom.py is patched to use the public minidom interface instead
    of setting .parentNode itself.  Possibly this reduces pulldom's 
    efficiency; someone else will have to pronounce on that.


Index: minidom.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/dom/minidom.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** minidom.py	2000/12/14 18:16:11	1.15
--- minidom.py	2000/12/20 14:47:24	1.16
***************
*** 41,44 ****
--- 41,45 ----
      def __init__(self):
          self.childNodes = []
+         self.parentNode = None
          if Node._debug:
              index = repr(id(self)) + repr(self.__class__)
***************
*** 99,102 ****
--- 100,105 ----
  
      def insertBefore(self, newChild, refChild):
+         if newChild.parentNode is not None:
+             newChild.parentNode.removeChild(newChild)
          if refChild is None:
              self.appendChild(newChild)
***************
*** 117,120 ****
--- 120,125 ----
  
      def appendChild(self, node):
+         if node.parentNode is not None:
+             node.parentNode.removeChild(node)
          if self.childNodes:
              last = self.lastChild
***************
*** 130,133 ****
--- 135,140 ----
  
      def replaceChild(self, newChild, oldChild):
+         if newChild.parentNode is not None:
+             newChild.parentNode.removeChild(newChild)
          if newChild is oldChild:
              return
***************
*** 145,148 ****
--- 152,161 ----
      def removeChild(self, oldChild):
          self.childNodes.remove(oldChild)
+         if oldChild.nextSibling is not None:
+             oldChild.nextSibling.previousSibling = oldChild.previousSibling
+         if oldChild.previousSibling is not None:
+             oldChild.previousSibling.nextSibling = oldChild.nextSibling            
+         oldChild.nextSibling = oldChild.previousSibling = None
+         
          if self._makeParentNodes:
              oldChild.parentNode = None
***************
*** 607,614 ****
--- 620,639 ----
  
      def appendChild(self, node):
+         if node.parentNode is not None:
+             node.parentNode.removeChild(node)
+ 
          if node.nodeType == Node.ELEMENT_NODE \
             and self._get_documentElement():
              raise TypeError, "two document elements disallowed"
          return Node.appendChild(self, node)
+ 
+     def removeChild(self, oldChild):
+         self.childNodes.remove(oldChild)
+         oldChild.nextSibling = oldChild.previousSibling = None
+         oldChild.parentNode = None
+         if self.documentElement is oldChild:
+             self.documentElement = None
+              
+         return oldChild
  
      def _get_documentElement(self):

Index: pulldom.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/dom/pulldom.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** pulldom.py	2000/12/14 18:00:18	1.12
--- pulldom.py	2000/12/20 14:47:24	1.13
***************
*** 56,60 ****
              node.setAttributeNode(attr)
  
!         node.parentNode = self.curNode
          self.curNode = node
  
--- 56,62 ----
              node.setAttributeNode(attr)
  
! ##        print self.curNode, self.curNode.childNodes, node, node.parentNode
!         self.curNode.appendChild(node)
! #        node.parentNode = self.curNode
          self.curNode = node
  
***************
*** 78,82 ****
              node.setAttributeNode(attr)
  
!         node.parentNode = self.curNode
          self.curNode = node
  
--- 80,85 ----
              node.setAttributeNode(attr)
  
!         #node.parentNode = self.curNode
!         self.curNode.appendChild(node)
          self.curNode = node
  
***************
*** 94,99 ****
      def comment(self, s):
          node = self.document.createComment(s)
!         parent = self.curNode
!         node.parentNode = parent
          self.lastEvent[1] = [(COMMENT, node), None]
          self.lastEvent = self.lastEvent[1]
--- 97,103 ----
      def comment(self, s):
          node = self.document.createComment(s)
!         self.curNode.appendChild(node)
! #        parent = self.curNode
! #        node.parentNode = parent
          self.lastEvent[1] = [(COMMENT, node), None]
          self.lastEvent = self.lastEvent[1]
***************
*** 103,108 ****
          node = self.document.createProcessingInstruction(target, data)
  
!         parent = self.curNode
!         node.parentNode = parent
          self.lastEvent[1] = [(PROCESSING_INSTRUCTION, node), None]
          self.lastEvent = self.lastEvent[1]
--- 107,113 ----
          node = self.document.createProcessingInstruction(target, data)
  
!         self.curNode.appendChild(node)
! #        parent = self.curNode
! #        node.parentNode = parent
          self.lastEvent[1] = [(PROCESSING_INSTRUCTION, node), None]
          self.lastEvent = self.lastEvent[1]
***************
*** 111,116 ****
      def ignorableWhitespace(self, chars):
          node = self.document.createTextNode(chars)
!         parent = self.curNode
!         node.parentNode = parent
          self.lastEvent[1] = [(IGNORABLE_WHITESPACE, node), None]
          self.lastEvent = self.lastEvent[1]
--- 116,122 ----
      def ignorableWhitespace(self, chars):
          node = self.document.createTextNode(chars)
!         self.curNode.appendChild(node)
! #        parent = self.curNode
! #        node.parentNode = parent
          self.lastEvent[1] = [(IGNORABLE_WHITESPACE, node), None]
          self.lastEvent = self.lastEvent[1]
***************
*** 119,124 ****
      def characters(self, chars):
          node = self.document.createTextNode(chars)
!         parent = self.curNode
!         node.parentNode = parent
          self.lastEvent[1] = [(CHARACTERS, node), None]
          self.lastEvent = self.lastEvent[1]
--- 125,131 ----
      def characters(self, chars):
          node = self.document.createTextNode(chars)
!         self.curNode.appendChild(node)
! #        parent = self.curNode
! #        node.parentNode = parent
          self.lastEvent[1] = [(CHARACTERS, node), None]
          self.lastEvent = self.lastEvent[1]