mirror of
https://github.com/xcat2/confluent.git
synced 2025-01-08 12:36:03 +00:00
Convert datetime objects to ISO8601 on the way out
If a plugin iterates a datetime object, decode to ISO-8601 string on the way out. This allows plugins to work directly with datetime objects and allow the messaging layer to normalize it to ISO-8601
This commit is contained in:
parent
26da687dc3
commit
bb0e256a98
@ -16,6 +16,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
import confluent.tlv as tlv
|
||||
from datetime import datetime
|
||||
import json
|
||||
import struct
|
||||
|
||||
@ -34,6 +35,8 @@ def unicode_dictvalues(dictdata):
|
||||
for key in dictdata:
|
||||
if isinstance(dictdata[key], str):
|
||||
dictdata[key] = decodestr(dictdata[key])
|
||||
elif isinstance(dictdata[key], datetime):
|
||||
dictdata[key] = dictdata[key].strftime('%Y-%m-%dT%H:%M:%S')
|
||||
elif isinstance(dictdata[key], list):
|
||||
for i in xrange(len(dictdata[key])):
|
||||
if isinstance(dictdata[key][i], str):
|
||||
|
@ -19,6 +19,7 @@
|
||||
# Things are defined here to 'encourage' developers to coordinate information
|
||||
# format. This is also how different data formats are supported
|
||||
import confluent.exceptions as exc
|
||||
from datetime import datetime
|
||||
import json
|
||||
|
||||
valid_health_values = set([
|
||||
@ -36,6 +37,8 @@ def _htmlify_structure(indict):
|
||||
ret += "<li>{0}: ".format(key)
|
||||
if type(indict[key]) in (str, unicode, float, int):
|
||||
ret += str(indict[key])
|
||||
elif isinstance(indict[key], datetime):
|
||||
ret += indict[key].strftime('%Y-%m-%dT%H:%M:%S')
|
||||
else:
|
||||
ret += _htmlify_structure(indict[key])
|
||||
elif isinstance(indict, list):
|
||||
|
Loading…
Reference in New Issue
Block a user