changes to userguide code py33
authorrobin
Mon, 18 Nov 2013 17:28:48 +0000
branchpy33
changeset 3789 5bc95e1f3dd4
parent 3788 fcfa76effd45
child 3790 2d62ae94f4cb
changes to userguide code
docs/userguide/ch2a_fonts.py
tools/docco/examples.py
tools/docco/rl_doc_utils.py
tools/docco/t_parse.py
--- a/docs/userguide/ch2a_fonts.py	Mon Nov 18 17:28:23 2013 +0000
+++ b/docs/userguide/ch2a_fonts.py	Mon Nov 18 17:28:48 2013 +0000
@@ -327,7 +327,7 @@
 registerFontFamily('Vera',normal='Vera',bold='VeraBd',italic='VeraIt',boldItalic='VeraBI')
 
 disc("""Before using the TT Fonts in Platypus we should add a mapping from the family name to the
-individual font names that describe the behaviour under the $<b>$ and $<i>$ attributes.""")
+individual font names that describe the behaviour under the $&lt;b&gt;$ and $&lt;i&gt;$ attributes.""")
 
 eg("""
 from reportlab.pdfbase.pdfmetrics import registerFontFamily
--- a/tools/docco/examples.py	Mon Nov 18 17:28:23 2013 +0000
+++ b/tools/docco/examples.py	Mon Nov 18 17:28:48 2013 +0000
@@ -1,8 +1,6 @@
 #Copyright ReportLab Europe Ltd. 2000-2012
 #see license.txt for license details
 #history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/tools/docco/examples.py
-import string
-
 testannotations="""
 def annotations(canvas):
     from reportlab.lib.units import inch
@@ -19,7 +17,7 @@
 
 test1 = """
 def f(a,b):
-    print "it worked", a, b
+    print("it worked", a, b)
     return a+b
 """
 
@@ -427,7 +425,7 @@
 and she'll have fun fun fun
 til her Daddy takes the keyboard away'''
 
-lyrics = string.split(lyrics, "\n")
+lyrics = lyrics.split("\n")
 testtextsize = """
 def textsize(canvas):
     from reportlab.lib.units import inch
@@ -852,15 +850,10 @@
     canvas.drawCentredString(3*Wd+2*W+W/2, Hd+H-H/4, "College Life")
 
 # D = dir()
-g = globals()
-Dprime = {}
-from types import StringType
-from string import strip
-for a,b in g.items():
-    if a[:4]=="test" and type(b) is StringType:
-        #print 'for', a
-        #print b
-        b = strip(b)
+TESTS=[(a,b) for a, b in globals().items() if a.startswith('test')]
+for a,b in TESTS:
+    if isinstance(b,str):
+        b = b.strip()
         exec(b+'\n')
 
 platypussetup = """
@@ -905,6 +898,6 @@
 if __name__=="__main__":
     # then do the platypus hello world
     for b in platypussetup, platypusfirstpage, platypusnextpage, platypusgo:
-        b = strip(b)
+        b = b.strip()
         exec(b+'\n')
     go()
--- a/tools/docco/rl_doc_utils.py	Mon Nov 18 17:28:23 2013 +0000
+++ b/tools/docco/rl_doc_utils.py	Mon Nov 18 17:28:48 2013 +0000
@@ -46,7 +46,6 @@
        format the arg as replaceable.  The escape sequence for literal
        $ is $\\$ (^ is ^\\^.
     """
-    from string import join
     for (template,subst) in [(QFcodetemplate, codesubst), (QFreptemplate, QFsubst)]:
         fragment = text
         parts = []
@@ -65,7 +64,7 @@
                     fragment = fragment[index:]
         except ValueError:
             parts.append(fragment)
-        text = join(parts, "")
+        text = ''.join(parts)
     return text
 #print quickfix("$testing$ testing $one$ ^two^ $three(^four^)$")
 
@@ -126,7 +125,7 @@
 def restartList():
     getSequencer().reset('list1')
 
-def list(text, doBullet=1):
+def list1(text, doBullet=1):
     text=quickfix(text)
     if doBullet:
         text='<bullet><seq id="list1"/>.</bullet>'+text
@@ -311,7 +310,7 @@
         for key, value in style.__dict__.items():
             lines.append('%s = %s' % (key, value))
         lines.sort()
-        return string.join(lines, '\n')
+        return '\n'.join(lines)
 
     def drawFigure(self):
 
@@ -349,7 +348,7 @@
         for key, value in style.__dict__.items():
             if key not in ('name','parent'):
                 lines.append('%s = %s' % (key, value))
-        return string.join(lines, '\n')
+        return '\n'.join(lines)
 
 
 class ParaBox2(figures.Figure):
--- a/tools/docco/t_parse.py	Mon Nov 18 17:28:23 2013 +0000
+++ b/tools/docco/t_parse.py	Mon Nov 18 17:28:48 2013 +0000
@@ -80,8 +80,7 @@
 """
 
 import re, string
-from types import StringType
-from string import find
+from reportlab.lib.utils import ascii_letters
 
 #
 # template parsing
@@ -114,7 +113,7 @@
        # compile the regular expressions if needed
        self.marker_dict = marker_dict = {}
        for mark, rgex in marker_to_regex_dict.items():
-           if type(rgex) == StringType:
+           if isinstance(rgex,str):
               rgex = re.compile(rgex)
            marker_dict[mark] = rgex
        # determine the parse sequence
@@ -158,7 +157,7 @@
        self.parse_seq = parse_seq
        self.ndirectives = ndirectives
 
-   def PARSE(self, str, start=0):
+   def PARSE(self, s, start=0):
        ndirectives = self.ndirectives
        wild_card = self.wild_card
        single_char = self.char
@@ -173,7 +172,7 @@
            (indicator, data) = parse_seq[parse_index]
            # is it a literal indicator?
            if indicator is None:
-              if find(str, data, currentindex) != currentindex:
+              if s.find(data, currentindex) != currentindex:
                  raise ValueError("literal not found at "+repr((currentindex,data)))
               currentindex = currentindex + len(data)
            else:
@@ -182,19 +181,19 @@
               if indicator == wild_card:
                  # if it is the last directive then it matches the rest of the string
                  if parse_index == lparse_seq:
-                    last = len(str)
+                    last = len(s)
                  # otherwise must look at next directive to find end of wildcard
                  else:
                     # next directive must be re or literal
                     (nextindicator, nextdata) = parse_seq[parse_index+1]
                     if nextindicator is None:
                        # search for literal
-                       last = find(str, nextdata, currentindex)
+                       last = s.find(nextdata, currentindex)
                        if last<currentindex:
                           raise ValueError("couldn't terminate wild with lit "+repr(currentindex))
                     else:
                        # data is a re, search for it
-                       last = nextdata.search(str, currentindex)
+                       last = nextdata.search(s, currentindex)
                        if last<currentindex:
                           raise ValueError("couldn't terminate wild with re "+repr(currentindex))
               elif indicator == single_char:
@@ -202,11 +201,11 @@
                  last = currentindex + data
               else:
                  # other directives are always regular expressions
-                 last = data.match(str, currentindex) + currentindex
+                 last = data.match(s, currentindex) + currentindex
                  if last<currentindex:
                     raise ValueError("couldn't match re at "+repr(currentindex))
-              #print "accepting", str[currentindex:last]
-              result[current_directive_index] = str[currentindex:last]
+              #print("accepting", s[currentindex:last])
+              result[current_directive_index] = s[currentindex:last]
               current_directive_index = current_directive_index+1
               currentindex = last
        # sanity check
@@ -216,7 +215,7 @@
 
 # some useful regular expressions
 USERNAMEREGEX = \
-  "["+string.letters+"]["+string.letters+string.digits+"_]*"
+  "["+ascii_letters+"]["+ascii_letters+string.digits+"_]*"
 STRINGLITREGEX = "'[^\n']*'"
 SIMPLEINTREGEX = "["+string.digits+"]+"
 id = re.compile(USERNAMEREGEX)