def _o(self, obj):
""" Translate object to json.
Dict in python is not json, so don't be confused.
When return object from rpc, should always use _o.
"""
if obj == None:
return obj
elif isinstance(obj, Decimal):
return str(obj)
elif isinstance(obj, datetime):
return obj.strftime("%Y-%m-%d %H:%M:%S")
elif isinstance(obj, date):
return obj.strftime("%Y-%m-%d")
elif isinstance(obj, (list, set, tuple)):
return self._ol(obj)
elif isinstance(obj, dict):
return self._od(obj)
elif isinstance(obj, (int, str, bool, float)):
return obj
else:
return self._oo(obj)
评论列表
文章目录