Skip to content
Snippets Groups Projects
Commit cedc76f2 authored by joe's avatar joe
Browse files

Added a custom json decoder to allow the reference implementation

of the client to decode datetime values
parent 80b035eb
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ import logging ...@@ -6,6 +6,7 @@ import logging
import re import re
import os import os
import sys import sys
import datetime
from configdb import exceptions from configdb import exceptions
from configdb.db import schema from configdb.db import schema
from configdb.client import connection from configdb.client import connection
...@@ -29,11 +30,21 @@ def read_from_file(value): ...@@ -29,11 +30,21 @@ def read_from_file(value):
with open(value, 'r') as fd: with open(value, 'r') as fd:
return fd.read() return fd.read()
class CfdbEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime.datetime):
return obj.isoformat()
# Let the base class default method raise the TypeError
return json.JSONEncoder.default(self, obj)
class JsonPlain(object): class JsonPlain(object):
@staticmethod @staticmethod
def pprint(value): def pprint(value):
"""Pretty-print value as JSON.""" """Pretty-print value as JSON."""
print json.dumps(value, sort_keys=True, indent=4)
print json.dumps(value, sort_keys=True, indent=4, cls=CfdbEncoder)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment