[Zope-Checkins] CVS: Zope/lib/python/StructuredText - ClassicDocumentClass.py:1.25.4.1 DocumentClass.py:1.49.4.1 STDOM.py:1.7.4.1 __init__.py:1.9.4.1

Chris McDonough chrism@zope.com
Sat, 28 Sep 2002 21:41:06 -0400


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

Modified Files:
      Tag: chrism-install-branch
	ClassicDocumentClass.py DocumentClass.py STDOM.py __init__.py 
Log Message:
Merge chrism-install-branch with head.  Apologies for the spew.


=== Zope/lib/python/StructuredText/ClassicDocumentClass.py 1.25 => 1.25.4.1 ===
--- Zope/lib/python/StructuredText/ClassicDocumentClass.py:1.25	Wed Aug 14 17:58:22 2002
+++ Zope/lib/python/StructuredText/ClassicDocumentClass.py	Sat Sep 28 21:40:35 2002
@@ -14,8 +14,8 @@
 import re, ST, STDOM
 from STletters import letters
 
-StringType=type('')
-ListType=type([])
+from types import StringType, UnicodeType, ListType
+StringTypes = (StringType, UnicodeType)
 
 class StructuredTextExample(ST.StructuredTextParagraph):
     """Represents a section of document with literal text, as for examples"""
@@ -235,7 +235,7 @@
         ]
 
     def __call__(self, doc):
-        if type(doc) is type(''):
+        if type(doc) in StringTypes:
             doc=ST.StructuredText(doc)
             doc.setSubparagraphs(self.color_paragraphs(
                doc.getSubparagraphs()))
@@ -245,7 +245,7 @@
         return doc
 
     def parse(self, raw_string, text_type,
-              type=type, st=type(''), lt=type([])):
+              type=type, sts=StringTypes, lt=type([])):
 
         """
         Parse accepts a raw_string, an expr to test the raw_string,
@@ -261,7 +261,7 @@
         tmp = []    # the list to be returned if raw_string is split
         append=tmp.append
 
-        if type(text_type) is st: text_type=getattr(self, text_type)
+        if type(text_type) in sts: text_type=getattr(self, text_type)
 
         while 1:
             t = text_type(raw_string)
@@ -272,7 +272,7 @@
             if start: append(raw_string[0:start])
 
             tt=type(t)
-            if tt is st:
+            if tt in sts:
                 # if we get a string back, add it to text to be parsed
                 raw_string = t+raw_string[end:len(raw_string)]
             else:
@@ -299,12 +299,12 @@
 
         for text_type in types:
 
-            if type(str) is StringType:
+            if type(str) in StringTypes:
                 str = self.parse(str, text_type)
             elif type(str) is ListType:
                 r=[]; a=r.append
                 for s in str:
-                    if type(s) is StringType:
+                    if type(s) in StringTypes:
                         s=self.parse(s, text_type)
                         if type(s) is ListType: r[len(r):]=s
                         else: a(s)
@@ -327,7 +327,7 @@
 
     def color_paragraphs(self, raw_paragraphs,
                            type=type, sequence_types=(type([]), type(())),
-                           st=type('')):
+                           sts=StringTypes):
         result=[]
         for paragraph in raw_paragraphs:
 
@@ -336,7 +336,7 @@
                 continue
 
             for pt in self.paragraph_types:
-                if type(pt) is st:
+                if type(pt) in sts:
                     # grab the corresponding function
                     pt=getattr(self, pt)
                 # evaluate the paragraph


=== Zope/lib/python/StructuredText/DocumentClass.py 1.49 => 1.49.4.1 ===
--- Zope/lib/python/StructuredText/DocumentClass.py:1.49	Wed Aug 14 17:58:22 2002
+++ Zope/lib/python/StructuredText/DocumentClass.py	Sat Sep 28 21:40:35 2002
@@ -15,8 +15,8 @@
 from STletters import letters, digits, literal_punc, under_punc,\
      strongem_punc, phrase_delimiters,dbl_quoted_punc
 
-StringType=type('')
-ListType=type([])
+from types import StringType, UnicodeType, ListType
+StringTypes = (StringType, UnicodeType)
 
 def flatten(obj, append):
     if obj.getNodeType()==STDOM.TEXT_NODE:
@@ -308,7 +308,7 @@
         ]
 
     def __call__(self, doc):
-        if type(doc) is type(''):
+        if type(doc) in StringTypes:
             doc=ST.StructuredText(doc)
             doc.setSubparagraphs(self.color_paragraphs(
                doc.getSubparagraphs()))
@@ -318,7 +318,7 @@
         return doc
 
     def parse(self, raw_string, text_type,
-              type=type, st=type(''), lt=type([])):
+              type=type, sts=StringTypes, lt=type([])):
 
         """
         Parse accepts a raw_string, an expr to test the raw_string,
