04e8283e92
Added supoort for streams api w/ winchester. Added json deserialization support for datetime & timerange types Fixed api typo ('distinquished' vs 'distinguished') Change-Id: Ibae617b5bc58fd9c6f41ae30e90d5d2cbc9fc3fa
32 lines
825 B
Python
32 lines
825 B
Python
import datetime
|
|
import timex
|
|
import iso8601
|
|
|
|
|
|
def decode_datetime(dct, name):
|
|
return iso8601.parse_date(dct['datetime'], default_timezone=None)
|
|
|
|
|
|
def decode_timerange(dct, name):
|
|
begin = iso8601.parse_date(dct['begin'], default_timezone=None)
|
|
end = iso8601.parse_date(dct['end'], default_timezone=None)
|
|
return timex.TimeRange(begin=begin, end=end)
|
|
|
|
|
|
def decode_timestamp(dct, name):
|
|
timestamp = iso8601.parse_date(dct['timestamp'], default_timezone=None)
|
|
return timex.Timestamp(timestamp)
|
|
|
|
|
|
DECODE_MAP = {'datetime': decode_datetime,
|
|
'timex.TimeRange': decode_timerange,
|
|
'timex.Timestamp': decode_timestamp}
|
|
|
|
|
|
def object_hook(dct):
|
|
if '__type__' in dct:
|
|
name = dct['__type__']
|
|
decoder = DECODE_MAP[name]
|
|
return decoder(dct, name)
|
|
return dct
|