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

Fred L. Drake, Jr. fdrake@acm.org
Tue, 20 Aug 2002 16:34:16 -0400


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

Modified Files:
      Tag: Zope-2_7-development-branch
	STDOM.py 
Log Message:
Remove unnecessary aliasing.  Python 2.3 issues a SyntaxWarning when binding
to the name None.  Switch to using isinstance() in affected locations.


=== Zope27/lib/python/StructuredText/STDOM.py 1.6 => 1.6.4.1 ===
--- Zope27/lib/python/StructuredText/STDOM.py:1.6	Fri Jun  7 21:10:25 2002
+++ Zope27/lib/python/StructuredText/STDOM.py	Tue Aug 20 16:34:15 2002
@@ -81,7 +81,7 @@
    the child access methods of the DOM.
    """
 
-   def getChildNodes(self, type=type, st=type('')):
+   def getChildNodes(self):
       """
       Returns a NodeList that contains all children of this node.
       If there are no children, this is a empty NodeList
@@ -89,12 +89,13 @@
       
       r=[]
       for n in self.getChildren():
-         if type(n) is st: n=TextNode(n)
+         if isinstance(n, str):
+            n=TextNode(n)
          r.append(n.__of__(self))
       
-      return  NodeList(r)
+      return NodeList(r)
    
-   def getFirstChild(self, type=type, st=type('')):
+   def getFirstChild(self):
       """
       The first child of this node. If there is no such node
       this returns None
@@ -106,12 +107,12 @@
          
       n=children[0]
 
-      if type(n) is st:
+      if isinstance(n, str):
          n=TextNode(n)
          
       return n.__of__(self)
 
-   def getLastChild(self, type=type, st=type('')):
+   def getLastChild(self):
       """
       The last child of this node.  If there is no such node
       this returns None.
@@ -119,21 +120,22 @@
       children = self.getChildren()
       if not children: return None
       n=chidren[-1]
-      if type(n) is st: n=TextNode(n)
+      if isinstance(n, str):
+         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):
+      return self.getChildNodes(type)
    
-   def _get_FirstChild(self, type=type, st=type('')):
-      return self.getFirstChild(type,st)
+   def _get_FirstChild(self):
+      return self.getFirstChild(type)
 
-   def _get_LastChild(self, type=type, st=type('')):
-      return self.getLastChild(type,st)
+   def _get_LastChild(self):
+      return self.getLastChild(type)
   
 class NodeWrapper(ParentNode):
    """
@@ -165,12 +167,7 @@
          i=i+1
       return None
 
-   def getPreviousSibling(self,
-                          type=type,
-                          st=type(''),
-                          getattr=getattr,
-                          None=None):
-
+   def getPreviousSibling(self):
       """
       The node immediately preceding this node.  If
       there is no such node, this returns None.
@@ -190,13 +187,13 @@
       try: n=children[index]
       except IndexError: return None
       else:
-         if type(n) is st:
+         if isinstance(n, str):
             n=TextNode(n)
          n._DOMIndex=index
          return n.__of__(self)
 
 
-   def getNextSibling(self, type=type, st=type('')):
+   def getNextSibling(self):
       """
       The node immediately preceding this node.  If
       there is no such node, this returns None.
@@ -216,7 +213,7 @@
       except IndexError:
          return None
       else:
-         if type(n) is st:
+         if isinstance(n, str):
             n=TextNode(n)
          n._DOMIndex=index
          return n.__of__(self)
@@ -237,16 +234,11 @@
    def _get_DOMIndex(self, children, getattr=getattr):
       return self._getDOMIndex(children,getattr)
       
-   def _get_PreviousSibling(self,
-                          type=type,
-                          st=type(''),
-                          getattr=getattr,
-                          None=None):
-
-      return self.getPreviousSibling(type,st,getattr,None)
+   def _get_PreviousSibling(self):
+      return self.getPreviousSibling(type,type(''),getattr,None)
       
-   def _get_NextSibling(self, type=type, st=type('')):
-      return self.getNextSibling(type,st)
+   def _get_NextSibling(self):
+      return self.getNextSibling(type,type(''))
       
    def _get_OwnerDocument(self):
       return self.getOwnerDocument()
@@ -286,17 +278,13 @@
       """
       return ()
 
-   def getPreviousSibling(self,
-                          type=type,
-                          st=type(''),
-                          getattr=getattr,
-                          None=None):
+   def getPreviousSibling(self):
       """
       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):
       """
       The node immediately preceding this node.  If
       there is no such node, this returns None.
@@ -340,15 +328,10 @@
    def _get_Children(self):
       return self.getChildren()
 
-   def _get_PreviousSibling(self,
-                          type=type,
-                          st=type(''),
-                          getattr=getattr,
-                          None=None):
+   def _get_PreviousSibling(self):
+      return self.getPreviousSibling(type,type(''),getattr,None)
       
-      return self.getPreviousSibling(type,st,getattr,None)
-      
-   def _get_NextSibling(self, type=type, st=type('')):
+   def _get_NextSibling(self):
       return self.getNextSibling()
 
    def _get_Attributes(self):
@@ -363,7 +346,8 @@
          
 class TextNode(Node):
 
-   def __init__(self, str): self._value=str
+   def __init__(self, str):
+       self._value=str
       
    def getNodeType(self):
       return TEXT_NODE
@@ -407,10 +391,10 @@
       """A code representing the type of the node."""
       return ELEMENT_NODE
 
-   def getNodeValue(self, type=type, st=type('')):
+   def getNodeValue(self):
       r=[]
       for c in self.getChildren():
-         if type(c) is not st:
+         if not isinstance(c, str):
             c=c.getNodeValue()
          r.append(c)
       return ''.join(r)
@@ -426,7 +410,8 @@
     
    _attributes=()
 
-   def getAttribute(self, name): return getattr(self, name, None)
+   def getAttribute(self, name):
+       return getattr(self, name, None)
    def getAttributeNode(self, name):
       if hasattr(self, name):
          return Attr(name, getattr(self, name))
@@ -480,8 +465,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):
+      return self.getNodeValue(type)
       
    def _get_ParentNode(self):
       return self.getParentNode()
@@ -517,7 +502,7 @@
    def __init__(self,list=None):
       self._data = list or []
     
-   def __getitem__(self, index, type=type, st=type('')):
+   def __getitem__(self, index):
       return self._data[index]
 
    def __getslice__(self, i, j):