@@ -334,7 +334,7 @@
         tmp = []    # the list to be returned if raw_string is split
         append=tmp.append
 
-        if type(text_type) is st: text_type=getattr(self, text_type)
+        if type(text_type) in sts: text_type=getattr(self, text_type)
 
         while 1:
             t = text_type(raw_string)
@@ -345,7 +345,7 @@
             if start: append(raw_string[0:start])
 
             tt=type(t)
-            if tt is st:
+            if tt in sts:
                 # if we get a string back, add it to text to be parsed
                 raw_string = t+raw_string[end:len(raw_string)]
             else:
@@ -372,12 +372,12 @@
 
         for text_type in types:
 
-            if type(str) is StringType:
+            if type(str) in StringTypes:
                 str = self.parse(str, text_type)
             elif type(str) is ListType:
                 r=[]; a=r.append
                 for s in str:
-                    if type(s) is StringType:
+                    if type(s) in StringTypes:
                         s=self.parse(s, text_type)
                         if type(s) is ListType: r[len(r):]=s
                         else: a(s)
@@ -400,7 +400,7 @@
 
     def color_paragraphs(self, raw_paragraphs,
                            type=type, sequence_types=(type([]), type(())),
-                           st=type('')):
+                           sts=StringTypes):
         result=[]
         for paragraph in raw_paragraphs:
             if paragraph.getNodeName() != 'StructuredTextParagraph':
@@ -408,7 +408,7 @@
                 continue
 
             for pt in self.paragraph_types:
-                if type(pt) is st:
+                if type(pt) in sts:
                     # grab the corresponding function
                     pt=getattr(self, pt)
                 # evaluate the paragraph


=== Zope/lib/python/StructuredText/STDOM.py 1.7 => 1.7.4.1 ===
--- Zope/lib/python/StructuredText/STDOM.py:1.7	Wed Aug 14 17:58:22 2002
+++ Zope/lib/python/StructuredText/STDOM.py	Sat Sep 28 21:40:35 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,7 +170,7 @@
 
     def getPreviousSibling(self,
                            type=type,
-                           st=type(''),
+                           sts=StringTypes,
                            getattr=getattr,
                            None=None):
 
@@ -190,13 +193,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 +219,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 +242,14 @@
 
     def _get_PreviousSibling(self,
                            type=type,
-                           st=type(''),
+                           sts=StringTypes,
                            getattr=getattr,
                            None=None):
 
-        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,7 +291,7 @@
 
     def getPreviousSibling(self,
                            type=type,
-                           st=type(''),
+                           sts=StringTypes,
                            getattr=getattr,
                            None=None):
         """
@@ -296,7 +299,7 @@
         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 +345,13 @@
 
     def _get_PreviousSibling(self,
                            type=type,
-                           st=type(''),
+                           sts=StringTypes,
                            getattr=getattr,
                            None=None):
 
-        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 +410,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 +483,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 +520,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):


=== Zope/lib/python/StructuredText/__init__.py 1.9 => 1.9.4.1 ===
--- Zope/lib/python/StructuredText/__init__.py:1.9	Wed Aug 14 17:58:22 2002
+++ Zope/lib/python/StructuredText/__init__.py	Sat Sep 28 21:40:35 2002
@@ -17,14 +17,14 @@
 from ST import Basic
 import DocBookClass
 import HTMLWithImages
-from types import StringType
+from types import StringType, UnicodeType
 import DocumentWithImages
 
 ClassicHTML=HTML
 HTMLNG=HTMLClass.HTMLClass()
 
 def HTML(src, level=1):
-    if isinstance(src, StringType):
+    if isinstance(src, StringType) or isinstance(src, UnicodeType):
         return ClassicHTML(src, level)
     return HTMLNG(src, level)