def _default_json_handler(self, obj):
"""Format given abject into json formatted string"""
if isinstance(obj, datetime.datetime):
if obj.year < 1900:
# strftime do not work with date < 1900
return constants.CLOUDSEARCH_DATETIME_CREATION_FORMAT % (
obj.year, obj.month, obj.day, obj.hour, obj.minute,
obj.second)
return obj.strftime(self.datefmt)
elif isinstance(obj, datetime.date):
return obj.isoformat()
elif isinstance(obj, datetime.time):
return obj.strftime(constants.CLOUDSEARCH_TIME_FORMAT)
elif istraceback(obj):
_traceback = ''.join(traceback.format_tb(obj))
return _traceback.strip()
elif isinstance(obj, Exception):
return "Exception: %s" % str(obj)
return str(obj)
评论列表
文章目录