Commit 313f5843 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

Merge branch 'master' into 'master'

Ensure that every string key and value of the json response from the network cache server is a str object

Please, @kazuhiko and @kirr, review this.

See merge request !1
parents 88c67f9b 68898f82
...@@ -49,6 +49,17 @@ class short_exc_info(tuple): ...@@ -49,6 +49,17 @@ class short_exc_info(tuple):
l = ['%s:%s\n' % (filename, lineno)] l = ['%s:%s\n' % (filename, lineno)]
l += traceback.format_exception_only(t, v) l += traceback.format_exception_only(t, v)
return ''.join(l).rstrip() return ''.join(l).rstrip()
def byteify(input):
'''Transform every unicode string inside a list or dict into normal strings. '''
if isinstance(input, dict):
return dict([(byteify(key), byteify(value)) for key, value in input.iteritems()])
elif isinstance(input, list):
return [byteify(element) for element in input]
elif isinstance(input, unicode):
return input.encode('utf-8')
else:
return input
class NetworkcacheClient(object): class NetworkcacheClient(object):
...@@ -263,7 +274,7 @@ class NetworkcacheClient(object): ...@@ -263,7 +274,7 @@ class NetworkcacheClient(object):
data_list = self.select_generic(key, self.signature_certificate_list) data_list = self.select_generic(key, self.signature_certificate_list)
for information_json, signature in data_list: for information_json, signature in data_list:
try: try:
information_dict = json.loads(information_json) information_dict = byteify(json.loads(information_json))
except Exception: except Exception:
logger.info('Failed to parse json-in-json response (%r)', logger.info('Failed to parse json-in-json response (%r)',
information_json) information_json)
......
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