Skip to content

Commit 8e700cc

Browse files
committed
this should fix PY2/Py3 issue for loads #103
1 parent fe56d8d commit 8e700cc

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

canmatrix/formats.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
logger = logging.getLogger('root')
66
import canmatrix
77
import os
8+
if sys.version_info > (3, 0):
9+
import io
10+
else:
11+
import StringIO
812

913
moduleList = ["arxml", "cmcsv", "dbc", "dbf", "cmjson",
1014
"kcd", "fibex", "sym", "xls", "xlsx", "yaml"]
@@ -37,8 +41,13 @@
3741
extensionMapping[loadedModule] = loadedModule
3842

3943

40-
def loads(string, importType=None, key="", flatImport=None, **options):
41-
fileObject = StringIO.StringIO[string]
44+
def loads(string, importType=None, key="", flatImport=None, encoding="utf-8",**options):
45+
if sys.version_info > (3, 0):
46+
if type(string) == str:
47+
string = bytes(string, encoding)
48+
fileObject = io.BytesIO(string)
49+
else:
50+
fileObject = StringIO.StringIO(string)
4251
return load(fileObject, importType, key, flatImport, **options)
4352

4453

0 commit comments

Comments
 (0)