reportlab: obsoletisms removed
authorrgbecker
Wed, 13 Feb 2008 10:58:03 +0000
changeset 2915 f2c1f8ef3b51
parent 2914 32e5bcc9b776
child 2916 c894eda9c168
reportlab: obsoletisms removed
reportlab/pdfbase/pdfdoc.py
reportlab/pdfgen/canvas.py
reportlab/pdfgen/textobject.py
reportlab/platypus/frames.py
reportlab/platypus/tables.py
reportlab/tools/py2pdf/py2pdf.py
--- a/reportlab/pdfbase/pdfdoc.py	Tue Jan 29 17:04:09 2008 +0000
+++ b/reportlab/pdfbase/pdfdoc.py	Wed Feb 13 10:58:03 2008 +0000
@@ -264,12 +264,12 @@
                 # does pdfmetrics know about it? if so, add
                 fontObj = pdfmetrics.getFont(psfontname)
                 if fontObj._dynamicFont:
-                    raise PDFError, "getInternalFontName(%s) called for a dynamic font" % repr(psfontname)
+                    raise PDFError("getInternalFontName(%s) called for a dynamic font" % repr(psfontname))
                 fontObj.addObjects(self)
                 #self.addFont(fontObj)
                 return fm[psfontname]
             except KeyError:
-                raise PDFError, "Font %s not known!" % repr(psfontname)
+                raise PDFError("Font %s not known!" % repr(psfontname))
 
     def thisPageName(self):
         return "Page"+repr(self.pageCounter)
@@ -553,15 +553,18 @@
         if type(s) is str:
             if enc is 'auto':
                 try:
-                    u = s.decode(s.startswith(codecs.BOM_UTF16_BE) and 'utf16' or 'utf8')
+                    s.decode('pdfdoc')
                 except:
-                    import sys
-                    print >>sys.stderr, 'Error in',repr(s)
-                    raise
-                if _checkPdfdoc(u):
-                    s = u.encode('pdfdoc')
-                else:
-                    s = codecs.BOM_UTF16_BE+u.encode('utf_16_be')
+                    try:
+                        u = s.decode(s.startswith(codecs.BOM_UTF16_BE) and 'utf16' or 'utf8')
+                    except:
+                        import sys
+                        print >>sys.stderr, 'Error in',repr(s)
+                        raise
+                    if _checkPdfdoc(u):
+                        s = u.encode('pdfdoc')
+                    else:
+                        s = codecs.BOM_UTF16_BE+u.encode('utf_16_be')
         elif type(s) is unicode:
             if enc is 'auto':
                 if _checkPdfdoc(s):
--- a/reportlab/pdfgen/canvas.py	Tue Jan 29 17:04:09 2008 +0000
+++ b/reportlab/pdfgen/canvas.py	Wed Feb 13 10:58:03 2008 +0000
@@ -1446,17 +1446,17 @@
         if direction in [0,90,180,270]:
             direction_arg = ('Di', '/%d' % direction)
         else:
-            raise 'PDFError', ' directions allowed are 0,90,180,270'
+            raise PDFError(' directions allowed are 0,90,180,270')
 
         if dimension in ['H', 'V']:
             dimension_arg = ('Dm', '/' + dimension)
         else:
-            raise'PDFError','dimension values allowed are H and V'
+            raisePDFError('dimension values allowed are H and V')
 
         if motion in ['I','O']:
             motion_arg = ('M', '/' + motion)
         else:
-            raise'PDFError','motion values allowed are I and O'
+            raisePDFError('motion values allowed are I and O')
 
         # this says which effects require which argument types from above
         PageTransitionEffects = {
@@ -1471,7 +1471,7 @@
         try:
             args = PageTransitionEffects[effectname]
         except KeyError:
-            raise 'PDFError', 'Unknown Effect Name "%s"' % effectname
+            raise PDFError('Unknown Effect Name "%s"' % effectname)
 
         # now build the dictionary
         transDict = {}
--- a/reportlab/pdfgen/textobject.py	Tue Jan 29 17:04:09 2008 +0000
+++ b/reportlab/pdfgen/textobject.py	Wed Feb 13 10:58:03 2008 +0000
@@ -67,11 +67,11 @@
             elif l==4:
                 self.setFillColorCMYK(aColor[0], aColor[1], aColor[2], aColor[3])
             else:
-                raise 'Unknown color', str(aColor)
+                raise ValueError('Unknown color %r' % aColor)
         elif type(aColor) is StringType:
             self.setFillColor(toColor(aColor))
         else:
-            raise 'Unknown color', str(aColor)
+            raise ValueError('Unknown color %r' % aColor)
 
     def setStrokeColor(self, aColor):
         """Takes a color object, allowing colors to be referred to by name"""
@@ -92,11 +92,11 @@
             elif l==4:
                 self.setStrokeColorCMYK(aColor[0], aColor[1], aColor[2], aColor[3])
             else:
-                raise 'Unknown color', str(aColor)
+                raise ValueError('Unknown color %r' % aColor)
         elif type(aColor) is StringType:
             self.setStrokeColor(toColor(aColor))
         else:
-            raise 'Unknown color', str(aColor)
+            raise ValueError('Unknown color %r' % aColor)
 
     def setFillGray(self, gray):
         """Sets the gray level; 0.0=black, 1.0=white"""
--- a/reportlab/platypus/frames.py	Tue Jan 29 17:04:09 2008 +0000
+++ b/reportlab/platypus/frames.py	Wed Feb 13 10:58:03 2008 +0000
@@ -82,7 +82,7 @@
 
     def __getattr__(self,a):
         if a in _geomAttr: return self.__dict__['_'+a]
-        raise AttributeError, a
+        raise AttributeError(a)
 
     def __setattr__(self,a,v):
         if a in _geomAttr:
@@ -148,8 +148,9 @@
 
         if y < p-_FUZZ:
             if not rl_config.allowTableBoundsErrors and ((h>self._aH or w>aW) and not trySplit):
-                raise "LayoutError", "Flowable %s (%sx%s points) too large for frame (%sx%s points)." % (
-                    flowable.__class__, w,h, aW,self._aH)
+                from reportlab.platypus.doctemplate import LayoutError
+                raise LayoutError("Flowable %s (%sx%s points) too large for frame (%sx%s points)." % (
+                    flowable.__class__, w,h, aW,self._aH))
             return 0
         else:
             #now we can draw it, and update the current point.
--- a/reportlab/platypus/tables.py	Tue Jan 29 17:04:09 2008 +0000
+++ b/reportlab/platypus/tables.py	Wed Feb 13 10:58:03 2008 +0000
@@ -226,7 +226,7 @@
         self.hAlign = hAlign or 'CENTER'
         self.vAlign = vAlign or 'MIDDLE'
         if type(data) not in _SeqTypes:
-            raise ValueError, "%s invalid data type" % self.identity()
+            raise ValueError("%s invalid data type" % self.identity())
         self._nrows = nrows = len(data)
         self._cellvalues = []
         _seqCW = type(colWidths) in _SeqTypes
@@ -237,7 +237,7 @@
         if not emptyTableAction: emptyTableAction = rl_config.emptyTableAction
         if not (nrows and ncols):
             if emptyTableAction=='error':
-                raise ValueError, "%s must have at least a row and column" % self.identity()
+                raise ValueError("%s must have at least a row and column" % self.identity())
             elif emptyTableAction=='indicate':
                 self.__class__ = Preformatted
                 global _emptyTableStyle
@@ -250,20 +250,20 @@
                 self.__class__ = Spacer
                 Spacer.__init__(self,0,0)
             else:
-                raise ValueError, '%s bad emptyTableAction: "%s"' % (self.identity(),emptyTableAction)
+                raise ValueError('%s bad emptyTableAction: "%s"' % (self.identity(),emptyTableAction))
             return
 
         # we need a cleanup pass to ensure data is strings - non-unicode and non-null
         self._cellvalues = self.normalizeData(data)
         if not _seqCW: colWidths = ncols*[colWidths]
         elif len(colWidths) != ncols:
-            raise ValueError, "%s data error - %d columns in data but %d in column widths" % (self.identity(),ncols, len(colWidths))
+            raise ValueError("%s data error - %d columns in data but %d in column widths" % (self.identity(),ncols, len(colWidths)))
         if not _seqRH: rowHeights = nrows*[rowHeights]
         elif len(rowHeights) != nrows:
-            raise ValueError, "%s data error - %d rows in data but %d in row heights" % (self.identity(),nrows, len(rowHeights))
+            raise ValueError("%s data error - %d rows in data but %d in row heights" % (self.identity(),nrows, len(rowHeights)))
         for i in xrange(nrows):
             if len(data[i]) != ncols:
-                raise ValueError, "%s not enough data columns in row %d!" % (self.identity(),i)
+                raise ValueError("%s not enough data columns in row %d!" % (self.identity(),i))
         self._rowHeights = self._argH = rowHeights
         self._colWidths = self._argW = colWidths
         cellrows = []
@@ -414,7 +414,7 @@
                     else:#work out size
                         t = self._elementWidth(v,s)
                         if t is None:
-                            raise ValueError, "Flowable %s in cell(%d,%d) can't have auto width\n%s" % (v.identity(30),i,j,self.identity(30))
+                            raise ValueError("Flowable %s in cell(%d,%d) can't have auto width\n%s" % (v.identity(30),i,j,self.identity(30)))
                         t += s.leftPadding+s.rightPadding
                         if span:
                             c0 = span[0]
@@ -512,7 +512,7 @@
                         if isinstance(v,(tuple,list,Flowable)):
                             if isinstance(v,Flowable): v = (v,)
                             if w is None and not self._canGetWidth(v):
-                                raise ValueError, "Flowable %s in cell(%d,%d) can't have auto width in\n%s" % (v[0].identity(30),i,j,self.identity(30))
+                                raise ValueError("Flowable %s in cell(%d,%d) can't have auto width in\n%s" % (v[0].identity(30),i,j,self.identity(30)))
                             if canv: canv._fontname, canv._fontsize, canv._leading = s.fontname, s.fontsize, s.leading or 1.2*s.fontsize
                             if ji in colSpanCells:
                                 if not span: continue
@@ -521,7 +521,8 @@
                             if canv: canv._fontname, canv._fontsize, canv._leading = saved
                             dW = dW + s.leftPadding + s.rightPadding
                             if not rl_config.allowTableBoundsErrors and dW>w:
-                                raise "LayoutError", "Flowable %s (%sx%s points) too wide for cell(%d,%d) (%sx* points) in\n%s" % (v[0].identity(30),fp_str(dW),fp_str(t),i,j, fp_str(w), self.identity(30))
+                                from reportlab.platypus.doctemplate import LayoutError
+                                raise LayoutError("Flowable %s (%sx%s points) too wide for cell(%d,%d) (%sx* points) in\n%s" % (v[0].identity(30),fp_str(dW),fp_str(t),i,j, fp_str(w), self.identity(30)))
                         else:
                             v = (v is not None and str(v) or '').split("\n")
                             t = (s.leading or 1.2*s.fontSize)*len(v)
@@ -1371,7 +1372,7 @@
                 elif just in ('CENTRE', 'CENTER'):
                     x = colpos+(colwidth+cellstyle.leftPadding-cellstyle.rightPadding-w)/2.0
                 else:
-                    raise ValueError, 'Invalid justification %s' % just
+                    raise ValueError('Invalid justification %s' % just)
                 y -= v.getSpaceBefore()
                 y -= h
                 v.drawOn(self.canv,x,y)
@@ -1390,7 +1391,7 @@
                 draw = self.canv.drawAlignedString
                 x = colpos + colwidth - cellstyle.rightPadding
             else:
-                raise ValueError, 'Invalid justification %s' % just
+                raise ValueError('Invalid justification %s' % just)
             vals = string.split(str(cellval), "\n")
             n = len(vals)
             leading = cellstyle.leading
@@ -1403,7 +1404,7 @@
                 #tim roberts pointed out missing fontsize correction 2004-10-04
                 y = rowpos + (cellstyle.bottomPadding + rowheight-cellstyle.topPadding+n*leading)/2.0 - fontsize
             else:
-                raise ValueError, "Bad valign: '%s'" % str(valign)
+                raise ValueError("Bad valign: '%s'" % str(valign))
 
             for v in vals:
                 draw(x, y, v)
--- a/reportlab/tools/py2pdf/py2pdf.py	Tue Jan 29 17:04:09 2008 +0000
+++ b/reportlab/tools/py2pdf/py2pdf.py	Wed Feb 13 10:58:03 2008 +0000
@@ -117,7 +117,7 @@
         return eval(aString)
     else:
         details = '%s cannot be parsed into a numeric tuple!' % aString
-        raise 'ValueError', details
+        raise ValueError(details)
 
 
 def loadFontifier(options=None):
@@ -1487,7 +1487,7 @@
     if find(cmdStr, 'paperSize') >= 0 and find(cmdStr, 'paperFormat') >= 0:
         details = "You can specify either paperSize or paperFormat, "
         details = detail + "but not both!"
-        raise 'ValueError', details
+        raise ValueError(details)
 
     # Create PDF converter and pass options to it.
     if options.input:
@@ -1499,7 +1499,7 @@
             P = PDFPrinter
         else:
             details = "Input file type must be 'python' or 'ascii'."
-            raise 'ValueError', details
+            raise ValueError(details)
 
     else:
         P = PythonPDFPrinter
@@ -1564,4 +1564,4 @@
 ###
 
 if __name__=='__main__': #NORUNTESTS
-    main(sys.argv)
\ No newline at end of file
+    main(sys.argv)