[CalendarServer-changes] [262] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Fri Oct 6 17:45:21 PDT 2006


Revision: 262
          http://trac.macosforge.org/projects/calendarserver/changeset/262
Author:   wsanchez at apple.com
Date:     2006-10-06 17:45:20 -0700 (Fri, 06 Oct 2006)

Log Message:
-----------
API cleanup for CalendarPrincipalResource.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/directory.py
    CalendarServer/trunk/twistedcaldav/ical.py
    CalendarServer/trunk/twistedcaldav/icaldav.py
    CalendarServer/trunk/twistedcaldav/itip.py
    CalendarServer/trunk/twistedcaldav/method/schedule_common.py
    CalendarServer/trunk/twistedcaldav/resource.py

Modified: CalendarServer/trunk/twistedcaldav/directory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory.py	2006-10-07 00:44:45 UTC (rev 261)
+++ CalendarServer/trunk/twistedcaldav/directory.py	2006-10-07 00:45:20 UTC (rev 262)
@@ -214,28 +214,16 @@
 
         return super(DirectoryPrincipalFile, self).readProperty(qname, request)
 
-    def calendarUserAddressSet(self):
-        """
-        @return: a list of calendar user addresses for this principal.
-        """
-
+    def calendarUserAddresses(self):
         # Must have a valid calendar principal uri
         if self.hasDeadProperty(customxml.TwistedCalendarPrincipalURI):
-            return caldavxml.CalendarUserAddressSet(davxml.HRef().fromString(self.getPropertyValue(customxml.TwistedCalendarPrincipalURI)))
+            return (self.getPropertyValue(customxml.TwistedCalendarPrincipalURI),)
         else:
             # If there is no calendar principal URI then the calendar user is disabled so do not provide
             # a valid calendar address.
-            return caldavxml.CalendarUserAddressSet()
+            return ()
 
     def matchesCalendarUserAddress(self, request, address):
-        """
-        Determine whether this principal matches the supplied calendar user
-        address.
-
-        @param address: the calendar user address to match.
-        @return: C{True} if the principal matches, C{False} otherwise.
-        """
-
         # By default we will always allow either a relative or absolute URI to the principal to
         # be supplied as a valid calendar user address.
 

Modified: CalendarServer/trunk/twistedcaldav/ical.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/ical.py	2006-10-07 00:44:45 UTC (rev 261)
+++ CalendarServer/trunk/twistedcaldav/ical.py	2006-10-07 00:45:20 UTC (rev 262)
@@ -939,6 +939,7 @@
         @param match: a C{list} of calendar user address strings to try and match.
         @return: the string value of the Organizer property, or None
         """
+        # FIXME: match argument is unused (except in recursion...)
         
         # Extract appropriate sub-component if this is a VCALENDAR
         if self.name() == "VCALENDAR":

Modified: CalendarServer/trunk/twistedcaldav/icaldav.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/icaldav.py	2006-10-07 00:44:45 UTC (rev 261)
+++ CalendarServer/trunk/twistedcaldav/icaldav.py	2006-10-07 00:45:20 UTC (rev 262)
@@ -132,27 +132,25 @@
     """
     def principalUID():
         """
-        Get the user id for this principal.
+        @return: the user id for this principal.
         """
 
-    def calendarHomeSet():
+    def calendarHomeURLs():
         """
-        Get list of calendar collections for this principal's calendar user.
-        @return: L{CalendarHomeSet} element.
+        @return: a list of calendar home URLs for this principal's calendar user.
         """
 
-    def calendarUserAddressSet():
+    def calendarUserAddresses():
         """
-        Get list of calendar user addresses for this principal's calendar user.
-        @return: L{CalendarUserAddressSet} element.
+        @return: a list of calendar user addresses for this principal's calendar
+            user.
         """
 
-    def calendarFreeBusySet(request):
+    def calendarFreeBusyURIs(self, request):
         """
-        Get list of calendars that contribute to free-busy for this principal's calendar user.
-        This property actually resides on the schedule Inbox.
-        @param request: L{twisted.web2.server.Request} for the current request.
-        @return: L{CalendarFreeBusySet} element.
+        @param request: the request being processed.
+        @return: a L{Deferred} list of URIs for calendars that contribute to
+            free-busy for this principal's calendar user.
         """
 
     def scheduleInboxURL():

