Commit 88f37ddd authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: do not return unicode strings

parent 2649e9d0
......@@ -34,11 +34,25 @@ from App.Common import rfc1123_date
from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE
import json
import six
ACCESS = "#access"
ERROR = "#error"
BUILDING = "#building"
# http://stackoverflow.com/a/13105359
def byteify(string):
if isinstance(string, dict):
return {byteify(key): byteify(value) for key, value in six.iteritems(string)}
elif isinstance(string, list):
return [byteify(element) for element in string]
elif isinstance(string, tuple):
return tuple(byteify(element) for element in string)
elif six.PY2 and isinstance(string, six.text_type):
return string.encode('utf-8')
else:
return string
class SlapOSCacheMixin:
# Declarative security
......@@ -87,7 +101,7 @@ class SlapOSCacheMixin:
#data_dict["user"] = data_dict["user"].decode("UTF-8")
return data_dict
data_dict = json.loads(data_json)
data_dict = byteify(json.loads(data_json))
last_contact = DateTime(data_dict.get('created_at'))
data_dict["no_data_since_15_minutes"] = 0
data_dict["no_data_since_5_minutes"] = 0
......
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