<!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>[14179] CalendarServer/trunk/twistedcaldav/timezonestdservice.py</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/14179">14179</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-11-16 14:37:12 -0800 (Sun, 16 Nov 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Update to latest tzdist spec.</pre>

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

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktwistedcaldavtimezonestdservicepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/timezonestdservice.py (14178 => 14179)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/timezonestdservice.py        2014-11-16 22:35:52 UTC (rev 14178)
+++ CalendarServer/trunk/twistedcaldav/timezonestdservice.py        2014-11-16 22:37:12 UTC (rev 14179)
</span><span class="lines">@@ -47,6 +47,7 @@
</span><span class="cx"> from twistedcaldav.resource import ReadOnlyNoCopyResourceMixIn
</span><span class="cx"> from twistedcaldav.timezones import TimezoneException, TimezoneCache, readVTZ, \
</span><span class="cx">     addVTZ
</span><ins>+from twistedcaldav.util import bestAcceptType
</ins><span class="cx"> from twistedcaldav.xmlutil import addSubElement
</span><span class="cx"> 
</span><span class="cx"> from pycalendar.icalendar.calendar import Calendar
</span><span class="lines">@@ -57,6 +58,7 @@
</span><span class="cx"> import itertools
</span><span class="cx"> import json
</span><span class="cx"> import os
</span><ins>+import urllib
</ins><span class="cx"> 
</span><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><span class="lines">@@ -91,9 +93,9 @@
</span><span class="cx"> 
</span><span class="cx">         self.formats = []
</span><span class="cx">         self.formats.append(&quot;text/calendar&quot;)
</span><del>-        self.formats.append(&quot;text/plain&quot;)
</del><span class="cx">         if config.EnableJSONData:
</span><span class="cx">             self.formats.append(&quot;application/calendar+json&quot;)
</span><ins>+        self.formats.append(&quot;text/plain&quot;)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def _initPrimaryService(self):
</span><span class="lines">@@ -196,68 +198,103 @@
</span><span class="cx"> 
</span><span class="cx">     http_PROPFIND = http_PROPFIND
</span><span class="cx"> 
</span><ins>+    def problemReport(self, code, description, status):
+        raise HTTPError(JSONResponse(
+            status,
+            {
+                &quot;type&quot;: &quot;https://datatracker.ietf.org/doc/draft-ietf-tzdist-service/&quot;,
+                &quot;error-code&quot;: code,
+                &quot;title&quot;: description,
+                &quot;status&quot;: status,
+            },
+            pretty=config.TimezoneService.PrettyPrintJSON,
+        ))
+
+
</ins><span class="cx">     def http_POST(self, request):
</span><span class="cx">         raise HTTPError(StatusResponse(responsecode.NOT_ALLOWED, &quot;Method not allowed&quot;))
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def http_GET(self, request):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         The timezone service GET method.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        # Check authentication and access controls
-        def _gotResult(_):
</del><ins>+        yield self.authorize(request, (davxml.Read(),))
</ins><span class="cx"> 
</span><del>-            if not request.args:
-                # Do normal GET behavior
-                return self.render(request)
</del><ins>+        urlbits = map(urllib.unquote, request.path.strip(&quot;/&quot;).split(&quot;/&quot;)[1:])
+        child = urlbits[0] if len(urlbits) &gt; 0 else &quot;&quot;
</ins><span class="cx"> 
</span><del>-            action = request.args.get(&quot;action&quot;, (&quot;&quot;,))
-            if len(action) != 1:
-                raise HTTPError(JSONResponse(
-                    responsecode.BAD_REQUEST,
-                    {
-                        &quot;error&quot;: &quot;invalid-action&quot;,
-                        &quot;description&quot;: &quot;Invalid action query parameter&quot;,
-                    },
-                    pretty=config.TimezoneService.PrettyPrintJSON,
-                ))
-            action = action[0]
</del><ins>+        if not child:
+            if len(request.args) != 0:
+                self.problemReport(&quot;invalid-action&quot;, &quot;Invalid request-URI query parameters&quot;, responsecode.BAD_REQUEST)
</ins><span class="cx"> 
</span><del>-            action = {
-                &quot;capabilities&quot;  : self.doCapabilities,
-                &quot;list&quot;          : self.doList,
-                &quot;get&quot;           : self.doGet,
-                &quot;expand&quot;        : self.doExpand,
-                &quot;find&quot;          : self.doFind,
-            }.get(action, None)
</del><ins>+            # Do normal GET behavior
+            returnValue(self.render(request))
</ins><span class="cx"> 
</span><del>-            if action is None:
-                raise HTTPError(JSONResponse(
-                    responsecode.BAD_REQUEST,
-                    {
-                        &quot;error&quot;: &quot;invalid-action&quot;,
-                        &quot;description&quot;: &quot;Unknown action query parameter&quot;,
-                    },
-                    pretty=config.TimezoneService.PrettyPrintJSON,
-                ))
</del><ins>+        childResponder = {
+            &quot;capabilities&quot;  : self.childCapabilities,
+            &quot;zones&quot;         : self.childZones,
+            &quot;observances&quot;   : self.childObservances,
+        }.get(child, None)
</ins><span class="cx"> 
</span><del>-            return action(request)
</del><ins>+        if childResponder is None:
+            self.problemReport(&quot;invalid-action&quot;, &quot;Invalid action&quot;, responsecode.BAD_REQUEST)
</ins><span class="cx"> 
</span><del>-        d = self.authorize(request, (davxml.Read(),))
-        d.addCallback(_gotResult)
-        return d
</del><ins>+        returnValue(childResponder(request, urlbits))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def doCapabilities(self, request):
</del><ins>+    def childCapabilities(self, request, urlbits):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        Return a list of all timezones known to the server.
</del><ins>+        Request on {/service-prefix}/capabilities.
</ins><span class="cx">         &quot;&quot;&quot;
</span><ins>+        if len(urlbits) != 1:
+            self.problemReport(&quot;invalid-action&quot;, &quot;Invalid path segment&quot;, responsecode.BAD_REQUEST)
+        return self.actionCapabilities(request)
</ins><span class="cx"> 
</span><ins>+
+    def childZones(self, request, urlbits):
+        &quot;&quot;&quot;
+        Request on {/service-prefix}/zones.
+        &quot;&quot;&quot;
+        if len(urlbits) == 2:
+            return self.actionGet(request, urlbits[1])
+        elif len(urlbits) == 1:
+            pattern = request.args.get(&quot;pattern&quot;, ())
+            if len(pattern) == 0:
+                return self.actionList(request)
+            else:
+                return self.actionFind(request)
+        else:
+            self.problemReport(&quot;invalid-action&quot;, &quot;Invalid path segment&quot;, responsecode.BAD_REQUEST)
+
+
+    def childObservances(self, request, urlbits):
+        &quot;&quot;&quot;
+        Request on {/service-prefix}/observances.
+        &quot;&quot;&quot;
+        if len(urlbits) == 2:
+            return self.actionExpand(request, urlbits[1])
+        elif len(urlbits) == 1:
+            self.problemReport(&quot;invalid-action&quot;, &quot;Missing {tzid} path segment&quot;, responsecode.BAD_REQUEST)
+        else:
+            self.problemReport(&quot;invalid-action&quot;, &quot;Invalid path segment&quot;, responsecode.BAD_REQUEST)
+
+
+    def actionCapabilities(self, request):
+        &quot;&quot;&quot;
+        Return the capabilities of this server.
+        &quot;&quot;&quot;
+
+        if len(request.args) != 0:
+            self.problemReport(&quot;invalid-action&quot;, &quot;Invalid request-URI query parameters&quot;, responsecode.BAD_REQUEST)
+
</ins><span class="cx">         result = {
</span><span class="cx">             &quot;version&quot;: &quot;1&quot;,
</span><span class="cx">             &quot;info&quot; : {
</span><span class="cx">                 &quot;primary-source&quot; if self.primary else &quot;secondary_source&quot;: self.info_source,
</span><ins>+                &quot;formats&quot;: self.formats,
</ins><span class="cx">                 &quot;contacts&quot; : [],
</span><span class="cx">             },
</span><span class="cx">             &quot;actions&quot; : [
</span><span class="lines">@@ -274,16 +311,16 @@
</span><span class="cx">                 {
</span><span class="cx">                     &quot;name&quot;: &quot;get&quot;,
</span><span class="cx">                     &quot;parameters&quot;: [
</span><del>-                        {&quot;name&quot;: &quot;format&quot;, &quot;required&quot;: False, &quot;multi&quot;: False, &quot;values&quot;: self.formats, },
-                        {&quot;name&quot;: &quot;tzid&quot;, &quot;required&quot;: True, &quot;multi&quot;: False, },
</del><ins>+                        {&quot;name&quot;: &quot;start&quot;, &quot;required&quot;: False, &quot;multi&quot;: False},
+                        {&quot;name&quot;: &quot;stop&quot;, &quot;required&quot;: False, &quot;multi&quot;: False, },
</ins><span class="cx">                     ],
</span><span class="cx">                 },
</span><span class="cx">                 {
</span><span class="cx">                     &quot;name&quot;: &quot;expand&quot;,
</span><span class="cx">                     &quot;parameters&quot;: [
</span><del>-                        {&quot;name&quot;: &quot;tzid&quot;, &quot;required&quot;: True, &quot;multi&quot;: False, },
-                        {&quot;name&quot;: &quot;start&quot;, &quot;required&quot;: False, &quot;multi&quot;: False, },
-                        {&quot;name&quot;: &quot;end&quot;, &quot;required&quot;: False, &quot;multi&quot;: False, },
</del><ins>+                        {&quot;name&quot;: &quot;start&quot;, &quot;required&quot;: True, &quot;multi&quot;: False, },
+                        {&quot;name&quot;: &quot;end&quot;, &quot;required&quot;: True, &quot;multi&quot;: False, },
+                        {&quot;name&quot;: &quot;changedsince&quot;, &quot;required&quot;: False, &quot;multi&quot;: False, },
</ins><span class="cx">                     ],
</span><span class="cx">                 },
</span><span class="cx">                 {
</span><span class="lines">@@ -297,44 +334,26 @@
</span><span class="cx">         return JSONResponse(responsecode.OK, result, pretty=config.TimezoneService.PrettyPrintJSON)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def doList(self, request):
</del><ins>+    def actionList(self, request):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Return a list of all timezones known to the server.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><ins>+        if set(request.args.keys()) - set((&quot;changedsince&quot;,)):
+            self.problemReport(&quot;invalid-action&quot;, &quot;Invalid request-URI query parameters&quot;, responsecode.BAD_REQUEST)
+
</ins><span class="cx">         changedsince = request.args.get(&quot;changedsince&quot;, ())
</span><span class="cx">         if len(changedsince) &gt; 1:
</span><del>-            raise HTTPError(JSONResponse(
-                responsecode.BAD_REQUEST,
-                {
-                    &quot;error&quot;: &quot;invalid-changedsince&quot;,
-                    &quot;description&quot;: &quot;Invalid changedsince query parameter&quot;,
-                },
-                pretty=config.TimezoneService.PrettyPrintJSON,
-            ))
</del><ins>+            self.problemReport(&quot;invalid-changedsince&quot;, &quot;Too many changedsince request-URI query parameters&quot;, responsecode.BAD_REQUEST)
</ins><span class="cx">         if len(changedsince) == 1:
</span><span class="cx">             # Validate a date-time stamp
</span><span class="cx">             changedsince = changedsince[0]
</span><span class="cx">             try:
</span><del>-                dt = DateTime.parseText(changedsince)
</del><ins>+                dt = DateTime.parseText(changedsince, fullISO=True)
</ins><span class="cx">             except ValueError:
</span><del>-                raise HTTPError(JSONResponse(
-                    responsecode.BAD_REQUEST,
-                    {
-                        &quot;error&quot;: &quot;invalid-changedsince&quot;,
-                        &quot;description&quot;: &quot;Invalid changedsince query parameter&quot;,
-                    },
-                    pretty=config.TimezoneService.PrettyPrintJSON,
-                ))
</del><ins>+                self.problemReport(&quot;invalid-changedsince&quot;, &quot;Invalid changedsince request-URI query parameter value&quot;, responsecode.BAD_REQUEST)
</ins><span class="cx">             if not dt.utc():
</span><del>-                raise HTTPError(JSONResponse(
-                    responsecode.BAD_REQUEST,
-                    {
-                        &quot;error&quot;: &quot;invalid-changedsince&quot;,
-                        &quot;description&quot;: &quot;Invalid changedsince query parameter - not UTC&quot;,
-                    },
-                    pretty=config.TimezoneService.PrettyPrintJSON,
-                ))
</del><ins>+                self.problemReport(&quot;invalid-changedsince&quot;, &quot;Invalid changedsince request-URI query parameter value - not UTC&quot;, responsecode.BAD_REQUEST)
</ins><span class="cx"> 
</span><span class="cx">         timezones = []
</span><span class="cx">         for tz in self.timezones.listTimezones(changedsince):
</span><span class="lines">@@ -350,124 +369,69 @@
</span><span class="cx">         return JSONResponse(responsecode.OK, result, pretty=config.TimezoneService.PrettyPrintJSON)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def doGet(self, request):
</del><ins>+    def actionGet(self, request, tzid):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Return the specified timezone data.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        tzids = request.args.get(&quot;tzid&quot;, ())
-        if len(tzids) != 1:
-            raise HTTPError(JSONResponse(
-                responsecode.BAD_REQUEST,
-                {
-                    &quot;error&quot;: &quot;invalid-tzid&quot;,
-                    &quot;description&quot;: &quot;Invalid tzid query parameter&quot;,
-                },
-                pretty=config.TimezoneService.PrettyPrintJSON,
-            ))
</del><ins>+        if set(request.args.keys()) - set((&quot;start&quot;, &quot;end&quot;,)):
+            self.problemReport(&quot;invalid-action&quot;, &quot;Invalid request-URI query parameters&quot;, responsecode.BAD_REQUEST)
</ins><span class="cx"> 
</span><del>-        format = request.args.get(&quot;format&quot;, (&quot;text/calendar&quot;,))
-        if len(format) != 1 or format[0] not in self.formats:
-            raise HTTPError(JSONResponse(
-                responsecode.BAD_REQUEST,
-                {
-                    &quot;error&quot;: &quot;invalid-format&quot;,
-                    &quot;description&quot;: &quot;Invalid format query parameter&quot;,
-                },
-                pretty=config.TimezoneService.PrettyPrintJSON,
-            ))
-        format = format[0]
</del><ins>+        accepted_type = bestAcceptType(request.headers.getHeader(&quot;accept&quot;), self.formats)
+        if accepted_type is None:
+            self.problemReport(&quot;invalid-format&quot;, &quot;Accept header does not match available media types&quot;, responsecode.NOT_ACCEPTABLE)
</ins><span class="cx"> 
</span><del>-        calendar = self.timezones.getTimezone(tzids[0])
</del><ins>+        calendar = self.timezones.getTimezone(tzid)
</ins><span class="cx">         if calendar is None:
</span><del>-            raise HTTPError(JSONResponse(
-                responsecode.NOT_FOUND,
-                {
-                    &quot;error&quot;: &quot;tzid-not-found&quot;,
-                    &quot;description&quot;: &quot;Tzid could not be found&quot;,
-                },
-                pretty=config.TimezoneService.PrettyPrintJSON,
-            ))
</del><ins>+            self.problemReport(&quot;tzid-not-found&quot;, &quot;Time zone identifier not found&quot;, responsecode.NOT_FOUND)
</ins><span class="cx"> 
</span><del>-        tzdata = calendar.getText(format=format if format != &quot;text/plain&quot; else None)
</del><ins>+        tzdata = calendar.getText(format=accepted_type if accepted_type != &quot;text/plain&quot; else None)
</ins><span class="cx"> 
</span><span class="cx">         response = Response()
</span><span class="cx">         response.stream = MemoryStream(tzdata)
</span><del>-        response.headers.setHeader(&quot;content-type&quot;, MimeType.fromString(&quot;%s; charset=utf-8&quot; % (format,)))
</del><ins>+        response.headers.setHeader(&quot;content-type&quot;, MimeType.fromString(&quot;%s; charset=utf-8&quot; % (accepted_type,)))
</ins><span class="cx">         return response
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def doExpand(self, request):
</del><ins>+    def actionExpand(self, request, tzid):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Expand a timezone within specified start/end dates.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        tzids = request.args.get(&quot;tzid&quot;, ())
-        if len(tzids) != 1:
-            raise HTTPError(JSONResponse(
-                responsecode.BAD_REQUEST,
-                {
-                    &quot;error&quot;: &quot;invalid-tzid&quot;,
-                    &quot;description&quot;: &quot;Invalid tzid query parameter&quot;,
-                },
-                pretty=config.TimezoneService.PrettyPrintJSON,
-            ))
</del><ins>+        if set(request.args.keys()) - set((&quot;start&quot;, &quot;end&quot;, &quot;changedsince&quot;,)):
+            self.problemReport(&quot;invalid-action&quot;, &quot;Invalid request-URI query parameters&quot;, responsecode.BAD_REQUEST)
</ins><span class="cx"> 
</span><del>-        try:
-            start = request.args.get(&quot;start&quot;, ())
-            if len(start) != 1:
-                raise ValueError()
-            elif len(start) == 1:
</del><ins>+        start = request.args.get(&quot;start&quot;, ())
+        if len(start) == 0:
+            self.problemReport(&quot;invalid-start&quot;, &quot;Missing start request-URI query parameter&quot;, responsecode.BAD_REQUEST)
+        if len(start) &gt; 1:
+            self.problemReport(&quot;invalid-start&quot;, &quot;Too many start request-URI query parameters&quot;, responsecode.BAD_REQUEST)
+        elif len(start) == 1:
+            try:
</ins><span class="cx">                 if len(start[0]) != 20:
</span><span class="cx">                     raise ValueError()
</span><span class="cx">                 start = DateTime.parseText(start[0], fullISO=True)
</span><del>-        except ValueError:
-            raise HTTPError(JSONResponse(
-                responsecode.BAD_REQUEST,
-                {
-                    &quot;error&quot;: &quot;invalid-start&quot;,
-                    &quot;description&quot;: &quot;Invalid start query parameter&quot;,
-                },
-                pretty=config.TimezoneService.PrettyPrintJSON,
-            ))
</del><ins>+            except ValueError:
+                self.problemReport(&quot;invalid-start&quot;, &quot;Invalid start request-URI query parameter value&quot;, responsecode.BAD_REQUEST)
</ins><span class="cx"> 
</span><del>-        try:
-            end = request.args.get(&quot;end&quot;, ())
-            if len(end) &gt; 1:
-                raise ValueError()
-            elif len(end) == 1:
</del><ins>+        end = request.args.get(&quot;end&quot;, ())
+        if len(end) == 0:
+            self.problemReport(&quot;invalid-end&quot;, &quot;Missing end request-URI query parameter&quot;, responsecode.BAD_REQUEST)
+        if len(end) &gt; 1:
+            self.problemReport(&quot;invalid-end&quot;, &quot;Too many end request-URI query parameters&quot;, responsecode.BAD_REQUEST)
+        elif len(end) == 1:
+            try:
</ins><span class="cx">                 if len(end[0]) != 20:
</span><span class="cx">                     raise ValueError()
</span><span class="cx">                 end = DateTime.parseText(end[0], fullISO=True)
</span><del>-            else:
-                end = DateTime.getNowUTC()
-                end.setDay(1)
-                end.setMonth(1)
-                start.setHHMMSS(0, 0, 0)
-                end.offsetYear(10)
</del><ins>+            except ValueError:
+                self.problemReport(&quot;invalid-end&quot;, &quot;Invalid end request-URI query parameter value&quot;, responsecode.BAD_REQUEST)
</ins><span class="cx">             if end &lt;= start:
</span><del>-                raise ValueError()
-        except ValueError:
-            raise HTTPError(JSONResponse(
-                responsecode.BAD_REQUEST,
-                {
-                    &quot;error&quot;: &quot;invalid-end&quot;,
-                    &quot;description&quot;: &quot;Invalid end query parameter&quot;,
-                },
-                pretty=config.TimezoneService.PrettyPrintJSON,
-            ))
</del><ins>+                self.problemReport(&quot;invalid-end&quot;, &quot;Invalid end request-URI query parameter value - earlier than start&quot;, responsecode.BAD_REQUEST)
</ins><span class="cx"> 
</span><del>-        tzid = tzids[0]
</del><span class="cx">         tzdata = self.timezones.getTimezone(tzid)
</span><span class="cx">         if tzdata is None:
</span><del>-            raise HTTPError(JSONResponse(
-                responsecode.NOT_FOUND,
-                {
-                    &quot;error&quot;: &quot;tzid-not-found&quot;,
-                    &quot;description&quot;: &quot;Tzid could not be found&quot;,
-                },
-                pretty=config.TimezoneService.PrettyPrintJSON,
-            ))
</del><ins>+            self.problemReport(&quot;tzid-not-found&quot;, &quot;Time zone identifier not found&quot;, responsecode.NOT_FOUND)
</ins><span class="cx"> 
</span><span class="cx">         # Now do the expansion (but use a cache to avoid re-calculating TZs)
</span><span class="cx">         observances = self.expandcache.get((tzid, start, end), None)
</span><span class="lines">@@ -491,21 +455,19 @@
</span><span class="cx">         return JSONResponse(responsecode.OK, result, pretty=config.TimezoneService.PrettyPrintJSON)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def doFind(self, request):
</del><ins>+    def actionFind(self, request):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Return a list of all timezones matching a pattern.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><ins>+        if set(request.args.keys()) - set((&quot;pattern&quot;,)):
+            self.problemReport(&quot;invalid-action&quot;, &quot;Invalid request-URI query parameters&quot;, responsecode.BAD_REQUEST)
+
</ins><span class="cx">         pattern = request.args.get(&quot;pattern&quot;, ())
</span><del>-        if len(pattern) != 1:
-            raise HTTPError(JSONResponse(
-                responsecode.BAD_REQUEST,
-                {
-                    &quot;error&quot;: &quot;invalid-pattern&quot;,
-                    &quot;description&quot;: &quot;Invalid pattern query parameter&quot;,
-                },
-                pretty=config.TimezoneService.PrettyPrintJSON,
-            ))
</del><ins>+        if len(pattern) == 0:
+            self.problemReport(&quot;invalid-pattern&quot;, &quot;Missing pattern request-URI query parameter&quot;, responsecode.BAD_REQUEST)
+        elif len(pattern) &gt; 1:
+            self.problemReport(&quot;invalid-pattern&quot;, &quot;Too many pattern request-URI query parameters&quot;, responsecode.BAD_REQUEST)
</ins><span class="cx">         pattern = pattern[0]
</span><span class="cx"> 
</span><span class="cx">         def _comp_is(pattern, s):
</span><span class="lines">@@ -534,14 +496,7 @@
</span><span class="cx">         pattern = _normalize(pattern)
</span><span class="cx"> 
</span><span class="cx">         if not pattern:
</span><del>-            raise HTTPError(JSONResponse(
-                responsecode.BAD_REQUEST,
-                {
-                    &quot;error&quot;: &quot;invalid-pattern&quot;,
-                    &quot;description&quot;: &quot;Invalid pattern query parameter&quot;,
-                },
-                pretty=config.TimezoneService.PrettyPrintJSON,
-            ))
</del><ins>+            self.problemReport(&quot;invalid-pattern&quot;, &quot;Invalid pattern request-URI query parameter value&quot;, responsecode.BAD_REQUEST)
</ins><span class="cx"> 
</span><span class="cx">         timezones = []
</span><span class="cx">         for tz in self.timezones.listTimezones(None):
</span></span></pre>
</div>
</div>

</body>
</html>