[Zope-Checkins] CVS: Zope2 - DocumentClass.py:1.5.6.1 STNG.txt:1.2.6.1 StructuredText.py:1.30.4.3

Brian Lloyd brian@digiciool.com
Wed, 7 Mar 2001 16:32:04 -0500 (EST)


Update of /cvs-repository/Zope2/lib/python/StructuredText
In directory korak:/home/brian/temp/zope-23-branch/lib/python/StructuredText

Modified Files:
      Tag: zope-2_3-branch
	DocumentClass.py STNG.txt StructuredText.py 
Log Message:
Fixed bug #2016: usage of raw strings in regexes



--- Updated File DocumentClass.py in package Zope2 --
--- DocumentClass.py	2001/01/08 21:46:59	1.5
+++ DocumentClass.py	2001/03/07 21:32:04	1.5.6.1
@@ -494,7 +494,7 @@
 
        return result
     
-    def doc_table(self, paragraph, expr = re.compile('\s*\|[-]+\|').match):
+    def doc_table(self, paragraph, expr = re.compile(r'\s*\|[-]+\|').match):
         text    = paragraph.getColorizableTexts()[0]
         m       = expr(text)
         
@@ -747,7 +747,7 @@
             cols = []
         return StructuredTextTable(rows,text,subs,indent=paragraph.indent)
             
-    def doc_bullet(self, paragraph, expr = re.compile('\s*[-*o]\s+').match):
+    def doc_bullet(self, paragraph, expr = re.compile(r'\s*[-*o]\s+').match):
         top=paragraph.getColorizableTexts()[0]
         m=expr(top)
 
@@ -765,7 +765,7 @@
 
     def doc_numbered(
         self, paragraph,
-        expr = re.compile('(\s*[a-zA-Z]+\.)|(\s*[0-9]+\.)|(\s*[0-9]+\s+)').match):
+        expr = re.compile(r'(\s*[a-zA-Z]+\.)|(\s*[0-9]+\.)|(\s*[0-9]+\s+)').match):
         
         # This is the old expression. It had a nasty habit
         # of grabbing paragraphs that began with a single
@@ -789,7 +789,7 @@
 
     def doc_description(
         self, paragraph,
-        delim = re.compile('\s+--\s+').search,
+        delim = re.compile(r'\s+--\s+').search,
         nb=re.compile(r'[^\0- ]').search,
         ):
 
@@ -814,7 +814,7 @@
            delim=d)
 
     def doc_header(self, paragraph,
-                    expr    = re.compile('[ a-zA-Z0-9.:/,-_*<>\?\'\"]+').match
+                    expr    = re.compile(r'[ a-zA-Z0-9.:/,-_*<>\?\'\"]+').match
                     ):
         subs=paragraph.getSubparagraphs()
         if not subs: return None
@@ -832,9 +832,9 @@
     def doc_literal(
         self, s,
         expr=re.compile(
-          "(?:\s|^)'"                                                  # open
-          "([^ \t\n\r\f\v']|[^ \t\n\r\f\v'][^\n']*[^ \t\n\r\f\v'])" # contents
-          "'(?:\s|[,.;:!?]|$)"                                        # close
+          r"(?:\s|^)'"                                                  # open
+          r"([^ \t\n\r\f\v']|[^ \t\n\r\f\v'][^\n']*[^ \t\n\r\f\v'])" # contents
+          r"'(?:\s|[,.;:!?]|$)"                                        # close
           ).search):
         
         r=expr(s)
@@ -846,7 +846,7 @@
 
     def doc_emphasize(
         self, s,
-        expr = re.compile('\s*\*([ \na-zA-Z0-9.:/;,\'\"\?]+)\*(?!\*|-)').search
+        expr = re.compile(r'\s*\*([ \na-zA-Z0-9.:/;,\'\"\?\-\_\/\=]+)\*(?!\*|-)').search
         ):
 
         r=expr(s)
@@ -858,8 +858,8 @@
     
     def doc_inner_link(self,
                        s,
-                       expr1 = re.compile("\.\.\s*").search,
-                       expr2 = re.compile("\[[a-zA-Z0-9]+\]").search):
+                       expr1 = re.compile(r"\.\.\s*").search,
+                       expr2 = re.compile(r"\[[a-zA-Z0-9]+\]").search):
         
         # make sure we dont grab a named link
         if expr2(s) and expr1(s):
@@ -879,7 +879,7 @@
     
     def doc_named_link(self,
                        s,
-                       expr=re.compile("(\.\.\s)(\[[a-zA-Z0-9]+\])").search):
+                       expr=re.compile(r"(\.\.\s)(\[[a-zA-Z0-9]+\])").search):
         
         result = expr(s)
         if result:
