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

Fred L. Drake fdrake@users.sourceforge.net
Thu, 27 Sep 2001 21:33:08 -0700


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

Modified Files:
	minidom.py 
Log Message:
For Python 2.2 and newer, actually support the full NodeList interface by
subclassing list to add the length and item() attributes.


Index: minidom.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/xml/dom/minidom.py,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** minidom.py	2001/09/19 13:28:25	1.36
--- minidom.py	2001/09/28 04:33:06	1.37
***************
*** 33,36 ****
--- 33,53 ----
  _Node = xml.dom.Node
  
+ 
+ if list is type([]):
+     class NodeList(list):
+         def item(self, index):
+             if 0 <= index < len(self):
+                 return self[index]
+ 
+         def __getattr__(self, name):
+             if name == "length":
+                 return len(self)
+             raise AttributeError, name
+ 
+ else:
+     def NodeList():
+         return []
+     
+ 
  class Node(_Node):
      allnodes = {}
***************
*** 42,46 ****
  
      def __init__(self):
!         self.childNodes = []
          self.parentNode = self.ownerDocument = None
          if Node._debug:
--- 59,63 ----
  
      def __init__(self):
!         self.childNodes = NodeList()
          self.parentNode = self.ownerDocument = None
          if Node._debug:
***************
*** 235,239 ****
          if self._makeParentNodes:
              clone.parentNode = None
!         clone.childNodes = []
          if deep:
              for child in self.childNodes:
--- 252,256 ----
          if self._makeParentNodes:
              clone.parentNode = None
!         clone.childNodes = NodeList()
          if deep:
              for child in self.childNodes: