[Zope-Checkins] CVS: Zope/lib/python/StructuredText - STDOM.py:1.7.4.3

Chris McDonough chrism@zope.com
Tue, 8 Oct 2002 17:46:24 -0400


Update of /cvs-repository/Zope/lib/python/StructuredText
In directory cvs.zope.org:/tmp/cvs-serv17057/lib/python/StructuredText

Modified Files:
      Tag: chrism-install-branch
	STDOM.py 
Log Message:
More merges from HEAD.


=== Zope/lib/python/StructuredText/STDOM.py 1.7.4.2 => 1.7.4.3 ===
--- Zope/lib/python/StructuredText/STDOM.py:1.7.4.2	Tue Oct  8 14:41:12 2002
+++ Zope/lib/python/StructuredText/STDOM.py	Tue Oct  8 17:45:53 2002
@@ -16,6 +16,9 @@
 All standard Zope objects support DOM to a limited extent.
 """
 
+from types import StringType, UnicodeType
+StringTypes = (StringType, UnicodeType)
+
 # Node type codes
 # ---------------
 
@@ -81,7 +84,7 @@
     the child access methods of the DOM.
     """
 
-    def getChildNodes(self, type=type, st=type('')):
+    def getChildNodes(self, type=type, sts=StringTypes):
         """
         Returns a NodeList that contains all children of this node.
         If there are no children, this is a empty NodeList
@@ -89,12 +92,12 @@
 
         r=[]
         for n in self.getChildren():
-            if type(n) is st: n=TextNode(n)
+            if type(n) in sts: n=TextNode(n)
             r.append(n.__of__(self))
 
         return  NodeList(r)
 
-    def getFirstChild(self, type=type, st=type('')):
+    def getFirstChild(self, type=type, sts=StringTypes):
         """
         The first child of this node. If there is no such node
         this returns None
@@ -106,12 +109,12 @@
 
         n=children[0]
 
-        if type(n) is st:
+        if type(n) in sts:
             n=TextNode(n)
 
         return n.__of__(self)
 
-    def getLastChild(self, type=type, st=type('')):
+    def getLastChild(self, type=type, sts=StringTypes):
         """
         The last child of this node.  If there is no such node
         this returns None.
@@ -119,21 +122,21 @@
         children = self.getChildren()
         if not children: return None
         n=chidren[-1]
-        if type(n) is st: n=TextNode(n)
+        if type(n) in sts: n=TextNode(n)
         return n.__of__(self)
 
     """
     create aliases for all above functions in the pythony way.
     """
 
-    def _get_ChildNodes(self, type=type, st=type('')):
-        return self.getChildNodes(type,st)
+    def _get_ChildNodes(self, type=type, sts=StringTypes):
+        return self.getChildNodes(type,sts)
 
-    def _get_FirstChild(self, type=type, st=type('')):
-        return self.getFirstChild(type,st)
+    def _get_FirstChild(self, type=type, sts=StringTypes):
+        return self.getFirstChild(type,sts)
 
-    def _get_LastChild(self, type=type, st=type('')):
-        return self.getLastChild(type,st)
+    def _get_LastChild(self, type=type, sts=StringTypes):
+        return self.getLastChild(type,sts)
 
 class NodeWrapper(ParentNode):
     """
@@ -167,9 +170,8 @@
 
     def getPreviousSibling(self,
                            type=type,
-                           st=type(''),
-                           getattr=getattr,
-                           None=None):
+                           sts=StringTypes,
+                           getattr=getattr):
 
         """
         The node immediately preceding this node.  If
@@ -190,13 +192,13 @@
         try: n=children[index]
         except IndexError: return None
         else:
-            if type(n) is st:
+            if type(n) in sts:
                 n=TextNode(n)
             n._DOMIndex=index
             return n.__of__(self)
 
 
-    def getNextSibling(self, type=type, st=type('')):
+    def getNextSibling(self, type=type, sts=StringTypes):
         """
         The node immediately preceding this node.  If
         there is no such node, this returns None.
@@ -216,7 +218,7 @@
         except IndexError:
             return None
         else:
-            if type(n) is st:
+            if type(n) in sts:
                 n=TextNode(n)
             n._DOMIndex=index
             return n.__of__(self)
@@ -239,14 +241,13 @@
 
     def _get_PreviousSibling(self,
                            type=type,
-                           st=type(''),
-                           getattr=getattr,
-                           None=None):
+                           sts=StringTypes,
+                           getattr=getattr):
 
-        return self.getPreviousSibling(type,st,getattr,None)
+        return self.getPreviousSibling(type,sts,getattr,None)
 
-    def _get_NextSibling(self, type=type, st=type('')):
-        return self.getNextSibling(type,st)
+    def _get_NextSibling(self, type=type, sts=StringTypes):
+        return self.getNextSibling(type,sts)
 
     def _get_OwnerDocument(self):
         return self.getOwnerDocument()
@@ -288,15 +289,14 @@
 
     def getPreviousSibling(self,
                            type=type,
-                           st=type(''),
-                           getattr=getattr,
-                           None=None):
+                           sts=StringTypes,
+                           getattr=getattr):
         """
         The node immediately preceding this node.  If
         there is no such node, this returns None.
         """
 
-    def getNextSibling(self, type=type, st=type('')):
+    def getNextSibling(self, type=type, sts=StringTypes):
         """
         The node immediately preceding this node.  If
         there is no such node, this returns None.
@@ -342,13 +342,12 @@
 
     def _get_PreviousSibling(self,
                            type=type,
-                           st=type(''),
-                           getattr=getattr,
-                           None=None):
+                           sts=StringTypes,
+                           getattr=getattr):
 
-        return self.getPreviousSibling(type,st,getattr,None)
+        return self.getPreviousSibling(type,sts,getattr,None)
 
-    def _get_NextSibling(self, type=type, st=type('')):
+    def _get_NextSibling(self, type=type, sts=StringTypes):
         return self.getNextSibling()
 
     def _get_Attributes(self):
@@ -407,10 +406,10 @@
         """A code representing the type of the node."""
         return ELEMENT_NODE
 
-    def getNodeValue(self, type=type, st=type('')):
+    def getNodeValue(self, type=type, sts=StringTypes):
         r=[]
         for c in self.getChildren():
-            if type(c) is not st:
+            if type(c) not in sts:
                 c=c.getNodeValue()
             r.append(c)
         return ''.join(r)
@@ -480,8 +479,8 @@
     def _get_NodeType(self):
         return self.getNodeType()
 
-    def _get_NodeValue(self, type=type, st=type('')):
-        return self.getNodeValue(type,st)
+    def _get_NodeValue(self, type=type, sts=StringTypes):
+        return self.getNodeValue(type,sts)
 
     def _get_ParentNode(self):
         return self.getParentNode()
@@ -517,7 +516,7 @@
     def __init__(self,list=None):
         self._data = list or []
 
-    def __getitem__(self, index, type=type, st=type('')):
+    def __getitem__(self, index, type=type, sts=StringTypes):
         return self._data[index]
 
     def __getslice__(self, i, j):