@@ -893,7 +893,7 @@
     
     def doc_underline(self,
                       s,
-                      expr=re.compile("\_([a-zA-Z0-9\s\.,\?]+)\_").search):
+                      expr=re.compile(r"\_([a-zA-Z0-9\s\.,\?]+)\_").search):
         
         result = expr(s)
         if result:
@@ -905,7 +905,7 @@
     
     def doc_strong(self, 
                    s,
-        expr = re.compile('\s*\*\*([ \na-zA-Z0-9.:/;\-,!\?\'\"]+)\*\*').search
+        expr = re.compile(r'\s*\*\*([ \na-zA-Z0-9.:/;\-,!\?\'\"]+)\*\*').search
         ):
 
         r=expr(s)
@@ -914,14 +914,17 @@
            return (StructuredTextStrong(s[start:end]), start-2, end+2)
         else:
            return None
+
+    ## Some constants to make the doc_href() regex easier to read.
+    _DQUOTEDTEXT = r'("[ a-zA-Z0-9\n\-\.\,\;\(\)\/\:\/]+")' ## double quoted text
+    _URL_AND_PUNC = r'([a-zA-Z0-9\@\.\,\?\!\/\:\;\-\#\~]+)'
+    _SPACES = r'(\s*)'
     
-    def doc_href(
-        
-        self, s,
-        expr1 = re.compile("(\"[ a-zA-Z0-9\n\-\.\,\;\(\)\/\:\/]+\")(:)([a-zA-Z0-9\:\/\.\~\-]+)([,]*\s*)").search,
-        expr2 = re.compile('(\"[ a-zA-Z0-9\n\-\.\:\;\(\)\/]+\")([,]+\s+)([a-zA-Z0-9\@\.\,\?\!\/\:\;\-\#]+)(\s*)').search):
+    def doc_href(self, s,
+                 expr1 = re.compile(_DQUOTEDTEXT + "(:)" + _URL_AND_PUNC + _SPACES).search,
+                 expr2 = re.compile(_DQUOTEDTEXT + r'(\,\s+)' + _URL_AND_PUNC + _SPACES).search):
         
-        punctuation = re.compile("[\,\.\?\!\;]+").match
+        punctuation = re.compile(r"[\,\.\?\!\;]+").match
         r=expr1(s) or expr2(s)
 
         if r:
@@ -948,7 +951,7 @@
         else:
             return None
     
-    def doc_sgml(self,s,expr=re.compile("\<[a-zA-Z0-9\.\=\'\"\:\/\-\#\+\s\*]+\>").search):
+    def doc_sgml(self,s,expr=re.compile(r"\<[a-zA-Z0-9\.\=\'\"\:\/\-\#\+\s\*]+\>").search):
         """
         SGML text is ignored and outputed as-is
         """

--- Updated File STNG.txt in package Zope2 --
--- STNG.txt	2001/01/04 15:01:59	1.2
+++ STNG.txt	2001/03/07 21:32:04	1.2.6.1
@@ -18,7 +18,7 @@
     st=StructuredText.Basic(raw)
 
   The output of 'StructuredText.Basic' is simply a
-  StructuredTextDocumemt object containing StructuredTextParagraph
+  StructuredTextDocument object containing StructuredTextParagraph
   objects arranged in a hierarchy. Paragraphs are delimited by strings
   of two or more whitespace characters beginning and ending with
   newline characters. Hierarchy is indicated by indentation. The

--- Updated File StructuredText.py in package Zope2 --
--- StructuredText.py	2001/02/12 20:45:55	1.30.4.2
+++ StructuredText.py	2001/03/07 21:32:04	1.30.4.3
@@ -121,15 +121,15 @@
   word 'examples', or '::' is treated as example code and is output as is.
 
 - Text enclosed single quotes (with white-space to the left of the
-  first quote and whitespace or puctuation to the right of the second quote)
+  first quote and whitespace or punctuation to the right of the second quote)
   is treated as example code.
 
 - Text surrounded by '*' characters (with white-space to the left of the
-  first '*' and whitespace or puctuation to the right of the second '*')
+  first '*' and whitespace or punctuation to the right of the second '*')
   is emphasized.
 
 - Text surrounded by '**' characters (with white-space to the left of the
-  first '**' and whitespace or puctuation to the right of the second '**')
+  first '**' and whitespace or punctuation to the right of the second '**')
   is made strong.
 
 - Text surrounded by '_' underscore characters (with whitespace to the left 
@@ -256,6 +256,9 @@
 #   (540) 371-6909
 #
 # $Log$
+# Revision 1.30.4.3  2001/03/07 21:32:04  brian
+# Fixed bug #2016: usage of raw strings in regexes
+#
 # Revision 1.30.4.2  2001/02/12 20:45:55  brian
 # fixed bug 1908 (CRLF fix)
 #