<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[14016] CalendarServer/trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/14016">14016</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-09-26 09:43:27 -0700 (Fri, 26 Sep 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add JSON response pretty print option and make that the default for std timezone service.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwistedcaldavstdconfigpy">CalendarServer/trunk/twistedcaldav/stdconfig.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavtimezonestdservicepy">CalendarServer/trunk/twistedcaldav/timezonestdservice.py</a></li>
<li><a href="#CalendarServertrunktxweb2httppy">CalendarServer/trunk/txweb2/http.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktwistedcaldavstdconfigpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py (14015 => 14016)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -483,11 +483,12 @@
</span><span class="cx">     &quot;TimezoneService&quot;         : {    # New standard timezone service
</span><span class="cx">         &quot;Enabled&quot;       : False, # Overall on/off switch
</span><span class="cx">         &quot;Mode&quot;          : &quot;primary&quot;, # Can be &quot;primary&quot; or &quot;secondary&quot;
</span><del>-        &quot;BasePath&quot;      : &quot;&quot;, # Path to directory containing a zoneinfo - if None use default package path
</del><ins>+        &quot;BasePath&quot;      : &quot;&quot;,        # Path to directory containing a zoneinfo - if None use default package path
</ins><span class="cx">                                      # secondary service MUST define its own writable path
</span><del>-        &quot;XMLInfoPath&quot;   : &quot;&quot;, # Path to db cache info - if None use default package path
</del><ins>+        &quot;XMLInfoPath&quot;   : &quot;&quot;,        # Path to db cache info - if None use default package path
</ins><span class="cx">                                      # secondary service MUST define its own writable path if
</span><span class="cx">                                      # not None
</span><ins>+        &quot;PrettyPrintJSON&quot; : True,    # User friendly JSON output
</ins><span class="cx"> 
</span><span class="cx">         &quot;SecondaryService&quot; : {
</span><span class="cx">             # Only one of these should be used when a secondary service is used
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavtimezonestdservicepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/timezonestdservice.py (14015 => 14016)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -225,6 +225,7 @@
</span><span class="cx">                         &quot;error&quot;: &quot;invalid-action&quot;,
</span><span class="cx">                         &quot;description&quot;: &quot;Invalid action query parameter&quot;,
</span><span class="cx">                     },
</span><ins>+                    pretty=config.TimezoneService.PrettyPrintJSON,
</ins><span class="cx">                 ))
</span><span class="cx">             action = action[0]
</span><span class="cx"> 
</span><span class="lines">@@ -242,6 +243,7 @@
</span><span class="cx">                         &quot;error&quot;: &quot;invalid-action&quot;,
</span><span class="cx">                         &quot;description&quot;: &quot;Unknown action query parameter&quot;,
</span><span class="cx">                     },
</span><ins>+                    pretty=config.TimezoneService.PrettyPrintJSON,
</ins><span class="cx">                 ))
</span><span class="cx"> 
</span><span class="cx">             return action(request)
</span><span class="lines">@@ -290,7 +292,7 @@
</span><span class="cx">                 },
</span><span class="cx">             ]
</span><span class="cx">         }
</span><del>-        return JSONResponse(responsecode.OK, result)
</del><ins>+        return JSONResponse(responsecode.OK, result, pretty=config.TimezoneService.PrettyPrintJSON)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def doList(self, request):
</span><span class="lines">@@ -306,6 +308,7 @@
</span><span class="cx">                     &quot;error&quot;: &quot;invalid-changedsince&quot;,
</span><span class="cx">                     &quot;description&quot;: &quot;Invalid changedsince query parameter&quot;,
</span><span class="cx">                 },
</span><ins>+                pretty=config.TimezoneService.PrettyPrintJSON,
</ins><span class="cx">             ))
</span><span class="cx">         if len(changedsince) == 1:
</span><span class="cx">             # Validate a date-time stamp
</span><span class="lines">@@ -319,11 +322,16 @@
</span><span class="cx">                         &quot;error&quot;: &quot;invalid-changedsince&quot;,
</span><span class="cx">                         &quot;description&quot;: &quot;Invalid changedsince query parameter&quot;,
</span><span class="cx">                     },
</span><ins>+                    pretty=config.TimezoneService.PrettyPrintJSON,
</ins><span class="cx">                 ))
</span><span class="cx">             if not dt.utc():
</span><span class="cx">                 raise HTTPError(JSONResponse(
</span><span class="cx">                     responsecode.BAD_REQUEST,
</span><del>-                    &quot;Invalid changedsince query parameter value&quot;,
</del><ins>+                    {
+                        &quot;error&quot;: &quot;invalid-changedsince&quot;,
+                        &quot;description&quot;: &quot;Invalid changedsince query parameter - not UTC&quot;,
+                    },
+                    pretty=config.TimezoneService.PrettyPrintJSON,
</ins><span class="cx">                 ))
</span><span class="cx"> 
</span><span class="cx">         timezones = []
</span><span class="lines">@@ -337,7 +345,7 @@
</span><span class="cx">             &quot;dtstamp&quot;: self.timezones.dtstamp,
</span><span class="cx">             &quot;timezones&quot;: timezones,
</span><span class="cx">         }
</span><del>-        return JSONResponse(responsecode.OK, result)
</del><ins>+        return JSONResponse(responsecode.OK, result, pretty=config.TimezoneService.PrettyPrintJSON)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def doGet(self, request):
</span><span class="lines">@@ -353,6 +361,7 @@
</span><span class="cx">                     &quot;error&quot;: &quot;invalid-tzid&quot;,
</span><span class="cx">                     &quot;description&quot;: &quot;Invalid tzid query parameter&quot;,
</span><span class="cx">                 },
</span><ins>+                pretty=config.TimezoneService.PrettyPrintJSON,
</ins><span class="cx">             ))
</span><span class="cx"> 
</span><span class="cx">         format = request.args.get(&quot;format&quot;, (&quot;text/calendar&quot;,))
</span><span class="lines">@@ -363,6 +372,7 @@
</span><span class="cx">                     &quot;error&quot;: &quot;invalid-format&quot;,
</span><span class="cx">                     &quot;description&quot;: &quot;Invalid format query parameter&quot;,
</span><span class="cx">                 },
</span><ins>+                pretty=config.TimezoneService.PrettyPrintJSON,
</ins><span class="cx">             ))
</span><span class="cx">         format = format[0]
</span><span class="cx"> 
</span><span class="lines">@@ -373,7 +383,8 @@
</span><span class="cx">                 {
</span><span class="cx">                     &quot;error&quot;: &quot;tzid-not-found&quot;,
</span><span class="cx">                     &quot;description&quot;: &quot;Tzid could not be found&quot;,
</span><del>-                }
</del><ins>+                },
+                pretty=config.TimezoneService.PrettyPrintJSON,
</ins><span class="cx">             ))
</span><span class="cx"> 
</span><span class="cx">         tzdata = calendar.getText(format=format if format != &quot;text/plain&quot; else None)
</span><span class="lines">@@ -397,6 +408,7 @@
</span><span class="cx">                     &quot;error&quot;: &quot;invalid-tzid&quot;,
</span><span class="cx">                     &quot;description&quot;: &quot;Invalid tzid query parameter&quot;,
</span><span class="cx">                 },
</span><ins>+                pretty=config.TimezoneService.PrettyPrintJSON,
</ins><span class="cx">             ))
</span><span class="cx"> 
</span><span class="cx">         try:
</span><span class="lines">@@ -415,7 +427,8 @@
</span><span class="cx">                 {
</span><span class="cx">                     &quot;error&quot;: &quot;invalid-start&quot;,
</span><span class="cx">                     &quot;description&quot;: &quot;Invalid start query parameter&quot;,
</span><del>-                }
</del><ins>+                },
+                pretty=config.TimezoneService.PrettyPrintJSON,
</ins><span class="cx">             ))
</span><span class="cx"> 
</span><span class="cx">         try:
</span><span class="lines">@@ -437,7 +450,8 @@
</span><span class="cx">                 {
</span><span class="cx">                     &quot;error&quot;: &quot;invalid-end&quot;,
</span><span class="cx">                     &quot;description&quot;: &quot;Invalid end query parameter&quot;,
</span><del>-                }
</del><ins>+                },
+                pretty=config.TimezoneService.PrettyPrintJSON,
</ins><span class="cx">             ))
</span><span class="cx"> 
</span><span class="cx">         tzid = tzids[0]
</span><span class="lines">@@ -448,7 +462,8 @@
</span><span class="cx">                 {
</span><span class="cx">                     &quot;error&quot;: &quot;tzid-not-found&quot;,
</span><span class="cx">                     &quot;description&quot;: &quot;Tzid could not be found&quot;,
</span><del>-                }
</del><ins>+                },
+                pretty=config.TimezoneService.PrettyPrintJSON,
</ins><span class="cx">             ))
</span><span class="cx"> 
</span><span class="cx">         # Now do the expansion (but use a cache to avoid re-calculating TZs)
</span><span class="lines">@@ -469,7 +484,7 @@
</span><span class="cx">                 } for onset, utc_offset_from, utc_offset_to, name in observances
</span><span class="cx">             ],
</span><span class="cx">         }
</span><del>-        return JSONResponse(responsecode.OK, result)
</del><ins>+        return JSONResponse(responsecode.OK, result, pretty=config.TimezoneService.PrettyPrintJSON)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunktxweb2httppy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txweb2/http.py (14015 => 14016)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -556,11 +556,15 @@
</span><span class="cx">     JSON L{Response} object.
</span><span class="cx">     Renders itself as an JSON document.
</span><span class="cx">     &quot;&quot;&quot;
</span><del>-    def __init__(self, code, jobj):
</del><ins>+    def __init__(self, code, jobj, pretty=False):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         @param jobj: a Python object that can be serialized to JSON.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Response.__init__(self, code, stream=json.dumps(jobj))
</del><ins>+        kwargs = {}
+        if pretty:
+            kwargs[&quot;indent&quot;] = 2
+            kwargs[&quot;separators&quot;] = (',', ':')
+        Response.__init__(self, code, stream=json.dumps(jobj, **kwargs))
</ins><span class="cx">         self.headers.setHeader(&quot;content-type&quot;, http_headers.MimeType(&quot;application&quot;, &quot;json&quot;))
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>