[Python-checkins] CVS: python/dist/src/Lib/xml/dom minidom.py,1.17,1.18

A.M. Kuchling python-dev@python.org
Sat, 30 Dec 2000 19:50:25 -0800


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

Modified Files:
	minidom.py 
Log Message:
Patch #102485 ] Check for legal children when adding children to a DOM node


Index: minidom.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/dom/minidom.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -r1.17 -r1.18
*** minidom.py	2000/12/28 18:40:56	1.17
--- minidom.py	2000/12/31 03:50:23	1.18
***************
*** 19,22 ****
--- 19,24 ----
  del string
  
+ from xml.dom import HierarchyRequestErr
+ 
  # localize the types, and allow support for Unicode values if available:
  import types
***************
*** 38,42 ****
      _makeParentNodes = 1
      debug = None
! 
      def __init__(self):
          self.childNodes = []
--- 40,45 ----
      _makeParentNodes = 1
      debug = None
!     childNodeTypes = ()
!     
      def __init__(self):
          self.childNodes = []
***************
*** 100,103 ****
--- 103,109 ----
  
      def insertBefore(self, newChild, refChild):
+         if newChild.nodeType not in self.childNodeTypes:
+             raise HierarchyRequestErr, \
+                   "%s cannot be child of %s" % (repr(newChild), repr(self) )
          if newChild.parentNode is not None:
              newChild.parentNode.removeChild(newChild)
***************
*** 120,123 ****
--- 126,132 ----
  
      def appendChild(self, node):
+         if node.nodeType not in self.childNodeTypes:
+             raise HierarchyRequestErr, \
+                   "%s cannot be child of %s" % (repr(node), repr(self) )
          if node.parentNode is not None:
              node.parentNode.removeChild(node)
***************
*** 135,138 ****
--- 144,150 ----
  
      def replaceChild(self, newChild, oldChild):
+         if newChild.nodeType not in self.childNodeTypes:
+             raise HierarchyRequestErr, \
+                   "%s cannot be child of %s" % (repr(newChild), repr(self) )
          if newChild.parentNode is not None:
              newChild.parentNode.removeChild(newChild)
***************
*** 251,255 ****
      attributes = None
      ownerElement = None
! 
      def __init__(self, qName, namespaceURI="", localName=None, prefix=None):
          # skip setattr for performance
--- 263,268 ----
      attributes = None
      ownerElement = None
!     childNodeTypes = (Node.TEXT_NODE, Node.ENTITY_REFERENCE_NODE)
!     
      def __init__(self, qName, namespaceURI="", localName=None, prefix=None):
          # skip setattr for performance
***************
*** 375,379 ****
      nextSibling = None
      previousSibling = None
! 
      def __init__(self, tagName, namespaceURI="", prefix="",
                   localName=None):
--- 388,395 ----
      nextSibling = None
      previousSibling = None
!     childNodeTypes = (Node.ELEMENT_NODE, Node.PROCESSING_INSTRUCTION_NODE,
!                       Node.COMMENT_NODE, Node.TEXT_NODE,
!                       Node.CDATA_SECTION_NODE, Node.ENTITY_REFERENCE_NODE)
!     
      def __init__(self, tagName, namespaceURI="", prefix="",
                   localName=None):
***************
*** 509,513 ****
      nodeName = "#comment"
      attributes = None
! 
      def __init__(self, data):
          Node.__init__(self)
--- 525,530 ----
      nodeName = "#comment"
      attributes = None
!     childNodeTypes = ()
!     
      def __init__(self, data):
          Node.__init__(self)
***************
*** 520,524 ****
      nodeType = Node.PROCESSING_INSTRUCTION_NODE
      attributes = None
! 
      def __init__(self, target, data):
          Node.__init__(self)
--- 537,542 ----
      nodeType = Node.PROCESSING_INSTRUCTION_NODE
      attributes = None
!     childNodeTypes = ()
!     
      def __init__(self, target, data):
          Node.__init__(self)
***************
*** 533,537 ****
      nodeName = "#text"
      attributes = None
! 
      def __init__(self, data):
          Node.__init__(self)
--- 551,556 ----
      nodeName = "#text"
      attributes = None
!     childNodeTypes = ()
!     
      def __init__(self, data):
          Node.__init__(self)
***************
*** 628,633 ****
--- 647,657 ----
  
      implementation = DOMImplementation()
+     childNodeTypes = (Node.ELEMENT_NODE, Node.PROCESSING_INSTRUCTION_NODE,
+                       Node.COMMENT_NODE, Node.DOCUMENT_TYPE_NODE)
  
      def appendChild(self, node):
+         if node.nodeType not in self.childNodeTypes:
+             raise HierarchyRequestErr, \
+                   "%s cannot be child of %s" % (repr(node), repr(self) )
          if node.parentNode is not None:
              node.parentNode.removeChild(node)