Modified: CalendarServer/trunk/twistedcaldav/itip.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/itip.py	2006-10-07 00:44:45 UTC (rev 261)
+++ CalendarServer/trunk/twistedcaldav/itip.py	2006-10-07 00:45:20 UTC (rev 262)
@@ -163,14 +163,13 @@
         # to free-busy as we will need to update those with the new one.
         
         # Find the current recipients calendar-free-busy-set
-        fbset = waitForDeferred(principal.calendarFreeBusySet(request))
+        fbset = waitForDeferred(principal.calendarFreeBusyURIs(request))
         yield fbset
         fbset = fbset.getResult()
 
         # Find the first calendar in the list with a component matching the one we are processing
         calmatch = None
-        for href in fbset.children:
-            calURL = str(href)
+        for calURL in fbset:
             updatecal = waitForDeferred(request.locateResource(calURL))
             yield updatecal
             updatecal = updatecal.getResult()
@@ -223,8 +222,8 @@
                 return
         else:
             # Write new resource into first calendar in f-b-set
-            if len(fbset.children) != 0 and accepted:
-                calURL = str(fbset.children[0])
+            if len(fbset) != 0 and accepted:
+                calURL = fbset[0]
                 updatecal = waitForDeferred(request.locateResource(calURL))
                 yield updatecal
                 updatecal = updatecal.getResult()
@@ -363,14 +362,13 @@
         # to free-busy as we will need to update those with the new one.
         
         # Find the current recipients calendar-free-busy-set
-        fbset = waitForDeferred(principal.calendarFreeBusySet(request))
+        fbset = waitForDeferred(principal.calendarFreeBusyURIs(request))
         yield fbset
         fbset = fbset.getResult()
 
         # Find the first calendar in the list with a component matching the one we are processing
         calmatch = None
-        for href in fbset.children:
-            calURL = str(href)
+        for calURL in fbset:
             updatecal = waitForDeferred(request.locateResource(calURL))
             yield updatecal
             updatecal = updatecal.getResult()
@@ -455,11 +453,11 @@
     uid = comp.propertyValue("UID")
 
     # Now compare each instance time-range with the index and see if there is an overlap
-    fbset = waitForDeferred(principal.calendarFreeBusySet(request))
+    fbset = waitForDeferred(principal.calendarFreeBusyURIs(request))
     yield fbset
     fbset = fbset.getResult()
-    for href in fbset.children:
-        calURL = str(href)
+
+    for calURL in fbset:
         testcal = waitForDeferred(request.locateResource(calURL))
         yield testcal
         testcal = testcal.getResult()
@@ -490,7 +488,7 @@
             break
      
     # Extract the ATTENDEE property matching current recipient from the calendar data
-    cuas = principal.calendarUserAddressSet()
+    cuas = principal.calendarUserAddresses()
     attendeeProp = calendar.getAttendeeProperty(cuas)
     if attendeeProp is None:
         yield False, None, accepted

Modified: CalendarServer/trunk/twistedcaldav/method/schedule_common.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/method/schedule_common.py	2006-10-07 00:44:45 UTC (rev 261)
+++ CalendarServer/trunk/twistedcaldav/method/schedule_common.py	2006-10-07 00:45:20 UTC (rev 262)
@@ -272,11 +272,11 @@
             # Different behaviour for free-busy vs regular invite
             if freebusy:
                 # Extract the ATTENDEE property matching current recipient from the calendar data
-                cuas = principal.calendarUserAddressSet()
+                cuas = principal.calendarUserAddresses()
                 attendeeProp = calendar.getAttendeeProperty(cuas)
             
                 # Find the current recipients calendar-free-busy-set
-                fbset = waitForDeferred(principal.calendarFreeBusySet(request))
+                fbset = waitForDeferred(principal.calendarFreeBusyURIs(request))
                 yield fbset
                 fbset = fbset.getResult()
 
@@ -285,8 +285,7 @@
                 
                 try:
                     matchtotal = 0
-                    for href in fbset.children:
-                        calURL = str(href)
+                    for calURL in fbset:
                         cal = waitForDeferred(request.locateResource(calURL))
                         yield cal
                         cal = cal.getResult()

