Skip to content
This repository
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 25 lines (22 sloc) 0.803 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
import datetime
import json

class EasygoingDictionary(dict):
"""A dictionary that returns None if you try to access a non-existent key.
"""
def __getitem__(self, key):
if not key in self:
return None
return super(EasygoingDictionary, self).__getitem__(key)


class DateTimeEncoder(json.JSONEncoder):
"""A custom JSONEncoder that converts datetime objects into their ISO
representation. If the specified object is not of type datetime, python's
default JSONEncoder is used."""
def default(self, obj):
if isinstance(obj, datetime.datetime):
return obj.isoformat()
elif isinstance(obj, datetime.date):
return obj.isoformat()
elif isinstance(obj, datetime.timedelta):
return (datetime.datetime.min + obj).time().isoformat()
else:
return json.JSONEncoder.default(self, obj)
Something went wrong with that request. Please try again.