Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _serialize_datetime(obj):
if isinstance(obj, datetime):
return obj.isoformat()
if isinstance(obj, TIMESTAMP_TYPES):
return obj
raise TypeError("not supported type to convert: {}".format(type(obj)))
timestamp_serialize_map = {
TimestampFormat.NONE: None,
TimestampFormat.EPOCH: _serialize_epoch,
TimestampFormat.DATETIME: _serialize_datetime,
}
def dumps_dict(obj, timestamp_format, indent=0):
serialize_func = timestamp_serialize_map[timestamp_format]
if indent <= 0:
return json.dumps(obj, default=serialize_func)
return json.dumps(obj, indent=indent, default=serialize_func)
def main():
options = parse_option()
initialize_log_handler(options.log_level)