How to use the pingparsing.cli.TimestampFormat.DATETIME function in pingparsing

To help you get started, we’ve selected a few pingparsing examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thombashi / pingparsing / pingparsing / cli.py View on Github external
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)