Commit 31a16689 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Fix some Python 2 incompatibilities

parent db22b670
...@@ -127,6 +127,13 @@ import csv ...@@ -127,6 +127,13 @@ import csv
if sys.version_info < (3,): if sys.version_info < (3,):
import StringIO import StringIO
def _to_str(x):
if isinstance(x, unicode):
return x.encode("utf8")
return x
def _to_str(x):
return x
from .decorators import _wraps, _require, _attrs, _limit_args, _copy_func from .decorators import _wraps, _require, _attrs, _limit_args, _copy_func
from inspect import ismethod from inspect import ismethod
...@@ -201,7 +208,7 @@ def _type_alias(type_name): ...@@ -201,7 +208,7 @@ def _type_alias(type_name):
if type_name in alias: if type_name in alias:
return alias[type_name] return alias[type_name]
if type_name in value_types(): if type_name in value_types():
return type_name return _to_str(type_name)
ma = re.compile(r"vector<(.*)>").match(type_name) ma = re.compile(r"vector<(.*)>").match(type_name)
if ma: if ma:
t = t =
...@@ -1308,7 +1315,7 @@ class InternalPropertyDict(dict): ...@@ -1308,7 +1315,7 @@ class InternalPropertyDict(dict):
self.__set_property(t, k, val) self.__set_property(t, k, val)
@_limit_args({"t": ["v", "e", "g"]}) @_limit_args({"t": ["v", "e", "g"]})
@_require("key", str) @_require("key", str, unicode)
def __set_property(self, t, key, v): def __set_property(self, t, key, v):
dict.__setitem__(self, (t, key), v) dict.__setitem__(self, (t, key), v)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment