Skip to content

Commit 55edcb6

Browse files
committed
[tools/odmlparser] utf-8 encode on write with py2
1 parent 7614561 commit 55edcb6

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

odml/tools/odmlparser.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import datetime
99
import json
10+
import sys
1011
import yaml
1112

1213
from . import xmlparser
@@ -17,6 +18,11 @@
1718
from .rdf_converter import RDFReader, RDFWriter
1819
from ..validation import Validation
1920

21+
try:
22+
unicode = unicode
23+
except NameError:
24+
unicode = str
25+
2026

2127
class ODMLWriter:
2228
"""
@@ -58,7 +64,7 @@ def to_string(self, odml_document):
5864
string_doc = ''
5965

6066
if self.parser == 'XML':
61-
string_doc = str(xmlparser.XMLWriter(odml_document))
67+
string_doc = unicode(xmlparser.XMLWriter(odml_document))
6268
elif self.parser == "RDF":
6369
# Use turtle as default output format for now.
6470
string_doc = RDFWriter(odml_document).get_rdf_str("turtle")
@@ -74,6 +80,9 @@ def to_string(self, odml_document):
7480
string_doc = json.dumps(odml_output, indent=4,
7581
cls=JSONDateTimeSerializer)
7682

83+
if sys.version_info.major < 3:
84+
string_doc = string_doc.encode("utf-8")
85+
7786
return string_doc
7887

7988

0 commit comments

Comments
 (0)