[Calypso] Incorrect parsing of rrule?

Petter Reinholdtsen pere at hungry.com
Thu Jan 28 00:29:13 PST 2016


[Guido Günther]
> The question is not if we fail the request but rather how badly. Do we
> fail the full one or only this part of the multistatus. See the
> report() function on how it builds up a multistatus (207) reply with
> several status embedded in the response body (which in turn can be any
> HTTP status code).

Aha.

> That's why I would opt for only failing this particular rule (with an
> appropriate status in the XML set via report() instead of failing the
> whole request.

Not quite sure about the notation of multistatus, but is this something
like what you had in mind?

diff --git a/calypso/xmlutils.py b/calypso/xmlutils.py
index 67290b7..4eacf5a 100644
--- a/calypso/xmlutils.py
+++ b/calypso/xmlutils.py
@@ -275,6 +275,19 @@ def match_filter_element(vobject, fe):
             return False
         start = fe.get("start")
         end = fe.get("end")
+        # According to RFC 4791, one of start and stop must be set,
+        # but the other can be empty.  If both are empty, the
+        # specification is violated.
+        if start is None and end is None:
+            msg = "time-range missing both start and stop attribute (required by RFC 4
791)"
+            log.error(msg)
+            raise ValueError(msg)
+        # RFC 4791 state if start is missing, assume it is -infinity
+        if start is None:
+            start = "00010101T000000Z" # start of year one
+        # RFC 4791 state if end is missing, assume it is +infinity
+        if end is None:
+            end = "99991231T235959Z" # last date with four digit year
         if rruleset is None:
             rruleset = dateutil.rrule.rruleset()
             dtstart = vobject.dtstart.value
@@ -357,8 +370,15 @@ def report(path, xml_request, collection):
 
         
         for item in items:
-            if not match_filter(item, filter_element):
-                continue
+            try:
+                if not match_filter(item, filter_element):
+                    continue
+            except ValueError as e:
+                # FIXME figure out how to pass e.msg to client
+                response = ET.Element(_tag("D", "response"))
+                multistatus.append(response)
+                status.text = _response(client.BAD_REQUEST)
+                pass
 
             response = ET.Element(_tag("D", "response"))
             multistatus.append(response)
-- 
Happy hacking
Petter Reinholdtsen


More information about the Calypso mailing list