Skip to content

Commit

Permalink
Fix encoding bugs in Python2 (non-ASCII characters) (tableau#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelSR authored and Russell Hay committed Sep 19, 2016
1 parent 5f91af0 commit b80333d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tableaudocumentapi/datasource.py
Expand Up @@ -31,7 +31,7 @@
def _get_metadata_xml_for_field(root_xml, field_name):
if "'" in field_name:
field_name = sax.escape(field_name, {"'": "'"})
xpath = ".//metadata-record[@class='column'][local-name='{}']".format(field_name)
xpath = u".//metadata-record[@class='column'][local-name='{}']".format(field_name)
return root_xml.find(xpath)


Expand Down
7 changes: 6 additions & 1 deletion tableaudocumentapi/field.py
Expand Up @@ -199,4 +199,9 @@ def _read_description(xmldata):
if description is None:
return None

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

return description_string

0 comments on commit b80333d

Please sign in to comment.