reportlab/platypus/tables.py
changeset 2589 1af821ded9f1
parent 2582 4a008286f3dc
child 2590 deaa612ecb4c
--- a/reportlab/platypus/tables.py	Thu May 04 23:07:51 2006 +0000
+++ b/reportlab/platypus/tables.py	Thu May 04 23:45:29 2006 +0000
@@ -238,7 +238,8 @@
                 raise ValueError, '%s bad emptyTableAction: "%s"' % (self.identity(),emptyTableAction)
             return
 
-        self._cellvalues = data
+        # 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 grid" % (self.identity(),ncols, len(colWidths))
@@ -277,6 +278,29 @@
         cv = string.replace(cv, "\n", "\n  ")
         return "%s(\n rowHeights=%s,\n colWidths=%s,\n%s\n) # end table" % (self.__class__.__name__,r,c,cv)
 
+    def normalizeData(self, data):
+        """Takes a block of input data (list of lists etc.) and
+        - coerces to non-unicode UTF8
+        - accepts nulls
+        
+        """
+        def normCell(stuff):
+            if stuff is None:
+                return ''
+            elif type(stuff) == type(u''):
+                return stuff.encode('utf8')
+            else:
+                return stuff
+        outData = []
+        for row in data:
+            outRow = [normCell(cell) for cell in row]
+            outData.append(outRow)
+        from pprint import pprint as pp
+        #pp(outData)
+        return outData
+
+
+
     def identity(self, maxLen=30):
         '''Identify our selves as well as possible'''
         if self.ident: return self.ident