string module usage minimization py33
authorrobin
Tue, 19 Nov 2013 13:50:34 +0000
branchpy33
changeset 3794 398ea04239b5
parent 3793 cc3f9cc828f7
child 3795 2a6c4b74219f
string module usage minimization
demos/rlzope/rlzope.py
docs/userguide/ch6_tables.py
docs/userguide/graph_charts.py
src/reportlab/graphics/barcode/code93.py
src/reportlab/graphics/samples/runall.py
src/reportlab/graphics/widgetbase.py
src/reportlab/lib/attrmap.py
src/reportlab/lib/codecharts.py
src/reportlab/lib/set_ops.py
src/reportlab/lib/testutils.py
src/reportlab/lib/yaml.py
src/reportlab/pdfbase/_cidfontdata.py
src/reportlab/pdfbase/pdfdoc.py
src/reportlab/pdfbase/pdfpattern.py
tests/test_charts_textlabels.py
tests/test_docstrings.py
tests/test_graphics_charts.py
tests/test_pdfbase_ttfonts.py
tests/test_pdfgen_general.py
tests/test_pdfgen_pycanvas.py
tests/test_platypus_general.py
tests/test_platypus_preformatted.py
tests/test_pyfiles.py
tests/test_source_chars.py
tools/docco/docpy.py
tools/docco/graphdocpy.py
tools/pythonpoint/demos/examples.py
tools/pythonpoint/pythonpoint.py
--- a/demos/rlzope/rlzope.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/demos/rlzope/rlzope.py	Tue Nov 19 13:50:34 2013 +0000
@@ -12,7 +12,7 @@
 #
 #
 
-import string, io
+import io
 try :
     from Shared.reportlab.platypus.paragraph import Paragraph
     from Shared.reportlab.platypus.doctemplate import *
@@ -123,10 +123,10 @@
 
     def escapexml(self, s) :
         """Escape some xml entities."""
-        s = string.strip(s)
-        s = string.replace(s, "&", "&")
-        s = string.replace(s, "<", "&lt;")
-        return string.replace(s, ">", "&gt;")
+        s = s.strip()
+        s = s.replace("&", "&amp;")
+        s = s.replace("<", "&lt;")
+        return s.replace(">", "&gt;")
 
 def rlzope(self) :
     """A sample external method to show people how to use ReportLab from within Zope."""
--- a/docs/userguide/ch6_tables.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/docs/userguide/ch6_tables.py	Tue Nov 19 13:50:34 2013 +0000
@@ -424,7 +424,7 @@
         self.caseSensitive = caseSensitive
         if maximumLineLength and text:
             text = self.stopLine(text, maximumLineLength, splitCharacters)
-        cleaner = lambda text, dedent=dedent: string.join(_dedenter(text or '',dedent),'')
+        cleaner = lambda text, dedent=dedent: ''.join(_dedenter(text or '',dedent))
         self._setup(text, style, bulletText, frags, cleaner)
 '''
 t=Preformatted(text,normalStyle,maxLineLength=60, newLineChars='> ')
--- a/docs/userguide/graph_charts.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/docs/userguide/graph_charts.py	Tue Nov 19 13:50:34 2013 +0000
@@ -900,7 +900,7 @@
 lc.width = 300
 lc.data = data
 lc.joinedLines = 1
-catNames = string.split('Jan Feb Mar Apr May Jun Jul Aug', ' ')
+catNames = 'Jan Feb Mar Apr May Jun Jul Aug'.split(' ')
 lc.categoryAxis.categoryNames = catNames
 lc.categoryAxis.labels.boxAnchor = 'n'
 lc.valueAxis.valueMin = 0
@@ -927,7 +927,7 @@
 lc.width = 300
 lc.data = data
 lc.joinedLines = 1
-catNames = string.split('Jan Feb Mar Apr May Jun Jul Aug', ' ')
+catNames = 'Jan Feb Mar Apr May Jun Jul Aug'.split(' ')
 lc.categoryAxis.categoryNames = catNames
 lc.categoryAxis.labels.boxAnchor = 'n'
 lc.valueAxis.valueMin = 0
--- a/src/reportlab/graphics/barcode/code93.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/src/reportlab/graphics/barcode/code93.py	Tue Nov 19 13:50:34 2013 +0000
@@ -32,7 +32,6 @@
 
 from reportlab.lib.units import inch
 from .common import MultiWidthBarcode
-import string
 
 _patterns = {
   '0' : ('AcAaAb', 0),  '1' : ('AaAbAc', 1),  '2' : ('AaAcAb', 2),
@@ -108,7 +107,7 @@
 
     s.reverse()
 
-    return string.join(s, '')
+    return ''.join(s)
 
 class _Code93Base(MultiWidthBarcode):
     barWidth = inch * 0.0075
@@ -184,9 +183,7 @@
     def validate(self):
         vval = ""
         self.valid = 1
-        for c in self.value:
-            if c in string.lowercase:
-                c = string.upper(c)
+        for c in self.value.upper():
             if c not in _patterns:
                 self.valid = 0
                 continue
--- a/src/reportlab/graphics/samples/runall.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/src/reportlab/graphics/samples/runall.py	Tue Nov 19 13:50:34 2013 +0000
@@ -2,7 +2,6 @@
 # makes a PDF sample for eaxh existing chart type
 import sys
 import glob
-import string
 import inspect
 import types
 
@@ -18,13 +17,13 @@
     return moduleClasses(__import__(f))
 
 def run(format, VERBOSE=0):
-    formats = string.split(format, ',')
+    formats = format.split( ',')
     for i in range(0, len(formats)):
-        formats[i] == string.lower(string.strip(formats[i]))
+        formats[i] == formats[i].strip().lower()
     allfiles = glob.glob('*.py')
     allfiles.sort()
     for fn in allfiles:
-        f = string.split(fn, '.')[0]
+        f = fn.split('.')[0]
         c = getclass(f)
         if c != None:
             print(c.__name__)
--- a/src/reportlab/graphics/widgetbase.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/src/reportlab/graphics/widgetbase.py	Tue Nov 19 13:50:34 2013 +0000
@@ -4,8 +4,6 @@
 __version__=''' $Id$ '''
 __doc__='''Base class for user-defined graphical widgets'''
 
-import string
-
 from reportlab.graphics import shapes
 from reportlab import rl_config
 from reportlab.lib import colors
@@ -99,7 +97,7 @@
 
         childPropDicts = {}
         for name, value in propDict.items():
-            parts = string.split(name, '.', 1)
+            parts = name.split('.', 1)
             if len(parts) == 1:
                 #simple attribute, set it now
                 setattr(self, name, value)
--- a/src/reportlab/lib/attrmap.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/src/reportlab/lib/attrmap.py	Tue Nov 19 13:50:34 2013 +0000
@@ -131,7 +131,7 @@
 def _findObjectAndAttr(src, P):
     '''Locate the object src.P for P a string, return parent and name of attribute
     '''
-    P = string.split(P, '.')
+    P = P.split('.')
     if len(P) == 0:
         return None, None
     else:
--- a/src/reportlab/lib/codecharts.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/src/reportlab/lib/codecharts.py	Tue Nov 19 13:50:34 2013 +0000
@@ -9,7 +9,6 @@
 and fonts, we need some routines to display all those characters.
 These are defined herein.  The idea is to include flowable, drawable
 and graphic objects for single and multi-byte fonts. """
-import string
 import codecs
 
 from reportlab.pdfgen.canvas import Canvas
@@ -207,12 +206,12 @@
     def makeRow(self, row):
         """Works out the character values for this kuten row"""
         cells = []
-        if string.find(self.encodingName, 'EUC') > -1:
+        if self.encodingName.find('EUC') > -1:
             # it is an EUC family encoding.
             for col in range(1, 95):
                 ch = chr(row + 160) + chr(col+160)
                 cells.append(ch)
-##        elif string.find(self.encodingName, 'GB') > -1:
+##        elif self.encodingName.find('GB') > -1:
 ##            # it is an EUC family encoding.
 ##            for col in range(1, 95):
 ##                ch = chr(row + 160) + chr(col+160)
@@ -224,7 +223,7 @@
         self.drawLabels(topLeft= 'R%d' % self.row)
 
         # work out which characters we need for the row
-        #assert string.find(self.encodingName, 'EUC') > -1, 'Only handles EUC encoding today, you gave me %s!' % self.encodingName
+        #assert self.encodingName.find('EUC') > -1, 'Only handles EUC encoding today, you gave me %s!' % self.encodingName
 
         # pad out by 1 to match Ken Lunde's tables
         charList = [None] + self.makeRow(self.row)
@@ -262,7 +261,7 @@
         """Works out the character values for this Big5 row.
         Rows start at 0xA1"""
         cells = []
-        if string.find(self.encodingName, 'B5') > -1:
+        if self.encodingName.find('B5') > -1:
             # big 5, different row size
             for y in [4,5,6,7,10,11,12,13,14,15]:
                 for x in range(16):
--- a/src/reportlab/lib/set_ops.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/src/reportlab/lib/set_ops.py	Tue Nov 19 13:50:34 2013 +0000
@@ -6,7 +6,6 @@
 __doc__="""From before Python had a Set class..."""
 
 import types
-import string
 
 def __set_coerce(t, S):
     if t is list:
@@ -14,7 +13,7 @@
     elif t is tuple:
         return tuple(S)
     elif t is bytes:
-        return string.join(S, '')
+        return ''.join(S)
     return S
 
 def unique(seq):
--- a/src/reportlab/lib/testutils.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/src/reportlab/lib/testutils.py	Tue Nov 19 13:50:34 2013 +0000
@@ -9,7 +9,7 @@
 nothing more than "reportlab.whatever..."
 """
 
-import sys, os, string, fnmatch, copy, re
+import sys, os, fnmatch, copy, re
 from configparser import ConfigParser
 import unittest
 
@@ -106,7 +106,6 @@
     """
 
     join = os.path.join
-    split = string.split
 
     # If CVS subfolder doesn't exist return empty list.
     try:
@@ -119,7 +118,7 @@
     for line in f.readlines():
         if folders and line[0] == 'D' \
            or files and line[0] != 'D':
-            entry = split(line, '/')[1]
+            entry = line.split('/')[1]
             if entry:
                 allEntries.append(join(folder, entry))
 
@@ -139,7 +138,7 @@
 
         # This seems to allow for newlines inside values
         # of the config file, but be careful!!
-        val = string.replace(value, '\n', '')
+        val = value.replace('\n', '')
 
         if self.pat.match(val):
             return eval(val)
--- a/src/reportlab/lib/yaml.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/src/reportlab/lib/yaml.py	Tue Nov 19 13:50:34 2013 +0000
@@ -39,9 +39,7 @@
 """
 __version__=''' $Id$ '''
 
-
 import sys
-import string
 
 #modes:
 PLAIN = 1
@@ -78,7 +76,7 @@
 
     def parseText(self, textBlock):
         "Parses the a possible multi-line text block"
-        lines = string.split(textBlock, '\n')
+        lines = textBlock.split('\n')
         for line in lines:
             self.readLine(line)
         self.endPara()
@@ -87,7 +85,7 @@
     def readLine(self, line):
         #this is the inner loop
         self._lineNo = self._lineNo + 1
-        stripped = string.lstrip(line)
+        stripped = line.lstrip()
         if len(stripped) == 0:
             if self._mode == PLAIN:
                 self.endPara()
@@ -96,7 +94,7 @@
         elif line[0]=='.':
             # we have a command of some kind
             self.endPara()
-            words = string.split(stripped[1:])
+            words = stripped[1:].split()
             cmd, args = words[0], words[1:]
 
             #is it a parser method?
@@ -112,7 +110,7 @@
                 # assume it is a paragraph style -
                 # becomes the formatter's problem
                 self.endPara()  #end the last one
-                words = string.split(stripped, ' ', 1)
+                words = stripped.split(' ', 1)
                 assert len(words)==2, "Style %s but no data at line %d" % (words[0], self._lineNo)
                 (styletag, data) = words
                 self._style = styletag[1:]
@@ -124,12 +122,12 @@
     def endPara(self):
         #ends the current paragraph, or preformatted block
 
-        text = string.join(self._buf, ' ')
+        text = ' '.join(self._buf)
         if text:
             if self._mode == PREFORMATTED:
                 #item 3 is list of lines
                 self._results.append(('PREFORMATTED', self._style,
-                                 string.join(self._buf,'\n')))
+                                 '\n'.join(self._buf)))
             else:
                 self._results.append(('PARAGRAPH', self._style, text))
         self._buf = []
--- a/src/reportlab/pdfbase/_cidfontdata.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/src/reportlab/pdfbase/_cidfontdata.py	Tue Nov 19 13:50:34 2013 +0000
@@ -473,12 +473,11 @@
 message2 = '\202\261\202\352\202\315\225\275\220\254\212p\203S\203V\203b\203N\202\305\202\267\201B'
 
 ##def pswidths(text):
-##    import string
-##    words = string.split(text)
+##    words = text.split()
 ##    out = []
 ##    for word in words:
 ##        if word == '[':
 ##            out.append(word)
 ##        else:
 ##            out.append(word + ',')
-##    return eval(string.join(out, ''))
+##    return eval(''.join(out))
--- a/src/reportlab/pdfbase/pdfdoc.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/src/reportlab/pdfbase/pdfdoc.py	Tue Nov 19 13:50:34 2013 +0000
@@ -14,7 +14,7 @@
 and are not part of any public interface.  Instead, canvas and font
 classes are made available elsewhere for users to manipulate.
 """
-import string, types, binascii, codecs
+import types, binascii, codecs
 from reportlab.pdfbase import pdfutils
 from reportlab.pdfbase.pdfutils import LINEEND # this constant needed in both
 from reportlab import rl_config
@@ -843,7 +843,7 @@
     if content is None:
         content = teststreamcontent
     content = content.strip()
-    content = string.replace(content, "\n", LINEEND) + LINEEND
+    content = content.replace("\n", LINEEND) + LINEEND
     S = PDFStream(content = content,
                     filters=rl_config.useA85 and [PDFBase85Encode,PDFZCompress] or [PDFZCompress])
     # nothing else needed...
@@ -2010,34 +2010,30 @@
 
 class PDFTrueTypeFont(PDFType1Font):
     Subtype = "TrueType"
-    #local_attributes = string.split("FirstChar LastChar Widths Encoding ToUnicode FontDescriptor") #same
+    #local_attributes = "FirstChar LastChar Widths Encoding ToUnicode FontDescriptor".split() #same
 
 ##class PDFMMType1Font(PDFType1Font):
 ##    Subtype = "MMType1"
 ##
 ##class PDFType3Font(PDFType1Font):
 ##    Subtype = "Type3"
-##    local_attributes = string.split(
-##        "FirstChar LastChar Widths CharProcs FontBBox FontMatrix Resources Encoding")
+##    local_attributes = "FirstChar LastChar Widths CharProcs FontBBox FontMatrix Resources Encoding".split()
 ##
 ##class PDFType0Font(PDFType1Font):
 ##    Subtype = "Type0"
-##    local_attributes = string.split(
-##        "DescendantFonts Encoding")
+##    local_attributes = "DescendantFonts Encoding".split(
 ##
 ##class PDFCIDFontType0(PDFType1Font):
 ##    Subtype = "CIDFontType0"
-##    local_attributes = string.split(
-##        "CIDSystemInfo FontDescriptor DW W DW2 W2 Registry Ordering Supplement")
+##    local_attributes = "CIDSystemInfo FontDescriptor DW W DW2 W2 Registry Ordering Supplement".split()
 ##
 ##class PDFCIDFontType0(PDFType1Font):
 ##    Subtype = "CIDFontType2"
-##    local_attributes = string.split(
-##        "BaseFont CIDToGIDMap CIDSystemInfo FontDescriptor DW W DW2 W2")
+##    local_attributes = "BaseFont CIDToGIDMap CIDSystemInfo FontDescriptor DW W DW2 W2".split()
 ##
 ##class PDFEncoding(PDFType1Font):
 ##    Type = "Encoding"
-##    name_attributes = string.split("Type BaseEncoding")
+##    name_attributes = "Type BaseEncoding".split()
 ##    # these attributes are assumed to already be of the right type
 ##    local_attributes = ["Differences"]
 ##
@@ -2206,7 +2202,7 @@
     def loadImageFromRaw(self,source):
         IMG=[]
         imagedata = pdfutils.makeRawImage(source,IMG=IMG)
-        words = string.split(imagedata[1])
+        words = imagedata[1].split()
         self.width = int(words[1])
         self.height = int(words[3])
         self.colorSpace = {'/RGB':'DeviceRGB', '/G':'DeviceGray', '/CMYK':'DeviceCMYK'}[words[7]]
--- a/src/reportlab/pdfbase/pdfpattern.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/src/reportlab/pdfbase/pdfpattern.py	Tue Nov 19 13:50:34 2013 +0000
@@ -1,9 +1,6 @@
 __doc__="""helper for importing pdf structures into a ReportLab generated document
 """
 from reportlab.pdfbase.pdfdoc import format
-
-import string
-
 class PDFPattern:
     __PDFObject__ = True
     __RefOnly__ = 1
@@ -54,6 +51,6 @@
                     L.append(format(value, document))
                 else:
                     L.append( str(value) )
-        return string.join(L, "")
+        return "".join(L)
 
 
--- a/tests/test_charts_textlabels.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/tests/test_charts_textlabels.py	Tue Nov 19 13:50:34 2013 +0000
@@ -86,7 +86,7 @@
         drawings = []
 
         for boxAnchors in ('sw se nw ne', 'w e n s', 'c'):
-            boxAnchors = string.split(boxAnchors, ' ')
+            boxAnchors = boxAnchors.split(' ')
 
             # Create drawing.
             d = Drawing(w, h)
--- a/tests/test_docstrings.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/tests/test_docstrings.py	Tue Nov 19 13:50:34 2013 +0000
@@ -11,18 +11,12 @@
 """
 from reportlab.lib.testutils import setOutDir,SecureTestCase, GlobDirectoryWalker, outputfile, printLocation
 setOutDir(__name__)
-import os, sys, glob, string, re, unittest
+import os, sys, glob, re, unittest
 from types import ModuleType, ClassType, MethodType, FunctionType
 import reportlab
 
 def getModuleObjects(folder, rootName, typ, pattern='*.py'):
     "Get a list of all objects defined *somewhere* in a package."
-
-    # Define some abbreviations.
-    find = string.find
-    split = string.split
-    replace = string.replace
-
     objects = []
     lookup = {}
     for file in GlobDirectoryWalker(folder, pattern):
@@ -40,8 +34,8 @@
         os.chdir(folder)
 
         modName = os.path.splitext(os.path.basename(file))[0]
-        prefix = folder[find(folder, rootName):]
-        prefix = replace(prefix, os.sep, '.')
+        prefix = folder[folder.find(rootName):]
+        prefix = prefix.replace(os.sep,'.')
         mName = prefix + '.' + modName
 
         try:
@@ -54,8 +48,8 @@
 
         # Get the 'real' (leaf) module
         # (__import__ loads only the top-level one).
-        if find(mName, '.') != -1:
-            for part in split(mName, '.')[1:]:
+        if mName.find('.') != -1:
+            for part in mName.split('.')[1:]:
                 module = getattr(module, part)
 
             # Find the objects in the module's content.
@@ -63,7 +57,7 @@
 
             # Handle modules.
             if typ == ModuleType:
-                if find(module.__name__, 'reportlab') > -1:
+                if module.__name__.find('reportlab') > -1:
                     objects.append((mName, module))
                     continue
 
@@ -73,7 +67,7 @@
                 if typ in (FunctionType, ClassType):
                     if type(obj) == typ and obj not in lookup:
                         if typ == ClassType:
-                            if find(obj.__module__, rootName) != 0:
+                            if obj.__module__.find(rootName) != 0:
                                 continue
                         objects.append((mName, obj))
                         lookup[obj] = 1
@@ -83,7 +77,7 @@
                         for m in dir(obj):
                             a = getattr(obj, m)
                             if type(a) == typ and a not in lookup:
-                                if find(a.__self__.__class__.__module__, rootName) != 0:
+                                if a.__self__.__class__.__module__.find(rootName) != 0:
                                     continue
                                 cName = obj.__name__
                                 objects.append((mName, a))
--- a/tests/test_graphics_charts.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/tests/test_graphics_charts.py	Tue Nov 19 13:50:34 2013 +0000
@@ -79,7 +79,7 @@
     bc.categoryAxis.labels.dy = -2
     bc.categoryAxis.labels.angle = 30
 
-    catNames = string.split('Jan Feb Mar Apr May Jun Jul Aug', ' ')
+    catNames = 'Jan Feb Mar Apr May Jun Jul Aug'.split( ' ')
     catNames = [n+'-99' for n in catNames]
     bc.categoryAxis.categoryNames = catNames
     drawing.add(bc)
@@ -113,7 +113,7 @@
     bc.categoryAxis.labels.dy = -2
     bc.categoryAxis.labels.angle = 30
 
-    catNames = string.split('Jan Feb Mar Apr May Jun Jul Aug', ' ')
+    catNames = 'Jan Feb Mar Apr May Jun Jul Aug'.split(' ')
     catNames = [n+'-99' for n in catNames]
     bc.categoryAxis.categoryNames = catNames
     drawing.add(bc)
--- a/tests/test_pdfbase_ttfonts.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/tests/test_pdfbase_ttfonts.py	Tue Nov 19 13:50:34 2013 +0000
@@ -6,7 +6,6 @@
 """
 from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation, NearTestCase
 setOutDir(__name__)
-import string
 from io import StringIO
 import unittest
 from reportlab.pdfgen.canvas import Canvas
@@ -252,16 +251,16 @@
         "Tests TTFont.splitString"
         doc = PDFDocument()
         font = TTFont("Vera", "Vera.ttf")
-        text = string.join(list(map(utf8, range(0, 511))), "")
-        allchars = string.join(list(map(chr, range(0, 256))), "")
+        text = "".join(list(map(utf8, range(0, 511))))
+        allchars = "".join(list(map(chr, range(0, 256))))
         nospace = allchars[:32] + allchars[33:]
         chunks = [(0, allchars), (1, nospace)]
         self.assertEquals(font.splitString(text, doc), chunks)
         # Do it twice
         self.assertEquals(font.splitString(text, doc), chunks)
 
-        text = string.join(list(map(utf8, list(range(510, -1, -1)))), "")
-        allchars = string.join(list(map(chr, list(range(255, -1, -1)))), "")
+        text = "".join(list(map(utf8, list(range(510, -1, -1)))))
+        allchars = "".join(list(map(chr, list(range(255, -1, -1)))))
         nospace = allchars[:223] + allchars[224:]
         chunks = [(1, nospace), (0, allchars)]
         self.assertEquals(font.splitString(text, doc), chunks)
@@ -273,7 +272,7 @@
 
         doc = PDFDocument()
         font = TTFont("Vera", "Vera.ttf")
-        text = string.join(list(map(utf8, list(range(512, -1, -1)))), "")
+        text = "".join(list(map(utf8, list(range(512, -1, -1)))))
         chunks = font.splitString(text, doc)
         state = font.state[doc]
         self.assertEquals(state.assignments[32], 32)
@@ -285,7 +284,7 @@
         doc = PDFDocument()
         font = TTFont("Vera", "Vera.ttf")
         # Actually generate some subsets
-        text = string.join(list(map(utf8, list(range(0, 513)))), "")
+        text = "".join(list(map(utf8, list(range(0, 513)))))
         font.splitString(text, doc)
         self.assertRaises(IndexError, font.getSubsetInternalName, -1, doc)
         self.assertRaises(IndexError, font.getSubsetInternalName, 3, doc)
--- a/tests/test_pdfgen_general.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/tests/test_pdfgen_general.py	Tue Nov 19 13:50:34 2013 +0000
@@ -6,7 +6,7 @@
 #tests and documents new low-level canvas
 from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
 setOutDir(__name__)
-import os, string
+import os
 import unittest
 from reportlab.pdfgen import canvas   # gmcm 2000/10/13, pdfgen now a package
 from reportlab.lib.units import inch, cm
@@ -106,9 +106,9 @@
 
     def _getHeight(self):
         "splits into lines"
-        self.comment1lines = string.split(self.comment1, '\n')
-        self.codelines = string.split(self.code, '\n')
-        self.comment2lines = string.split(self.comment2, '\n')
+        self.comment1lines = self.comment1.split('\n')
+        self.codelines = self.code.split('\n')
+        self.comment2lines = self.comment2.split('\n')
         textheight = (len(self.comment1lines) +
                 len(self.code) +
                 len(self.comment2lines) +
--- a/tests/test_pdfgen_pycanvas.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/tests/test_pdfgen_pycanvas.py	Tue Nov 19 13:50:34 2013 +0000
@@ -6,7 +6,7 @@
 #tests and documents new low-level canvas and the pycanvas module to output Python source code.
 from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
 setOutDir(__name__)
-import string, os, unittest
+import os, unittest
 from reportlab.pdfgen import pycanvas   # gmcm 2000/10/13, pdfgen now a package
 from reportlab.lib.units import inch, cm
 from reportlab.lib import colors
@@ -109,9 +109,9 @@
 
     def _getHeight(self):
         "splits into lines"
-        self.comment1lines = string.split(self.comment1, '\n')
-        self.codelines = string.split(self.code, '\n')
-        self.comment2lines = string.split(self.comment2, '\n')
+        self.comment1lines = self.comment1.split('\n')
+        self.codelines = self.code.split('\n')
+        self.comment2lines = self.comment2.split('\n')
         textheight = (len(self.comment1lines) +
                 len(self.code) +
                 len(self.comment2lines) +
--- a/tests/test_platypus_general.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/tests/test_platypus_general.py	Tue Nov 19 13:50:34 2013 +0000
@@ -13,7 +13,7 @@
 """
 from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
 setOutDir(__name__)
-import string, copy, sys, os
+import copy, sys, os
 from reportlab.pdfgen import canvas
 from reportlab import platypus
 from reportlab.platypus import BaseDocTemplate, PageTemplate, Flowable, FrameBreak
@@ -71,20 +71,20 @@
     """Within the script, it is useful to whack out a page in triple
     quotes containing separate paragraphs. This breaks one into its
     constituent paragraphs, using blank lines as the delimiter."""
-    lines = string.split(textBlock, '\n')
+    lines = textBlock.split('\n')
     paras = []
     currentPara = []
     for line in lines:
-        if len(string.strip(line)) == 0:
+        if len(line.strip()) == 0:
             #blank, add it
             if currentPara != []:
-                paras.append(string.join(currentPara, '\n'))
+                paras.append('\n'.join(currentPara))
                 currentPara = []
         else:
             currentPara.append(line)
     #...and the last one
     if currentPara != []:
-        paras.append(string.join(currentPara, '\n'))
+        paras.append('\n'.join(currentPara))
 
     return paras
 
--- a/tests/test_platypus_preformatted.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/tests/test_platypus_preformatted.py	Tue Nov 19 13:50:34 2013 +0000
@@ -6,7 +6,6 @@
 from reportlab.lib.testutils import setOutDir,makeSuiteForClasses, outputfile, printLocation
 setOutDir(__name__)
 import sys, os, random
-from string import split, strip, join, whitespace
 from operator import truth
 from types import StringType, ListType
 import unittest
@@ -101,7 +100,6 @@
 __version__=''' $Id: xpreformatted.py 3866 2011-06-27 13:08:20Z rgbecker $ '''
 __doc__='''A 'rich preformatted text' widget allowing internal markup'''
 
-import string
 from types import StringType, ListType
 from reportlab.lib import PyFontify
 from paragraph import Paragraph, cleanBlockQuotedText, _handleBulletWidth, ParaLines, _getFragWords, stringWidth, _sameFrag, getAscentDescent, imgVRange, imgNormV
@@ -110,7 +108,7 @@
 class XPreformatted(Paragraph):
     def __init__(self, text, style, bulletText = None, frags=None, caseSensitive=1, dedent=0):
         self.caseSensitive = caseSensitive
-        cleaner = lambda text, dedent=dedent: string.join(_dedenter(text or '',dedent),'\\n')
+        cleaner = lambda text, dedent=dedent: ,'\\n'.join(_dedenter(text or '',dedent))
         self._setup(text, style, bulletText, frags, cleaner)
 
     def breakLines(self, width):
@@ -138,12 +136,12 @@
                 fontName = f.fontName
                 ascent, descent = getAscentDescent(fontName,fontSize)
                 kind = 0
-                L=string.split(f.text, '\\n')
+                L=f.text.split('\\n')
                 for l in L:
                     currentWidth = stringWidth(l,fontName,fontSize)
                     requiredWidth = max(currentWidth,requiredWidth)
                     extraSpace = maxWidth-currentWidth
-                    lines.append((extraSpace,string.split(l,' '),currentWidth))
+                    lines.append((extraSpace,l.split(' '),currentWidth))
                     lineno = lineno+1
                     maxWidth = lineno&lt;len(maxWidths) and maxWidths[lineno] or maxWidths[-1]
                 blPara = f.clone(kind=kind, lines=lines,ascent=ascent,descent=descent,fontSize=fontSize)
--- a/tests/test_pyfiles.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/tests/test_pyfiles.py	Tue Nov 19 13:50:34 2013 +0000
@@ -74,7 +74,7 @@
             nonAscii = [c for c in fileContent if ord(c)>127]
             nonAscii = unique(nonAscii)
 
-            truncPath = path[string.find(path, 'reportlab'):]
+            truncPath = path[path.find('reportlab'):]
             args = (truncPath, repr(list(map(ord, nonAscii))))
             msg = "File %s contains characters: %s." % args
 ##            if nonAscii:
@@ -93,11 +93,11 @@
 
         for path in allPyFiles:
             #hack - exclude barcode extensions from this test
-            if string.find(path, 'barcode'):
+            if path.find('barcode'):
                 pass
             else:
                 basename = os.path.splitext(path)[0]
-                truncPath = path[string.find(path, 'reportlab'):]
+                truncPath = path[path.find('reportlab'):]
                 msg = "Filename %s contains trailing digits." % truncPath
                 assert basename[-1] not in string.digits, msg
 
--- a/tests/test_source_chars.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/tests/test_source_chars.py	Tue Nov 19 13:50:34 2013 +0000
@@ -7,7 +7,7 @@
 setOutDir(__name__)
 from reportlab.lib.testutils import RL_HOME,testsFolder
 __version__=''' $Id$ '''
-import os, sys, glob, string, re
+import os, sys, glob, re
 from types import ModuleType, ClassType, MethodType, FunctionType
 import reportlab
 import unittest
@@ -26,7 +26,7 @@
 
     def checkFileForTabs(self, filename):
         txt = open_and_read(filename, 'r')
-        chunks = string.split(txt, '\t')
+        chunks = txt.split('\t')
         tabCount = len(chunks) - 1
         if tabCount:
             #raise Exception, "File %s contains %d tab characters!" % (filename, tabCount)
@@ -37,8 +37,8 @@
         initSize = len(txt)
         badLines = 0
         badChars = 0
-        for line in string.split(txt, '\n'):
-            stripped = string.rstrip(line)
+        for line in txt.split('\n'):
+            stripped = line.rstrip()
             spaces = len(line) - len(stripped)  # OK, so they might be trailing tabs, who cares?
             if spaces:
                 badLines = badLines + 1
@@ -68,15 +68,15 @@
         txt = open(filename, 'r').read()
         badChars = 0
         cleaned = []
-        for line in string.split(txt, '\n'):
-            stripped = string.rstrip(line)
+        for line in txt.split('\n'):
+            stripped = line.rstrip()
             cleaned.append(stripped)
             spaces = len(line) - len(stripped)  # OK, so they might be trailing tabs, who cares?
             if spaces:
                 badChars = badChars + spaces
 
         if badChars != 0:
-            open(filename, 'w').write(string.join(cleaned, '\n'))
+            open(filename, 'w').write('\n'.join(cleaned))
             print("file %s contained %d trailing spaces, FIXED" % (filename, badChars))
     print('done')
 
--- a/tools/docco/docpy.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/tools/docco/docpy.py	Tue Nov 19 13:50:34 2013 +0000
@@ -33,9 +33,7 @@
 __version__ = '0.8'
 
 
-import sys, os, re, types, string, getopt, copy, time
-from string import find, join, split, replace, expandtabs, rstrip
-
+import sys, os, re, types, getopt, copy, time
 from reportlab.pdfgen import canvas
 from reportlab.lib import colors
 from reportlab.lib.units import inch, cm
@@ -74,7 +72,7 @@
         canvas.setFont('Times-Roman', 12)
         canvas.drawString(4 * inch, cm, "%d" % pageNumber)
         if hasattr(canvas, 'headerLine'): # hackish
-            headerline = string.join(canvas.headerLine, ' \215 ') # bullet
+            headerline = , ' \215 '.join(canvas.headerLine) # bullet
             canvas.drawString(2*cm, A4[1]-1.75*cm, headerline)
 
     canvas.setFont('Times-Roman', 8)
@@ -154,9 +152,7 @@
 
 def htmlescape(text):
     "Escape special HTML characters, namely &, <, >."
-    return replace(replace(replace(text, '&', '&amp;'),
-                                         '<', '&lt;'),
-                                         '>', '&gt;')
+    return text.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')
 
 def htmlrepr(object):
     return htmlescape(repr(object))
@@ -173,13 +169,13 @@
             result = inspect.getcomments(object)
         except:
             pass
-    return result and rstrip(result) + '\n' or ''
+    return result and result.rstrip() + '\n' or ''
 
 
 def reduceDocStringLength(docStr):
     "Return first line of a multiline string."
 
-    return split(docStr, '\n')[0]
+    return docStr.split('\n')[0]
 
 
 ####################################################################
@@ -193,7 +189,7 @@
 
     This is usually a header for all classes or functions.
 u    """
-    text = htmlescape(expandtabs(text))
+    text = htmlescape(text.expandtabs())
     result = []
     result.append("""<TABLE WIDTH="100\%" BORDER="0">""")
     result.append("""<TR><TD BGCOLOR="%s" VALIGN="CENTER">""" % bgcolor)
@@ -201,7 +197,7 @@
     result.append("""</TD></TR></TABLE>""")
     result.append('')
 
-    return join(result, '\n')
+    return '\n'.join(result)
 
 
 def makeHtmlSubSection(text, bgcolor='#AAA0FF'):
@@ -209,7 +205,7 @@
 
     This is usually a class or function name.
     """
-    text = htmlescape(expandtabs(text))
+    text = htmlescape(text.expandtabs())
     result = []
     result.append("""<TABLE WIDTH="100\%" BORDER="0">""")
     result.append("""<TR><TD BGCOLOR="%s" VALIGN="CENTER">""" % bgcolor)
@@ -217,7 +213,7 @@
     result.append("""</TD></TR></TABLE>""")
     result.append('')
 
-    return join(result, '\n')
+    return '\n'.join(result)
 
 
 def makeHtmlInlineImage(text):
@@ -613,7 +609,7 @@
 
         if bases:
             bases = [b.__name__ for b in bases] # hack
-            append('%s%s(%s)' % (lev*label, name, join(bases, ', ')))
+            append('%s%s(%s)' % (lev*label, name, ', '.join(bases)))
         else:
             append('%s%s' % (lev*label, name))
         return
@@ -696,7 +692,7 @@
 
         self.outLines.append("""<H1>%s</H1>""" % name)
         self.outLines.append('')
-        for line in split(doc, '\n'):
+        for line in doc.split('\n'):
             self.outLines.append("""<FONT SIZE="-1">%s</FONT>""" % htmlescape(line))
             self.outLines.append('<BR>')
         self.outLines.append('')
@@ -721,10 +717,10 @@
 
         if bases:
             bases = [b.__name__ for b in bases] # hack
-            self.outLines.append(makeHtmlSubSection('%s(%s)' % (name, join(bases, ', '))))
+            self.outLines.append(makeHtmlSubSection('%s(%s)' % (name, ', '.join(bases))))
         else:
             self.outLines.append(makeHtmlSubSection('%s' % name))
-        for line in split(doc, '\n'):
+        for line in doc.split('\n'):
             self.outLines.append("""<FONT SIZE="-1">%s</FONT>""" % htmlescape(line))
             self.outLines.append('<BR>')
 
@@ -750,7 +746,7 @@
         append = self.outLines.append
         append("""<DL><DL><DT><TT><STRONG>%s</STRONG>%s</TT></DT>""" % (name, sig))
         append('')
-        for line in split(doc, '\n'):
+        for line in doc.split('\n'):
             append("""<DD><FONT SIZE="-1">%s</FONT></DD>""" % htmlescape(line))
             append('<BR>')
         append('</DL></DL>')
@@ -876,7 +872,7 @@
         story = self.story
         if bases:
             bases = [b.__name__ for b in bases] # hack
-            story.append(Paragraph('%s(%s)' % (name, join(bases, ', ')), self.makeHeadingStyle(self.indentLevel, 'class')))
+            story.append(Paragraph('%s(%s)' % (name,', '.join(bases)), self.makeHeadingStyle(self.indentLevel, 'class')))
         else:
             story.append(Paragraph(name, self.makeHeadingStyle(self.indentLevel, 'class')))
 
@@ -960,7 +956,7 @@
 
         if bases:
             bases = [b.__name__ for b in bases] # hack
-            self.classCompartment = '%s(%s)' % (name, join(bases, ', '))
+            self.classCompartment = '%s(%s)' % (name, ', '.join(bases))
         else:
             self.classCompartment = name
 
@@ -1182,7 +1178,7 @@
         package = __import__(name)
         # Some special care needed for dotted names.
         if '.' in name:
-            subname = 'package' + name[find(name, '.'):]
+            subname = 'package' + name[name.find('.'):]
             package = eval(subname)
         path = os.path.dirname(package.__file__)
 
--- a/tools/docco/graphdocpy.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/tools/docco/graphdocpy.py	Tue Nov 19 13:50:34 2013 +0000
@@ -10,8 +10,7 @@
 
 import sys
 sys.path.insert(0, '.')
-import os, re, types, string, getopt, pickle, copy, time, pprint, traceback
-from string import find, join, split, replace, expandtabs, rstrip
+import os, re, types, getopt, pickle, copy, time, pprint, traceback
 import reportlab
 from reportlab import rl_config
 
@@ -74,7 +73,7 @@
         canvas.setFont('Times-Roman', 12)
         canvas.drawString(4 * inch, cm, "%d" % pageNumber)
         if hasattr(canvas, 'headerLine'): # hackish
-            headerline = string.join(canvas.headerLine, ' \xc2\x8d ')
+            headerline = ' \xc2\x8d '.join(canvas.headerLine)
             canvas.drawString(2*cm, A4[1]-1.75*cm, headerline)
 
     canvas.setFont('Times-Roman', 8)
@@ -353,11 +352,10 @@
 
 
     def beginFunctions(self, names):
-        srch = string.join(names, ' ')
-        if string.find(string.join(names, ' '), ' sample') > -1:
+        srch = ' '.join(names)
+        if ' '.join(names).find(' sample') > -1:
             PdfDocBuilder0.beginFunctions(self, names)
 
-
     # Skip non-sample functions.
     def beginFunction(self, name, doc, sig):
         "Skip function for 'uninteresting' names."
@@ -473,14 +471,14 @@
             f = getBytesIO()
             pprint.pprint(value, f)
             value = f.getvalue()[:-1]
-            valueLines = string.split(value, '\n')
+            valueLines = value.split('\n')
             for i in range(1, len(valueLines)):
                 valueLines[i] = ' '*(len(key)+3) + valueLines[i]
-            value = string.join(valueLines, '\n')
+            value = '\n'.join(valueLines)
 
             lines.append('%s = %s' % (key, value))
 
-        text = join(lines, '\n')
+        text = '\n'.join(lines)
         self.story.append(Paragraph("<i>Properties of Example Widget</i>", self.bt))
         self.story.append(Paragraph("", self.bt))
         self.story.append(Preformatted(text, self.code))
@@ -549,7 +547,7 @@
 
 
     def beginFunctions(self, names):
-        if string.find(string.join(names, ' '), ' sample') > -1:
+        if ' '.join(names).find(' sample') > -1:
             HtmlDocBuilder0.beginFunctions(self, names)
 
 
@@ -657,13 +655,13 @@
             f = getBytesIO()
             pprint.pprint(value, f)
             value = f.getvalue()[:-1]
-            valueLines = string.split(value, '\n')
+            valueLines = value.split('\n')
             for i in range(1, len(valueLines)):
                 valueLines[i] = ' '*(len(key)+3) + valueLines[i]
-            value = string.join(valueLines, '\n')
+            value = '\n'.join(valueLines)
 
             lines.append('%s = %s' % (key, value))
-        text = join(lines, '\n')
+        text = '\n'.join(lines)
         self.outLines.append('<H3>Properties of Example Widget</H3>')
         self.outLines.append('<PRE>%s</PRE>' % text)
         self.outLines.append('')
@@ -717,7 +715,7 @@
         story = self.story
         if bases:
             bases = [b.__name__ for b in bases] # hack
-            story.append(Paragraph('%s(%s)' % (name, join(bases, ', ')), bt))
+            story.append(Paragraph('%s(%s)' % (name, ', '.join(bases)), bt))
         else:
             story.append(Paragraph(name, bt))
 
@@ -885,7 +883,7 @@
         package = __import__(name)
         # Some special care needed for dotted names.
         if '.' in name:
-            subname = 'package' + name[find(name, '.'):]
+            subname = 'package' + name[namefind('.'):]
             package = eval(subname)
         path = os.path.dirname(package.__file__)
 
--- a/tools/pythonpoint/demos/examples.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/tools/pythonpoint/demos/examples.py	Tue Nov 19 13:50:34 2013 +0000
@@ -1,5 +1,3 @@
-import string
-
 testannotations="""
 def annotations(canvas):
     from reportlab.lib.units import inch
@@ -365,7 +363,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
@@ -786,12 +784,11 @@
 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)
+        b = b.strip()
         exec(b+'\n')
 
 platypussetup = """
@@ -836,6 +833,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/pythonpoint/pythonpoint.py	Tue Nov 19 12:21:04 2013 +0000
+++ b/tools/pythonpoint/pythonpoint.py	Tue Nov 19 13:50:34 2013 +0000
@@ -71,7 +71,7 @@
 - add pyRXP support (TODO)
 """
 __version__='''$Id$'''
-import os, sys, imp, string, pprint, getopt, glob
+import os, sys, imp, pprint, getopt, glob
 
 from reportlab import rl_config
 from reportlab.lib import styles
@@ -666,13 +666,13 @@
 
     def parseData(self):
         """Try to make sense of the table data!"""
-        rawdata = string.strip(string.join(self.rawBlocks, ''))
-        lines = string.split(rawdata, self.rowDelim)
+        rawdata = ''.join(self.rawBlocks).strip()
+        lines = rawdata.split(self.rowDelim)
         #clean up...
-        lines = list(map(string.strip, lines))
+        lines = [line.strip() for line in lines]
         self.data = []
         for line in lines:
-            cells = string.split(line, self.fieldDelim)
+            cells = line.split(self.fieldDelim)
             self.data.append(cells)
 
         #get the width list if not given
@@ -872,10 +872,10 @@
         We want to throw away
         tabs, newlines and so on, and only accept embedded string
         like '\n'"""
-        lines = string.split(self.text, '\n')
+        lines = self.text.split('\n')
         newtext = []
         for line in lines:
-            newtext.append(string.strip(line))
+            newtext.append(line.strip())
         #accept all the '\n' as newlines
 
         self.text = newtext
@@ -899,7 +899,7 @@
 
         if self.color is None:
             return
-        lines = string.split(string.strip(drawText), '\\n')
+        lines = drawText.strip().split('\\n')
         canv.saveState()
 
         canv.setFont(self.font, self.size)
@@ -1043,7 +1043,7 @@
     args = [x for x in args if x and x[0]=='-'] + [x for x in args if not x or x[0]!='-']
     try:
         shortOpts = 'hnvsx'
-        longOpts = string.split('cols= outdir= handout help notes printout verbose silent nofx')
+        longOpts = 'cols= outdir= handout help notes printout verbose silent nofx'.split()
         optList, args = getopt.getopt(args, shortOpts, longOpts)
     except getopt.error as msg:
         options['help'] = 1