def _dthandler(obj):
 if isinstance(obj, datetime.datetime):
  return obj.isoformat()
 elif hasattr(obj, 'to_json'):
  return obj.to_json()
 else:
  return None

def _dthandler ( obj ) : if isinstance ( obj , datetime . datetime ) : return obj . isoformat ( ) elif hasattr ( obj , 'to_json' ) : return obj . to_json ( ) else : return None
handler for object types that are not json-serializable .