Source code for erecord_cmn.utils.coding
# -*- coding: utf-8 -*-
"""erecord_cmn.utils.coding
Coding methods
"""
import json
[docs]def byteify(input):
"""unicode to utf-8
Convert any decoded JSON object from using unicode strings to
UTF-8-encoded byte strings
"""
if isinstance(input, dict):
return {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
[docs]def get_val(value):
"""JSON object to utf-8 """
return byteify(json.loads(value))