Skip to content

Commit ee380ac

Browse files
MiguelSRRussell Hay
authored and
Russell Hay
committed
Fix encoding bugs in Python2 (non-ASCII characters) (#80)
1 parent 9974238 commit ee380ac

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

tableaudocumentapi/datasource.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
def _get_metadata_xml_for_field(root_xml, field_name):
3232
if "'" in field_name:
3333
field_name = sax.escape(field_name, {"'": "'"})
34-
xpath = ".//metadata-record[@class='column'][local-name='{}']".format(field_name)
34+
xpath = u".//metadata-record[@class='column'][local-name='{}']".format(field_name)
3535
return root_xml.find(xpath)
3636

3737

tableaudocumentapi/field.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,9 @@ def _read_description(xmldata):
199199
if description is None:
200200
return None
201201

202-
return u'{}'.format(ET.tostring(description, encoding='utf-8')) # This is necessary for py3 support
202+
description_string = ET.tostring(description, encoding='utf-8')
203+
# Format expects a unicode string so in Python 2 we have to do the explicit conversion
204+
if isinstance(description_string, bytes):
205+
description_string = description_string.decode('utf-8')
206+
207+
return description_string

0 commit comments

Comments
 (0)