py3k tests now pass

This commit is contained in:
Mark Rogers
2011-05-15 08:35:29 -05:00
parent 1e21fee70e
commit cb4c67767a
3 changed files with 21 additions and 12 deletions
+12 -9
View File
@@ -47,7 +47,7 @@ def export_book(databook):
stream = BytesIO()
wb.save(stream)
wb.save(unicode(stream))
return stream.getvalue()
@@ -63,6 +63,11 @@ def dset_sheet(dataset, ws):
row_number = i + 1
odf_row = table.TableRow(stylename=bold)
for j, col in enumerate(row):
try:
col = unicode(col, errors='ignore')
except TypeError:
## col is already unicode
pass
ws.addElement(table.TableColumn())
# bold headers
@@ -70,14 +75,14 @@ def dset_sheet(dataset, ws):
odf_row.setAttribute('stylename', bold)
ws.addElement(odf_row)
cell = table.TableCell()
cell.addElement(text.P(stylename="Bold", text=unicode(col, errors='ignore')))
cell.addElement(text.P(stylename="Bold", text=col))
odf_row.addElement(cell)
# bold separators
elif len(row) < dataset.width:
ws.addElement(odf_row)
cell = table.TableCell()
cell.addElement(text.P(text=unicode(col, errors='ignore')))
cell.addElement(text.P(text=col))
odf_row.addElement(cell)
# wrap the rest
@@ -86,17 +91,15 @@ def dset_sheet(dataset, ws):
if '\n' in col:
ws.addElement(odf_row)
cell = table.TableCell()
cell.addElement(text.P(text=unicode(col, errors='ignore')))
cell.addElement(text.P(text=col))
odf_row.addElement(cell)
else:
ws.addElement(odf_row)
cell = table.TableCell()
cell.addElement(text.P(text=unicode(col, errors='ignore')))
cell.addElement(text.P(text=col))
odf_row.addElement(cell)
except TypeError:
ws.addElement(odf_row)
cell = table.TableCell()
cell.addElement(text.P(text=unicode(col, errors='ignore')))
odf_row.addElement(cell)
cell.addElement(text.P(text=col))
odf_row.addElement(cell)
+1 -1
View File
@@ -158,7 +158,7 @@ def cnv_NCName(attribute, arg, element):
""" NCName is defined in http://www.w3.org/TR/REC-xml-names/#NT-NCName
Essentially an XML name minus ':'
"""
if type(arg) in str:
if isinstance(arg, str):
return make_NCName(arg)
else:
return arg.getAttrNS(STYLENS, 'name')
+8 -2
View File
@@ -38,6 +38,12 @@ def _escape(data, entities={}):
the optional entities parameter. The keys and values must all be
strings; each key will be replaced with its corresponding value.
"""
try:
data = data.decode('utf-8')
except TypeError:
## Make sure our stream is a string
## If it comes through as bytes it fails
pass
data = data.replace("&", "&amp;")
data = data.replace("<", "&lt;")
data = data.replace(">", "&gt;")
@@ -198,7 +204,7 @@ def _append_child(self, node):
childNodes.append(node)
node.__dict__["parentNode"] = self
class Childless:
class Childless(object):
""" Mixin that makes childless-ness easy to implement and avoids
the complexity of the Node methods that deal with children.
"""
@@ -255,7 +261,7 @@ class Text(Childless, Node):
if self.data:
f.write(_escape(str(self.data).encode('utf-8')))
class CDATASection(Childless, Text):
class CDATASection(Text, Childless):
nodeType = Node.CDATA_SECTION_NODE
def toXml(self,level,f):