--- 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
--- a/reportlab/test/test_multibyte_jpn.py Thu May 04 23:07:51 2006 +0000
+++ b/reportlab/test/test_multibyte_jpn.py Thu May 04 23:45:29 2006 +0000
@@ -340,7 +340,7 @@
from reportlab.platypus import Paragraph
from reportlab.lib.styles import ParagraphStyle
jsty = ParagraphStyle('japanese',fontName='HeiseiMin-W3', wordWrap='CJK')
- jpara = Paragraph(sample2_utf8, style=jsty)
+ jpara = Paragraph(oneline_uni, style=jsty)
c.drawString(100, 710, 'Try to wrap a paragraph using a style with wordWrap="CJK"')
w, h = jpara.wrap(400,400)
--- a/reportlab/test/test_platypus_tables.py Thu May 04 23:07:51 2006 +0000
+++ b/reportlab/test/test_platypus_tables.py Thu May 04 23:45:29 2006 +0000
@@ -277,11 +277,11 @@
""", styleSheet['BodyText']))
- t = Table([['Corporate Assets','Amount'],
+ t = Table([[u'Corporate Assets','Amount'],
['Fixed Assets','1,234,567.89'],
['Company Vehicle','1,234.8901'],
['Petty Cash','42'],
- ['Intellectual Property','(42,078,231.56)'],
+ [u'Intellectual Property\u00ae','(42,078,231.56)'],
['Overdraft','(12,345)'],
['Boardroom Flat Screen','60 inches'],
['Net Position','Deep Sh*t.Really']