Commit edecf67c authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: do not return unicode strings

parent c21424a1
...@@ -34,11 +34,25 @@ from App.Common import rfc1123_date ...@@ -34,11 +34,25 @@ from App.Common import rfc1123_date
from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE from Products.ERP5Type.Cache import DEFAULT_CACHE_SCOPE
import json import json
import six
ACCESS = "#access" ACCESS = "#access"
ERROR = "#error" ERROR = "#error"
BUILDING = "#building" 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: class SlapOSCacheMixin:
# Declarative security # Declarative security
...@@ -87,7 +101,7 @@ class SlapOSCacheMixin: ...@@ -87,7 +101,7 @@ class SlapOSCacheMixin:
#data_dict["user"] = data_dict["user"].decode("UTF-8") #data_dict["user"] = data_dict["user"].decode("UTF-8")
return data_dict return data_dict
data_dict = json.loads(data_json) data_dict = byteify(json.loads(data_json))
last_contact = DateTime(data_dict.get('created_at')) last_contact = DateTime(data_dict.get('created_at'))
data_dict["no_data_since_15_minutes"] = 0 data_dict["no_data_since_15_minutes"] = 0
data_dict["no_data_since_5_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