[CalendarServer-changes] [14016] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Fri Sep 26 09:43:27 PDT 2014
Revision: 14016
http://trac.calendarserver.org//changeset/14016
Author: cdaboo at apple.com
Date: 2014-09-26 09:43:27 -0700 (Fri, 26 Sep 2014)
Log Message:
-----------
Add JSON response pretty print option and make that the default for std timezone service.
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/stdconfig.py
CalendarServer/trunk/twistedcaldav/timezonestdservice.py
CalendarServer/trunk/txweb2/http.py
Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py 2014-09-25 20:54:32 UTC (rev 14015)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py 2014-09-26 16:43:27 UTC (rev 14016)
@@ -483,11 +483,12 @@
"TimezoneService" : { # New standard timezone service
"Enabled" : False, # Overall on/off switch
"Mode" : "primary", # Can be "primary" or "secondary"
- "BasePath" : "", # Path to directory containing a zoneinfo - if None use default package path
+ "BasePath" : "", # Path to directory containing a zoneinfo - if None use default package path
# secondary service MUST define its own writable path
- "XMLInfoPath" : "", # Path to db cache info - if None use default package path
+ "XMLInfoPath" : "", # Path to db cache info - if None use default package path
# secondary service MUST define its own writable path if
# not None
+ "PrettyPrintJSON" : True, # User friendly JSON output
"SecondaryService" : {
# Only one of these should be used when a secondary service is used
Modified: CalendarServer/trunk/twistedcaldav/timezonestdservice.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/timezonestdservice.py 2014-09-25 20:54:32 UTC (rev 14015)
+++ CalendarServer/trunk/twistedcaldav/timezonestdservice.py 2014-09-26 16:43:27 UTC (rev 14016)
@@ -225,6 +225,7 @@
"error": "invalid-action",
"description": "Invalid action query parameter",
},
+ pretty=config.TimezoneService.PrettyPrintJSON,
))
action = action[0]
@@ -242,6 +243,7 @@
"error": "invalid-action",
"description": "Unknown action query parameter",
},
+ pretty=config.TimezoneService.PrettyPrintJSON,
))
return action(request)
@@ -290,7 +292,7 @@
},
]
}
- return JSONResponse(responsecode.OK, result)
+ return JSONResponse(responsecode.OK, result, pretty=config.TimezoneService.PrettyPrintJSON)
def doList(self, request):
@@ -306,6 +308,7 @@
"error": "invalid-changedsince",
"description": "Invalid changedsince query parameter",
},
+ pretty=config.TimezoneService.PrettyPrintJSON,
))
if len(changedsince) == 1:
# Validate a date-time stamp
@@ -319,11 +322,16 @@
"error": "invalid-changedsince",
"description": "Invalid changedsince query parameter",
},
+ pretty=config.TimezoneService.PrettyPrintJSON,
))
if not dt.utc():
raise HTTPError(JSONResponse(
responsecode.BAD_REQUEST,
- "Invalid changedsince query parameter value",
+ {
+ "error": "invalid-changedsince",
+ "description": "Invalid changedsince query parameter - not UTC",
+ },
+ pretty=config.TimezoneService.PrettyPrintJSON,
))
timezones = []
@@ -337,7 +345,7 @@
"dtstamp": self.timezones.dtstamp,
"timezones": timezones,
}
- return JSONResponse(responsecode.OK, result)
+ return JSONResponse(responsecode.OK, result, pretty=config.TimezoneService.PrettyPrintJSON)
def doGet(self, request):
@@ -353,6 +361,7 @@
"error": "invalid-tzid",
"description": "Invalid tzid query parameter",
},
+ pretty=config.TimezoneService.PrettyPrintJSON,
))
format = request.args.get("format", ("text/calendar",))
@@ -363,6 +372,7 @@
"error": "invalid-format",
"description": "Invalid format query parameter",
},
+ pretty=config.TimezoneService.PrettyPrintJSON,
))
format = format[0]
@@ -373,7 +383,8 @@
{
"error": "tzid-not-found",
"description": "Tzid could not be found",
- }
+ },
+ pretty=config.TimezoneService.PrettyPrintJSON,
))
tzdata = calendar.getText(format=format if format != "text/plain" else None)
@@ -397,6 +408,7 @@
"error": "invalid-tzid",
"description": "Invalid tzid query parameter",
},
+ pretty=config.TimezoneService.PrettyPrintJSON,
))
try:
@@ -415,7 +427,8 @@
{
"error": "invalid-start",
"description": "Invalid start query parameter",
- }
+ },
+ pretty=config.TimezoneService.PrettyPrintJSON,
))
try:
@@ -437,7 +450,8 @@
{
"error": "invalid-end",
"description": "Invalid end query parameter",
- }
+ },
+ pretty=config.TimezoneService.PrettyPrintJSON,
))
tzid = tzids[0]
@@ -448,7 +462,8 @@
{
"error": "tzid-not-found",
"description": "Tzid could not be found",
- }
+ },
+ pretty=config.TimezoneService.PrettyPrintJSON,
))
# Now do the expansion (but use a cache to avoid re-calculating TZs)
@@ -469,7 +484,7 @@
} for onset, utc_offset_from, utc_offset_to, name in observances
],
}
- return JSONResponse(responsecode.OK, result)
+ return JSONResponse(responsecode.OK, result, pretty=config.TimezoneService.PrettyPrintJSON)
Modified: CalendarServer/trunk/txweb2/http.py
===================================================================
--- CalendarServer/trunk/txweb2/http.py 2014-09-25 20:54:32 UTC (rev 14015)
+++ CalendarServer/trunk/txweb2/http.py 2014-09-26 16:43:27 UTC (rev 14016)
@@ -556,11 +556,15 @@
JSON L{Response} object.
Renders itself as an JSON document.
"""
- def __init__(self, code, jobj):
+ def __init__(self, code, jobj, pretty=False):
"""
@param jobj: a Python object that can be serialized to JSON.
"""
- Response.__init__(self, code, stream=json.dumps(jobj))
+ kwargs = {}
+ if pretty:
+ kwargs["indent"] = 2
+ kwargs["separators"] = (',', ':')
+ Response.__init__(self, code, stream=json.dumps(jobj, **kwargs))
self.headers.setHeader("content-type", http_headers.MimeType("application", "json"))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140926/3acceb58/attachment-0001.html>
More information about the calendarserver-changes
mailing list