Modified: CalendarServer/trunk/twistedcaldav/resource.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/resource.py	2006-10-07 00:44:45 UTC (rev 261)
+++ CalendarServer/trunk/twistedcaldav/resource.py	2006-10-07 00:45:20 UTC (rev 262)
@@ -85,7 +85,7 @@
             # Render a monolithic iCalendar file
             if request.uri[-1] != "/":
                 # Redirect to include trailing '/' in URI
-                return RedirectResponse(request.unparseURL(path=request.path+'/'))
+                return RedirectResponse(request.unparseURL(path=request.path+"/"))
 
             def _defer(data):
                 response = Response()
@@ -143,8 +143,8 @@
         if namespace == caldav_namespace:
             if name == "supported-calendar-component-set":
                 # CalDAV-access-09, section 5.2.3
-                if self.deadProperties().contains(qname):
-                    return succeed(self.deadProperties().get(qname))
+                if self.hasDeadProperty(qname):
+                    return succeed(self.readDeadProperty(qname))
                 return succeed(self.supportedCalendarComponentSet)
             elif name == "supported-calendar-data":
                 # CalDAV-access-09, section 5.2.4
@@ -251,10 +251,7 @@
 
     def findCalendarCollections(self, depth, request, callback, privileges=None):
         """
-        See L{IDAVResource.findChildren}.
-
-        This implementation works for C{depth} values of C{"0"}, C{"1"}, 
-        and C{"infinity"}.  As long as C{self.listChildren} is implemented
+        See L{ICalDAVResource.findCalendarCollections}.
         """
         assert depth in ("0", "1", "infinity"), "Invalid depth: %s" % (depth,)
 
@@ -275,7 +272,7 @@
             if child.isCalendarCollection():
                 callback(child, childpath)
             elif child.isCollection():
-                if depth == 'infinity': 
+                if depth == "infinity": 
                     fc = child.findCalendarCollections(depth, request, callback, privileges)
                     fc.addCallback(lambda x: reactor.callLater(0, getChild))
                     return fc
@@ -542,24 +539,116 @@
     """
     implements(ICalendarPrincipalResource)
 
-    def calendarHomeSet(self):
+    liveProperties = DAVPrincipalResource.liveProperties + (
+        (caldav_namespace, "calendar-home-set"        ),
+        (caldav_namespace, "calendar-user-address-set"),
+        (caldav_namespace, "calendar-free-busy-set"   ),
+        (caldav_namespace, "schedule-inbox-URL"       ),
+        (caldav_namespace, "schedule-outbox-URL"      ),
+    )
+
+    def readProperty(self, property, request):
+        def defer():
+            if type(property) is tuple:
+                qname = property
+                sname = "{%s}%s" % property
+            else:
+                qname = property.qname()
+                sname = property.sname()
+
+            namespace, name = qname
+
+            if namespace == caldav_namespace:
+                if name == "calendar-home-set":
+                    return caldavxml.CalendarHomeSet(
+                        *[davxml.HRef(url) for url in self.calendarHomeURLs()]
+                    )
+
+                if name == "calendar-user-address-set":
+                    return caldavxml.CalendarUserAddressSet(
+                        *[davxml.HRef(url) for url in self.calendarHomeURLs()]
+                    )
+
+                if name == "calendar-free-busy-set":
+                    return caldavxml.CalendarFreeBusySet(
+                        *[davxml.HRef(url) for url in self.calendarFreeBusyURIs()]
+                    )
+
+                if name == "schedule-inbox-URL":
+                    url = self.scheduleInboxURL()
+                    if url is None:
+                        return None
+                    else:
+                        return caldavxml.ScheduleInboxURL(davxml.HRef(url))
+
+                if name == "schedule-outbox-URL":
+                    url = self.scheduleOutboxURL()
+                    if url is None:
+                        return None
+                    else:
+                        return caldavxml.ScheduleOutboxURL(davxml.HRef(url))
+
+        return maybeDeferred(defer)
+
+    def calendarHomeURLs(self):
         """
-        @return: a list of calendar user home URLs for this principal.
+        See L{ICalendarPrincipalResource.calendarHomeURLs}.
+        This implementation raises L{NotImplementedError} if the dead property
+        C{(caldav_namespace, "calendar-home-set")} is not set.
         """
-        return self.readDeadProperty((caldav_namespace, "calendar-home-set"))
+        if self.hasDeadProperty((caldav_namespace, "calendar-home-set")):
+            home_set = self.readDeadProperty((caldav_namespace, "calendar-home-set"))
+            return [str(h) for h in home_set.children]
+        else:
+            raise NotImplementedError()
 
+    def calendarUserAddresses(self):
+        """
+        See L{ICalendarPrincipalResource.calendarUserAddresses}.
+        """
+        if self.hasDeadProperty((caldav_namespace, "calendar-user-address-set")):
+            addresses = self.readDeadProperty((caldav_namespace, "calendar-user-address-set"))
+            return [str(h) for h in addresses.children]
+        else:
+            # Must have a valid address of some kind so use the principal uri
+            return (self.principalURL(),)
+
+    @deferredGenerator
+    def calendarFreeBusyURIs(self, request):
+        """
+        See L{ICalendarPrincipalResource.calendarFreeBusyURIs}.
+        """
+        inbox = waitForDeferred(request.locateResource(self.scheduleInboxURL()))
+        yield inbox
+        inbox = inbox.getResult()
+
+        if inbox is None:
+            yield None
+            return
+        
+        has = waitForDeferred(inbox.hasProperty((caldav_namespace, "calendar-free-busy-set", request)))
+        yield has
+        has = has.getResult()
+        
+        if not has:
+            yield None
+            return
+
+        fbset = waitForDeferred(inbox.readProperty((caldav_namespace, "calendar-free-busy-set", request)))
+        yield fbset
+        fbset = fbset.getResult()
+
+        yield [str(h) for h in fbset.children]
+
     def scheduleInboxURL(self):
         """
         @return: the schedule INBOX URL for this principal.
         """
         if self.hasDeadProperty((caldav_namespace, "schedule-inbox-URL")):
             inbox = self.readDeadProperty((caldav_namespace, "schedule-inbox-URL"))
-            assert isinstance(inbox, caldavxml.ScheduleInboxURL)
-            inbox.removeWhitespaceNodes()
-            if len(inbox.children) == 1:
-                return str(inbox.children[0])
-        
-        return ""
+            return str(inbox.children[0])
+        else:
+            return None
 
     def scheduleOutboxURL(self):
         """
@@ -567,23 +656,10 @@
         """
         if self.hasDeadProperty((caldav_namespace, "schedule-outbox-URL")):
             outbox = self.readDeadProperty((caldav_namespace, "schedule-outbox-URL"))
-            assert isinstance(outbox, caldavxml.ScheduleOutboxURL)
-            outbox.removeWhitespaceNodes()
-            if len(outbox.children) == 1:
-                return str(outbox.children[0])
+            return str(outbox.children[0])        
+        else:
+            return None
         
-        return ""
-        
-    def calendarUserAddressSet(self):
-        """
-        @return: a list of calendar user addresses for this principal.
-        """
-        if self.hasDeadProperty((caldav_namespace, "calendar-user-address-set")):
-            return self.readDeadProperty((caldav_namespace, "calendar-user-address-set"))
-            
-        # Must have a valid address of some kind so use the principal uri
-        return caldavxml.CalendarUserAddressSet(davxml.HRef().fromString(self._url))
-
     def matchesCalendarUserAddress(self, request, address):
         """
         Determine whether this principal matches the supplied calendar user
@@ -604,27 +680,12 @@
             return True
 
         # Look at the property if URI lookup does not work
-        for cua in self.calendarUserAddressSet().children:
-            if str(cua) == address:
+        for cua in self.calendarUserAddresses():
+            if cua == address:
                 return True
         
         return False
 
-    def calendarFreeBusySet(self, request):
-        """
-        @return: L{Deferred} whose result is a list of calendars that contribute to free-busy for this
-            principal's calendar user.
-        """
-        def _defer(inbox):
-            if inbox and inbox.hasDeadProperty((caldav_namespace, "calendar-free-busy-set")):
-                return inbox.readDeadProperty((caldav_namespace, "calendar-free-busy-set"))
-            return caldavxml.CalendarFreeBusySet()
-
-        inbox_url = self.scheduleInboxURL()
-        d = request.locateResource(inbox_url)
-        d.addCallback(_defer)
-        return d
-
 class CalendarSchedulingCollectionResource (CalDAVResource):
     """
     CalDAV principal resource.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20061006/1a7b0656/attachment.html


More information about the calendarserver-changes mailing list