[CalendarServer-changes] [9526] CalDAVClientLibrary/trunk/caldavclientlibrary

source_changes at macosforge.org source_changes at macosforge.org
Mon Aug 6 09:41:19 PDT 2012


Revision: 9526
          http://trac.macosforge.org/projects/calendarserver/changeset/9526
Author:   cdaboo at apple.com
Date:     2012-08-06 09:41:19 -0700 (Mon, 06 Aug 2012)
Log Message:
-----------
Fix sync and multiget. Add calendar-query options.

Modified Paths:
--------------
    CalDAVClientLibrary/trunk/caldavclientlibrary/client/clientsession.py
    CalDAVClientLibrary/trunk/caldavclientlibrary/protocol/caldav/multiget.py

Added Paths:
-----------
    CalDAVClientLibrary/trunk/caldavclientlibrary/protocol/caldav/query.py

Modified: CalDAVClientLibrary/trunk/caldavclientlibrary/client/clientsession.py
===================================================================
--- CalDAVClientLibrary/trunk/caldavclientlibrary/client/clientsession.py	2012-08-03 23:35:56 UTC (rev 9525)
+++ CalDAVClientLibrary/trunk/caldavclientlibrary/client/clientsession.py	2012-08-06 16:41:19 UTC (rev 9526)
@@ -21,7 +21,6 @@
 from caldavclientlibrary.protocol.http.authentication.basic import Basic
 from caldavclientlibrary.protocol.http.authentication.digest import Digest
 from caldavclientlibrary.protocol.webdav.synccollection import SyncCollection
-from caldavclientlibrary.protocol.http.util import parseStatusLine
 try:
     from caldavclientlibrary.protocol.http.authentication.gssapi import Kerberos
 except ImportError:
@@ -523,10 +522,9 @@
 
                 # Get child element name (decode URL)
                 name = URL(url=item.getResource(), decode=True)
-                status = parseStatusLine(item.status)
-                if status == 404:
+                if item.status == 404:
                     removed.add(name)
-                elif status / 100 != 2:
+                elif item.status / 100 != 2:
                     other.add(name)
                 else:
                     changed.add(name)

Modified: CalDAVClientLibrary/trunk/caldavclientlibrary/protocol/caldav/multiget.py
===================================================================
--- CalDAVClientLibrary/trunk/caldavclientlibrary/protocol/caldav/multiget.py	2012-08-03 23:35:56 UTC (rev 9525)
+++ CalDAVClientLibrary/trunk/caldavclientlibrary/protocol/caldav/multiget.py	2012-08-06 16:41:19 UTC (rev 9526)
@@ -30,6 +30,8 @@
         self.props = props
         self.hrefs = hrefs
 
+        self.initRequestData()
+
     def initRequestData(self):
         # Write XML info to a string
         os = StringIO()

Added: CalDAVClientLibrary/trunk/caldavclientlibrary/protocol/caldav/query.py
===================================================================
--- CalDAVClientLibrary/trunk/caldavclientlibrary/protocol/caldav/query.py	                        (rev 0)
+++ CalDAVClientLibrary/trunk/caldavclientlibrary/protocol/caldav/query.py	2012-08-06 16:41:19 UTC (rev 9526)
@@ -0,0 +1,111 @@
+##
+# Copyright (c) 2012 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from StringIO import StringIO
+from caldavclientlibrary.protocol.caldav.definitions import caldavxml
+from caldavclientlibrary.protocol.http.data.string import RequestDataString
+from caldavclientlibrary.protocol.utils.xmlhelpers import BetterElementTree
+from caldavclientlibrary.protocol.webdav.definitions import davxml
+from caldavclientlibrary.protocol.webdav.report import Report
+from xml.etree.ElementTree import Element
+from xml.etree.ElementTree import SubElement
+
+class Query(Report):
+
+    def __init__(self, session, url, props=()):
+        super(Query, self).__init__(session, url)
+        self.props = props
+        
+        self.initRequestData()
+
+    def initRequestData(self):
+        # Write XML info to a string
+        os = StringIO()
+        self.generateXML(os)
+        self.request_data = RequestDataString(os.getvalue(), "text/xml charset=utf-8")
+    
+    def generateXML(self, os):
+        # Structure of document is:
+        #
+        # <CalDAV:calendar-query>
+        #   <DAV:prop>
+        #     <<names of each property as elements>>
+        #   </DAV:prop>
+        #   <CALDAV:filter>...</CALDAV:filter>
+        # </CalDAV:calendar-query>
+        
+        # <CalDAV:calendar-query> element
+        query = Element(caldavxml.calendar_query)
+        
+        if self.props:
+            # <DAV:prop> element
+            prop = SubElement(query, davxml.prop)
+            
+            # Now add each property
+            for propname in self.props:
+                # Add property element taking namespace into account
+                SubElement(prop, propname)
+        
+        # Now add each href
+        self.addFilterElement(query)
+        
+        # Now we have the complete document, so write it out (no indentation)
+        xmldoc = BetterElementTree(query)
+        xmldoc.writeUTF8(os)
+
+    def addFilterElement(self, query):
+        """
+        Add a CALDAV:filter element to the specified CALDAV:calendar-query element.
+        Sub-classes must override to add specific types of query
+        """
+        raise NotImplementedError
+
+class QueryVEVENTTimeRange(Query):
+
+    def __init__(self, session, url, trstart, trend, props=()):
+        
+        self.trstart = trstart
+        self.trend = trend
+        super(QueryVEVENTTimeRange, self).__init__(session, url, props)
+
+    def addFilterElement(self, query):
+        """
+        Add a CALDAV:filter element to the specified CALDAV:calendar-query element.
+        Sub-classes must override to add specific types of query
+        """
+
+        # Structure of document is:
+        #
+        # <CalDAV:filter>
+        #   <CALDAV:component-filter name="VCALENDAR">
+        #     <CALDAV:component-filter name="VEVENT">
+        #       <CALDAV:time-range start="..." end="...">
+        #       </CALDAV:time-range>
+        #     </CALDAV:component-filter>
+        #   </CALDAV:component-filter>
+        # </CalDAV:calendar-query>
+
+        filter = SubElement(query, caldavxml.filter)
+        calcompfilter = SubElement(filter, caldavxml.comp_filter, {"name":"VCALENDAR"})
+        eventcompfilter = SubElement(calcompfilter, caldavxml.comp_filter, {"name":"VEVENT"})
+
+        tr = {}
+        if self.trstart:
+            tr["start"] = self.trstart
+        if self.trend:
+            tr["end"] = self.trend
+        SubElement(eventcompfilter, caldavxml.time_range, tr)
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120806/33a7ec7d/attachment.html>


More information about the calendarserver-changes mailing list