Preserve mapping types in decode_from_utf8/encode_to_utf8
@@ -113,7 +113,7 @@ def encode_to_utf8(data):
if isinstance(data, bytes):
return data
elif isinstance(data, collections.Mapping):
- return dict(map(encode_to_utf8, data.iteritems()))
+ return type(data)(map(encode_to_utf8, data.iteritems()))
elif isinstance(data, collections.Iterable):
return type(data)(map(encode_to_utf8, data))
else:
@@ -126,7 +126,7 @@ def decode_from_utf8(data):
if isinstance(data, unicode):
return data
elif isinstance(data, collections.Mapping):
- return dict(map(decode_from_utf8, data.iteritems()))
+ return type(data)(map(decode_from_utf8, data.iteritems()))
elif isinstance(data, collections.Iterable):
return type(data)(map(decode_from_utf8, data))
else:
