summaryrefslogtreecommitdiff
path: root/tablib
diff options
context:
space:
mode:
authorJim Dalton <jim@ere.net>2012-05-10 11:14:17 -0700
committerJim Dalton <jim@ere.net>2012-05-10 11:14:17 -0700
commit21c11b9911a0141602444265a34219c16c152067 (patch)
tree8cd012ae1947a558b006b3db436791de9413627f /tablib
parente8c923d7121da21cb96eedd68710c37f5c9b471f (diff)
downloadtablib-21c11b9911a0141602444265a34219c16c152067.tar.gz
Fix UnicodeError in HTML output
* Alter `test_unicode_append` so that actual unicode characters outside the ASCII bytestring range are tested. * Make sure output of `render` in markup.py is unicode * Add wrapper around output of `export_set` in _html.py so that unicode characters are output.
Diffstat (limited to 'tablib')
-rw-r--r--tablib/formats/_html.py5
-rw-r--r--tablib/packages/markup.py12
2 files changed, 10 insertions, 7 deletions
diff --git a/tablib/formats/_html.py b/tablib/formats/_html.py
index ffde95f..222c589 100644
--- a/tablib/formats/_html.py
+++ b/tablib/formats/_html.py
@@ -11,6 +11,7 @@ if sys.version_info[0] > 2:
from tablib.packages import markup3 as markup
else:
from cStringIO import StringIO
+ import codecs
from tablib.packages import markup
import tablib
@@ -45,7 +46,9 @@ def export_set(dataset):
page.table.close()
- stream.writelines(str(page))
+ # Allow unicode characters in output
+ wrapper = codecs.getwriter("utf8")(stream)
+ wrapper.writelines(unicode(page))
return stream.getvalue()
diff --git a/tablib/packages/markup.py b/tablib/packages/markup.py
index 234f116..0198899 100644
--- a/tablib/packages/markup.py
+++ b/tablib/packages/markup.py
@@ -67,7 +67,7 @@ class element:
def render( self, tag, single, between, kwargs ):
"""Append the actual tags to content."""
- out = "<%s" % tag
+ out = u"<%s" % tag
for key, value in kwargs.iteritems( ):
if value is not None: # when value is None that means stuff like <... checked>
key = key.strip('_') # strip this so class_ will mean class, etc.
@@ -75,16 +75,16 @@ class element:
key = 'http-equiv'
elif key == 'accept_charset':
key = 'accept-charset'
- out = "%s %s=\"%s\"" % ( out, key, escape( value ) )
+ out = u"%s %s=\"%s\"" % ( out, key, escape( value ) )
else:
- out = "%s %s" % ( out, key )
+ out = u"%s %s" % ( out, key )
if between is not None:
- out = "%s>%s</%s>" % ( out, between, tag )
+ out = u"%s>%s</%s>" % ( out, between, tag )
else:
if single:
- out = "%s />" % out
+ out = u"%s />" % out
else:
- out = "%s>" % out
+ out = u"%s>" % out
if self.parent is not None:
self.parent.content.append( out )
else: