[CalendarServer-changes] [4493] CalendarServer/branches/more-deferreds-3

source_changes at macosforge.org source_changes at macosforge.org
Thu Aug 13 12:23:00 PDT 2009


Revision: 4493
          http://trac.macosforge.org/projects/calendarserver/changeset/4493
Author:   william_short at apple.com
Date:     2009-08-13 12:22:56 -0700 (Thu, 13 Aug 2009)
Log Message:
-----------
mostly works

Modified Paths:
--------------
    CalendarServer/branches/more-deferreds-3/bin/caldavd
    CalendarServer/branches/more-deferreds-3/calendarserver/tap/caldav.py
    CalendarServer/branches/more-deferreds-3/calendarserver/tools/export.py
    CalendarServer/branches/more-deferreds-3/calendarserver/tools/warmup.py
    CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.application.app.patch
    CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.mail.imap4.patch
    CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.python.util.patch
    CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.auth.digest.patch
    CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.method.report.patch
    CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.resource.patch
    CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.error.patch
    CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.server.patch
    CalendarServer/branches/more-deferreds-3/run
    CalendarServer/branches/more-deferreds-3/twistedcaldav/caldavxml.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/calendar.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/directory.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/principal.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/test/test_principal.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/extensions.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/freebusyurl.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/icaldav.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/index.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/memcacheprops.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/method/delete_common.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/method/get.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/method/propfind.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/method/put_common.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/method/report_calquery.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/method/report_common.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/resource.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/implicit.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/processing.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/scheduler.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/utils.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/static.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_collectioncontents.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_index.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_memcacheprops.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_sql.py
    CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_static.py

Added Paths:
-----------
    CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.static.patch
    CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.test.test_resource.patch
    CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.xattrprops.patch
    CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.static.patch

Modified: CalendarServer/branches/more-deferreds-3/bin/caldavd
===================================================================
--- CalendarServer/branches/more-deferreds-3/bin/caldavd	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/bin/caldavd	2009-08-13 19:22:56 UTC (rev 4493)
@@ -120,4 +120,4 @@
 
 echo exec "${python}" "${twistdpath}" "${twistd_reactor}" ${daemonize} ${username} ${groupname} "${plugin_name}" ${configfile} ${service_type} ${profile} "${child_reactor}";
 
-exec "${python}" "${twistdpath}" ${twistd_reactor} ${daemonize} ${username} ${groupname} "${plugin_name}" ${configfile} ${service_type} ${profile} ${child_reactor};
+exec "${python}" "${twistdpath}" ${twistd_reactor}  ${daemonize} ${username} ${groupname} "${plugin_name}" ${configfile} ${service_type} ${profile} ${child_reactor};

Modified: CalendarServer/branches/more-deferreds-3/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/calendarserver/tap/caldav.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/calendarserver/tap/caldav.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -597,14 +597,6 @@
             directory,
         )
 
-        self.log_info("Setting up calendar collection: %r"
-                      % (self.calendarResourceClass,))
-
-        calendarCollection = self.calendarResourceClass(
-            os.path.join(config.DocumentRoot, "calendars"),
-            directory, "/calendars/",
-        )
-
         self.log_info("Setting up root resource: %r"
                       % (self.rootResourceClass,))
 
@@ -612,10 +604,18 @@
             config.DocumentRoot,
             principalCollections=(principalCollection,),
         )
-
         root.putChild("principals", principalCollection)
-        root.putChild("calendars", calendarCollection)
 
+        d = self.calendarResourceClass.fetch(None,
+            os.path.join(config.DocumentRoot, "calendars"),
+            directory, "/calendars/")
+
+        def _installCalendars(calendarCollection):
+            self.log_info("Setting up calendar collection: %r"
+                          % (self.calendarResourceClass,))
+            root.putChild("calendars", calendarCollection)
+        d.addCallback(_installCalendars)
+
         for name, info in config.Aliases.iteritems():
             if os.path.sep in name or not info.get("path", None):
                 self.log_error("Invalid alias: %s" % (name,))

Modified: CalendarServer/branches/more-deferreds-3/calendarserver/tools/export.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/calendarserver/tools/export.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/calendarserver/tools/export.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -37,6 +37,8 @@
 from os.path import dirname, abspath
 
 from twistedcaldav.config import ConfigurationError
+from twisted.internet.defer import gatherResults
+
 from twistedcaldav.ical import Component as iComponent, Property as iProperty
 from twistedcaldav.ical import iCalendarProductID
 from twistedcaldav.resource import isCalendarCollectionResource
@@ -153,6 +155,12 @@
             sys.stdout.write("%s\n" % (e,))
             sys.exit(1)
 
+    def _gotChildren(children):
+                for childName in children:
+                    child = calendarHome.getChild(childName)
+                    if isCalendarCollectionResource(child):
+                        collections.add(child)
+
     for record in records:
         recordType, shortName = record
         calendarHome = config.directory.calendarHomeForShortName(recordType, shortName)
@@ -161,63 +169,65 @@
             sys.exit(1)
         calendarHomes.add(calendarHome)
 
-    for calendarHome in calendarHomes:
-        for childName in calendarHome.listChildren():
-            child = calendarHome.getChild(childName)
-            if isCalendarCollectionResource(child):
-                collections.add(child)
+        d = gatherResults([calendarHome.listChildren().addCallback(_gotChildren) for calendarHome in calendarHomes])
+    def _finish(_):
+        try:
+            calendar = iComponent("VCALENDAR")
+            calendar.addProperty(iProperty("VERSION", "2.0"))
+            calendar.addProperty(iProperty("PRODID", iCalendarProductID))
 
-    try:
-        calendar = iComponent("VCALENDAR")
-        calendar.addProperty(iProperty("VERSION", "2.0"))
-        calendar.addProperty(iProperty("PRODID", iCalendarProductID))
+            uids  = set()
+            tzids = set()
 
-        uids  = set()
-        tzids = set()
+            ds = []
+            for collection in collections:
+                d = collection.index().indexedSearch(None)
+                def _gotResults(results):
+                    for name, uid, type in results:
+                        child = collection.getChild(name)
+                        childData = child.iCalendarText()
 
-        for collection in collections:
-            for name, uid, type in collection.index().indexedSearch(None):
-                child = collection.getChild(name)
-                childData = child.iCalendarText()
+                        try:
+                            childCalendar = iComponent.fromString(childData)
+                        except ValueError:
+                            continue
+                        assert childCalendar.name() == "VCALENDAR"
 
-                try:
-                    childCalendar = iComponent.fromString(childData)
-                except ValueError:
-                    continue
-                assert childCalendar.name() == "VCALENDAR"
-
-                if uid in uids:
-                    sys.stderr.write("Skipping duplicate event UID %r from %s\n" % (uid, collection.fp.path))
-                    continue
-                else:
-                    uids.add(uid)
-
-                for component in childCalendar.subcomponents():
-                    # Only insert VTIMEZONEs once
-                    if component.name() == "VTIMEZONE":
-                        tzid = component.propertyValue("TZID")
-                        if tzid in tzids:
+                        if uid in uids:
+                            sys.stderr.write("Skipping duplicate event UID %r from %s\n" % (uid, collection.fp.path))
                             continue
                         else:
-                            tzids.add(tzid)
+                            uids.add(uid)
 
-                    calendar.addComponent(component)
+                        for component in childCalendar.subcomponents():
+                            # Only insert VTIMEZONEs once
+                            if component.name() == "VTIMEZONE":
+                                tzid = component.propertyValue("TZID")
+                                if tzid in tzids:
+                                    continue
+                                else:
+                                    tzids.add(tzid)
 
-        calendarData = str(calendar)
+                            calendar.addComponent(component)
+                ds.append(d)
+            def _done(_):
+                calendarData = str(calendar)
 
-        if outputFileName:
-            try:
-                output = open(outputFileName, "w")
-            except IOError, e:
-                sys.stderr.write("Unable to open output file for writing %s: %s\n" % (outputFileName, e))
-                sys.exit(1)
-        else:
-            output = sys.stdout
+                if outputFileName:
+                    try:
+                        output = open(outputFileName, "w")
+                    except IOError, e:
+                        sys.stderr.write("Unable to open output file for writing %s: %s\n" % (outputFileName, e))
+                        sys.exit(1)
+                else:
+                    output = sys.stdout
 
-        output.write(calendarData)
+                output.write(calendarData)
+            return gatherResults(ds).addCallback(_gotResults).addCallback(_done)
 
-    except UsageError, e:
-        usage(e)
+        except UsageError, e:
+            usage(e)
+    return d.addCallback(_finish)
 
 if __name__ == "__main__":
     main()

Modified: CalendarServer/branches/more-deferreds-3/calendarserver/tools/warmup.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/calendarserver/tools/warmup.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/calendarserver/tools/warmup.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -33,6 +33,8 @@
 from os.path import dirname, abspath
 
 from twistedcaldav.config import ConfigurationError
+from twisted.internet.defer import gatherResults
+
 from twistedcaldav.resource import isPseudoCalendarCollectionResource
 from twistedcaldav.static import CalDAVFile, CalendarHomeFile
 from twistedcaldav.directory.directory import DirectoryService
@@ -152,31 +154,38 @@
 
     calendarCollections = set()
 
+    def _gotChildren(children):
+        for childName in children:
+            child = calendarHome.getChild(childName)
+            if isPseudoCalendarCollectionResource(child):
+                calendarCollections.add(child)
+    ds = []
     for calendarHome in calendarHomes:
         #print calendarHome
         #sys.stdout.write("*")
         readProperties(calendarHome)
 
-        for childName in calendarHome.listChildren():
-            child = calendarHome.getChild(childName)
-            if isPseudoCalendarCollectionResource(child):
-                calendarCollections.add(child)
+        ds.append(calendarHome.listChildren().addCallback(_gotChildren))
+    d = gatherResults(ds)
 
-    for calendarCollection in calendarCollections:
-        try:
-            for name, uid, type in calendarCollection.index().indexedSearch(None):
-                child = calendarCollection.getChild(name)
+    def _finish(_):
+        for calendarCollection in calendarCollections:
+            try:
+                for name, uid, type in calendarCollection.index().indexedSearch(None):
+                    child = calendarCollection.getChild(name)
 
-                #sys.stdout.write("+")
-                childCalendar = child.iCalendarText()
+                    #sys.stdout.write("+")
+                    d = child.iCalendarText()
 
-                readProperties(child)
+                    readProperties(child)
 
-        except sqlite3.OperationalError:
-            # Outbox doesn't live on disk
-            if calendarCollection.fp.basename() != "outbox":
-                raise
+            except sqlite3.OperationalError:
+                # Outbox doesn't live on disk
+                if calendarCollection.fp.basename() != "outbox":
+                    raise
 
+    return d.addCallback(_finish)
+
 def readProperties(resource):
     #sys.stdout.write("-")
     for qname in resource.deadProperties().list():

Modified: CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.application.app.patch
===================================================================
--- CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.application.app.patch	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.application.app.patch	2009-08-13 19:22:56 UTC (rev 4493)
@@ -1,7 +1,6 @@
-Index: twisted/application/app.py
-===================================================================
---- twisted/application/app.py	(revision 26969)
-+++ twisted/application/app.py	(working copy)
+=== modified file 'twisted/application/app.py'
+--- twisted/application/app.py	2008-12-14 22:09:07 +0000
++++ twisted/application/app.py	2009-07-15 23:30:17 +0000
 @@ -241,7 +241,11 @@
          @param application: The application on which to check for an
              L{ILogObserver}.
@@ -15,25 +14,24 @@
  
          if observer is None:
              observer = self._getLogObserver()
-@@ -408,9 +412,7 @@
+@@ -408,8 +412,6 @@
          Run the application.
          """
          self.preApplication()
 -        self.application = self.createOrGetApplication()
- 
 -
+ 
          getLogObserverLegacy = getattr(self, 'getLogObserver', None)
          if getLogObserverLegacy is not None:
-             warnings.warn("Specifying a log observer with getLogObserver is "
-@@ -418,8 +420,10 @@
+@@ -418,7 +420,9 @@
                            category=DeprecationWarning)
              self.startLogging(self.getLogObserver())
          else:
 -            self.logger.start(self.application)
 +            self.logger.start(None)
- 
-+        self.application = self.createOrGetApplication()
 +
++        self.application = self.createOrGetApplication()
+ 
          self.postApplication()
          self.logger.stop()
- 
+

Modified: CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.mail.imap4.patch
===================================================================
--- CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.mail.imap4.patch	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.mail.imap4.patch	2009-08-13 19:22:56 UTC (rev 4493)
@@ -1,7 +1,6 @@
-Index: twisted/mail/imap4.py
-===================================================================
---- twisted/mail/imap4.py	(revision 26969)
-+++ twisted/mail/imap4.py	(working copy)
+=== modified file 'twisted/mail/imap4.py'
+--- twisted/mail/imap4.py	2009-03-23 11:02:59 +0000
++++ twisted/mail/imap4.py	2009-07-15 23:30:17 +0000
 @@ -333,7 +333,7 @@
  
  
@@ -20,3 +19,4 @@
  
  
  class MailboxException(IMAP4Exception): pass
+

Modified: CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.python.util.patch
===================================================================
--- CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.python.util.patch	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.python.util.patch	2009-08-13 19:22:56 UTC (rev 4493)
@@ -1,8 +1,7 @@
-Index: twisted/python/util.py
-===================================================================
---- twisted/python/util.py	(revision 26969)
-+++ twisted/python/util.py	(working copy)
-@@ -569,9 +569,29 @@
+=== modified file 'twisted/python/util.py'
+--- twisted/python/util.py	2009-03-30 13:33:33 +0000
++++ twisted/python/util.py	2009-07-15 23:30:18 +0000
+@@ -569,7 +569,27 @@
      L2.sort()
      return [e[2] for e in L2]
  
@@ -18,8 +17,8 @@
 +if sys.platform == "darwin" and hasCtypes:
 +    import pwd
 +    libc = cdll.LoadLibrary(find_library("libc"))
-     def initgroups(uid, primaryGid):
-         """
++    def initgroups(uid, primaryGid):
++        """
 +        Call initgroups with ctypes.
 +        """
 +        c_gid = c_int(primaryGid)
@@ -28,8 +27,7 @@
 +        return libc.initgroups(c_username, c_gid)
 +
 +elif pwd is None or grp is None or setgroups is None or getgroups is None:
-+    def initgroups(uid, primaryGid):
-+        """
+     def initgroups(uid, primaryGid):
+         """
          Do nothing.
- 
-         Underlying platform support require to manipulate groups is missing.
+

Modified: CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.auth.digest.patch
===================================================================
--- CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.auth.digest.patch	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.auth.digest.patch	2009-08-13 19:22:56 UTC (rev 4493)
@@ -1,7 +1,6 @@
-Index: twisted/web2/auth/digest.py
-===================================================================
---- twisted/web2/auth/digest.py	(revision 26969)
-+++ twisted/web2/auth/digest.py	(working copy)
+=== modified file 'twisted/web2/auth/digest.py'
+--- twisted/web2/auth/digest.py	2009-04-20 17:38:06 +0000
++++ twisted/web2/auth/digest.py	2009-07-15 23:30:18 +0000
 @@ -138,11 +138,15 @@
      implements(credentials.IUsernameHashedPassword,
                 IUsernameDigestHash)
@@ -19,7 +18,7 @@
  
      def checkPassword(self, password):
          response = self.fields.get('response')
-@@ -155,11 +159,23 @@
+@@ -155,10 +159,22 @@
  
          expected = calcResponse(
              calcHA1(algo, self.username, self.realm, password, nonce, cnonce),
@@ -30,7 +29,7 @@
 -        return expected == response
 +        if expected == response:
 +            return True
- 
++
 +        # IE7 sends cnonce and nc values, but auth fails if they are used.
 +        # So try again without them...
 +        # They can be omitted for backwards compatibility [RFC 2069].
@@ -41,10 +40,9 @@
 +            )
 +            if expected == response:
 +                return True
-+
+ 
      def checkHash(self, digestHash):
          response = self.fields.get('response')
-         uri = self.fields.get('uri')
 @@ -171,7 +187,7 @@
  
          expected = calcResponse(
@@ -80,3 +78,4 @@
 +                                               self.realm,
 +                                               auth,
 +                                               originalMethod))
+

Modified: CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.method.report.patch
===================================================================
--- CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.method.report.patch	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.method.report.patch	2009-08-13 19:22:56 UTC (rev 4493)
@@ -1,7 +1,6 @@
-Index: twisted/web2/dav/method/report.py
-===================================================================
---- twisted/web2/dav/method/report.py	(revision 26969)
-+++ twisted/web2/dav/method/report.py	(working copy)
+=== modified file 'twisted/web2/dav/method/report.py'
+--- twisted/web2/dav/method/report.py	2009-04-20 17:38:06 +0000
++++ twisted/web2/dav/method/report.py	2009-07-15 23:30:18 +0000
 @@ -94,8 +94,9 @@
      namespace = doc.root_element.namespace
      name = doc.root_element.name
@@ -32,3 +31,4 @@
      try:
          method = getattr(self, method_name)
          
+

Modified: CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.resource.patch
===================================================================
--- CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.resource.patch	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.resource.patch	2009-08-13 19:22:56 UTC (rev 4493)
@@ -1,7 +1,6 @@
-Index: twisted/web2/dav/resource.py
-===================================================================
---- twisted/web2/dav/resource.py	(revision 26969)
-+++ twisted/web2/dav/resource.py	(working copy)
+=== modified file 'twisted/web2/dav/resource.py'
+--- twisted/web2/dav/resource.py	2009-05-07 20:35:07 +0000
++++ twisted/web2/dav/resource.py	2009-07-15 23:30:18 +0000
 @@ -49,12 +49,14 @@
  if not hasattr(__builtin__, "frozenset"):
      import sets.ImmutableSet as frozenset
@@ -19,7 +18,56 @@
  from twisted.internet import reactor
  from twisted.web2 import responsecode
  from twisted.web2.http import HTTPError, RedirectResponse, StatusResponse
-@@ -642,41 +644,43 @@
+@@ -578,7 +580,6 @@
+ 
+         completionDeferred = Deferred()
+         basepath = request.urlForResource(self)
+-        children = list(self.listChildren())
+ 
+         def checkPrivilegesError(failure):
+             failure.trap(AccessDeniedError)
+@@ -595,7 +596,7 @@
+             d.addCallback(lambda _: child)
+             return d
+ 
+-        def gotChild(child, childpath):
++        def gotChild(child, childpath, children):
+             if child is None:
+                 callback(None, childpath + "/")
+             else:
+@@ -603,14 +604,15 @@
+                     callback(child, childpath + "/")
+                     if depth == "infinity":
+                         d = child.findChildren(depth, request, callback, privileges)
+-                        d.addCallback(lambda x: reactor.callLater(0, getChild))
++                        d.addCallback(lambda x: reactor.callLater(0, getChild, children))
+                         return d
+                 else:
+                     callback(child, childpath)
+ 
+-            reactor.callLater(0, getChild)
++            reactor.callLater(0, getChild, children)
+ 
+-        def getChild():
++        def getChild(children):
++            children = list(children)
+             try:
+                 childname = children.pop()
+             except IndexError:
+@@ -619,10 +621,10 @@
+                 childpath = joinURL(basepath, childname)
+                 d = request.locateChildResource(self, childname)
+                 d.addCallback(checkPrivileges)
+-                d.addCallbacks(gotChild, checkPrivilegesError, (childpath,))
++                d.addCallbacks(gotChild, checkPrivilegesError, (childpath, children))
+                 d.addErrback(completionDeferred.errback)
+ 
+-        getChild()
++        self.listChildren().addCallback(getChild)
+ 
+         return completionDeferred
+ 
+@@ -642,39 +644,41 @@
      # Authentication
      ##
  
@@ -49,10 +97,15 @@
 -                # "Authorization will not help" according to RFC2616
 -                #
 -                raise HTTPError(response)
- 
+-
 -            d = self.checkPrivileges(request, privileges, recurse)
 -            d.addErrback(onErrors)
 -            return d
+-
+-        d = maybeDeferred(self.authenticate, request)
+-        d.addCallback(onAuth)
+-        return d
++
 +        try:
 +            yield self.authenticate(request)
 +        except (UnauthorizedLogin, LoginFailed), e:
@@ -62,10 +115,7 @@
 +                request.remoteAddr
 +            ))
 +            raise HTTPError(response)
- 
--        d = maybeDeferred(self.authenticate, request)
--        d.addCallback(onAuth)
--        return d
++
 +        try:
 +            yield self.checkPrivileges(request, privileges, recurse)
 +        except AccessDeniedError, e:
@@ -84,12 +134,10 @@
 +            # "Authorization will not help" according to RFC2616
 +            #
 +            raise HTTPError(response)
++
  
  
-+
      def authenticate(self, request):
-         if not (
-             hasattr(request, 'portal') and 
 @@ -1880,7 +1884,7 @@
          # If this is a collection and the URI doesn't end in "/", redirect.
          #
@@ -99,3 +147,4 @@
  
          def setHeaders(response):
              response = IResponse(response)
+

Added: CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.static.patch
===================================================================
--- CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.static.patch	                        (rev 0)
+++ CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.static.patch	2009-08-13 19:22:56 UTC (rev 4493)
@@ -0,0 +1,28 @@
+=== modified file 'twisted/web2/dav/static.py'
+--- twisted/web2/dav/static.py	2009-04-20 17:38:06 +0000
++++ twisted/web2/dav/static.py	2009-07-15 23:30:18 +0000
+@@ -53,6 +53,14 @@
+ 
+     Extends twisted.web2.static.File to handle WebDAV methods.
+     """
++    @classmethod
++    def fetch(cls, request, path, *args, **kwargs):
++        """
++        stuff etc
++        """
++        return succeed(cls(path, *args, **kwargs))
++
++
+     def __init__(
+         self, path,
+         defaultType="text/plain", indexNames=None,
+@@ -192,7 +200,7 @@
+         return (self.createSimilarFile(self.fp.child(path).path), segments[1:])
+ 
+     def createSimilarFile(self, path):
+-        return self.__class__(
++        return self.__class__.fetch(None, 
+             path, defaultType=self.defaultType, indexNames=self.indexNames[:],
+             principalCollections=self.principalCollections())
+ 
+

Added: CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.test.test_resource.patch
===================================================================
--- CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.test.test_resource.patch	                        (rev 0)
+++ CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.test.test_resource.patch	2009-08-13 19:22:56 UTC (rev 4493)
@@ -0,0 +1,13 @@
+=== modified file 'twisted/web2/dav/test/test_resource.py'
+--- twisted/web2/dav/test/test_resource.py	2009-05-07 20:35:07 +0000
++++ twisted/web2/dav/test/test_resource.py	2009-07-15 23:30:18 +0000
+@@ -376,7 +376,7 @@
+         return self.children is not None
+ 
+     def listChildren(self):
+-        return self.children.keys()
++        return succeed(self.children.keys())
+ 
+     def supportedPrivileges(self, request):
+         return succeed(davPrivilegeSet)
+

Added: CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.xattrprops.patch
===================================================================
--- CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.xattrprops.patch	                        (rev 0)
+++ CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.dav.xattrprops.patch	2009-08-13 19:22:56 UTC (rev 4493)
@@ -0,0 +1,20 @@
+=== modified file 'twisted/web2/dav/xattrprops.py'
+--- twisted/web2/dav/xattrprops.py	2009-06-03 23:46:41 +0000
++++ twisted/web2/dav/xattrprops.py	2009-07-15 23:30:18 +0000
+@@ -49,6 +49,7 @@
+ 
+ from twisted.python.util import untilConcludes
+ from twisted.python.failure import Failure
++from twisted.internet.defer import succeed
+ from twisted.python import log
+ from twisted.web2 import responsecode
+ from twisted.web2.http import HTTPError, StatusResponse
+@@ -188,6 +189,7 @@
+ 
+         # Update the resource because we've modified it
+         self.resource.fp.restat()
++        return succeed(None)
+ 
+ 
+     def delete(self, qname):
+

Modified: CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.error.patch
===================================================================
--- CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.error.patch	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.error.patch	2009-08-13 19:22:56 UTC (rev 4493)
@@ -1,7 +1,6 @@
-Index: twisted/web2/error.py
-===================================================================
---- twisted/web2/error.py	(revision 26969)
-+++ twisted/web2/error.py	(working copy)
+=== modified file 'twisted/web2/error.py'
+--- twisted/web2/error.py	2005-11-22 22:59:59 +0000
++++ twisted/web2/error.py	2009-07-15 23:30:18 +0000
 @@ -92,7 +92,7 @@
              "<body><h1>%s</h1>%s</body></html>") % (
          response.code, title, title, message)
@@ -11,3 +10,4 @@
      response.stream = stream.MemoryStream(body)
      
      return response
+

Modified: CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.server.patch
===================================================================
--- CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.server.patch	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.server.patch	2009-08-13 19:22:56 UTC (rev 4493)
@@ -28,3 +28,4 @@
          # This is where CONNECT would go if we wanted it
          return None
  
+

Added: CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.static.patch
===================================================================
--- CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.static.patch	                        (rev 0)
+++ CalendarServer/branches/more-deferreds-3/lib-patches/Twisted/twisted.web2.static.patch	2009-08-13 19:22:56 UTC (rev 4493)
@@ -0,0 +1,69 @@
+=== modified file 'twisted/web2/static.py'
+--- twisted/web2/static.py	2009-04-20 17:38:06 +0000
++++ twisted/web2/static.py	2009-07-15 23:30:18 +0000
+@@ -16,7 +16,7 @@
+ 
+ # Twisted Imports
+ from twisted.python import filepath
+-from twisted.internet.defer import maybeDeferred
++from twisted.internet.defer import maybeDeferred, succeed
+ from zope.interface import implements
+ 
+ class MetaDataMixin(object):
+@@ -291,12 +291,13 @@
+         self.ignoredExts.append(ext)
+ 
+     def directoryListing(self):
+-        return dirlist.DirectoryLister(self.fp.path,
+-                                       self.listChildren(),
+-                                       self.contentTypes,
+-                                       self.contentEncodings,
+-                                       self.defaultType)
+-
++        return self.listChildren().addCallback(lambda children: dirlist.DirectoryLister(
++                self.fp.path,
++                children,
++                self.contentTypes,
++                self.contentEncodings,
++                self.defaultType))
++                                        
+     def putChild(self, name, child):
+         """
+         Register a child with the given name with this resource.
+@@ -329,7 +330,7 @@
+         children = self.putChildren.keys()
+         if self.fp.isdir():
+             children += [c for c in self.fp.listdir() if c not in children]
+-        return children
++        return succeed(children)
+ 
+     def locateChild(self, req, segments):
+         """
+@@ -387,17 +388,17 @@
+                 ifp = self.fp.childSearchPreauth(*self.indexNames)
+                 if ifp:
+                     # Render from the index file
+-                    standin = self.createSimilarFile(ifp.path)
++                    standin = self.createSimilarFile(ifp.path).render(req)
+                 else:
+                     # Render from a DirectoryLister
+-                    standin = dirlist.DirectoryLister(
+-                        self.fp.path,
+-                        self.listChildren(),
+-                        self.contentTypes,
+-                        self.contentEncodings,
+-                        self.defaultType
+-                    )
+-                return standin.render(req)
++                    return self.listChildren().addCallback(
++                         lambda children: dirlist.DirectoryLister(
++                          self.fp.path,
++                          self.listChildren(),
++                          self.contentTypes,
++                          self.contentEncodings,
++                          self.defaultType
++                         ).render(req))
+ 
+         try:
+             f = self.fp.open()
+

Modified: CalendarServer/branches/more-deferreds-3/run
===================================================================
--- CalendarServer/branches/more-deferreds-3/run	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/run	2009-08-13 19:22:56 UTC (rev 4493)
@@ -50,7 +50,7 @@
          kill="false";
       restart="false";
   plugin_name="caldav";
- service_type="Combined";
+ service_type="Single";
      read_key="";
       profile="";
       reactor="";

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/caldavxml.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/caldavxml.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/caldavxml.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -497,7 +497,7 @@
         @param timezone: the L{Component} the VTIMEZONE to use for floating/all-day.
         @return: an L{CalendarData} with the (filtered) calendar data.
         """
-        return self.elementFromCalendar(resource.iCalendarText(), timezone)
+        return resource.iCalendarText().addCallback(self.elementFromCalendar, timezone)
 
     def elementFromCalendar(self, calendar, timezone=None):
         """
@@ -526,7 +526,7 @@
         @param timezone: the L{Component} the VTIMEZONE to use for floating/all-day.
         @return: an L{CalendarData} with the (filtered) calendar data.
         """
-        return self.elementFromCalendarWithAccessRestrictions(resource.iCalendarText(), access, timezone)
+        return resource.iCalendarText().addCallback(self.elementFromCalendarWithAccessRestrictions, access, timezone)
 
     def elementFromCalendarWithAccessRestrictions(self, calendar, access, timezone=None):
         """

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/calendar.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/calendar.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/calendar.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -27,7 +27,7 @@
     "DirectoryCalendarHomeResource",
 ]
 
-from twisted.internet.defer import succeed, inlineCallbacks, returnValue
+from twisted.internet.defer import succeed, inlineCallbacks, returnValue, gatherResults
 from twisted.web2 import responsecode
 from twisted.web2.dav import davxml
 from twisted.web2.http import HTTPError
@@ -102,7 +102,7 @@
         return self.putChildren.get(name, None)
 
     def listChildren(self):
-        return self.directory.recordTypes()
+        return succeed(self.directory.recordTypes())
 
     def principalCollections(self):
         # FIXME: directory.principalCollection smells like a hack
@@ -117,7 +117,7 @@
     def homeForDirectoryRecord(self, record):
         uidResource = self.getChild(uidsResourceName)
         if uidResource is None:
-            return None
+            return succeed(None)
         else:
             return uidResource.getChild(record.uid)
 
@@ -172,10 +172,10 @@
                         for shortName in record.shortNames:
                             yield shortName
 
-            return _recordShortnameExpand()
+            return succeed(_recordShortnameExpand())
         else:
             # Not a listable collection
-            raise HTTPError(responsecode.FORBIDDEN)
+            return fail(HTTPError(responsecode.FORBIDDEN))
 
     def createSimilarFile(self, path):
         raise HTTPError(responsecode.NOT_FOUND)
@@ -227,7 +227,7 @@
 
     def listChildren(self):
         # Not a listable collection
-        raise HTTPError(responsecode.FORBIDDEN)
+        return fail(HTTPError(responsecode.FORBIDDEN))
 
     ##
     # DAV
@@ -251,6 +251,7 @@
     """
     Calendar home collection resource.
     """
+
     def __init__(self, parent, record):
         """
         @param path: the path to the file which will back the resource.
@@ -263,31 +264,13 @@
         self.record = record
         self.parent = parent
 
-        # Cache children which must be of a specific type
-        childlist = (
-            ("inbox" , ScheduleInboxResource ),
-            ("outbox", ScheduleOutboxResource),
-        )
-        if config.EnableDropBox:
-            childlist += (
-                ("dropbox", DropBoxHomeResource),
-            )
-        if config.FreeBusyURL.Enabled:
-            childlist += (
-                ("freebusy", FreeBusyURLResource),
-            )
-        for name, cls in childlist:
-            child = self.provisionChild(name)
-            assert isinstance(child, cls), "Child %r is not a %s: %r" % (name, cls.__name__, child)
-            self.putChild(name, child)
-
     def provisionDefaultCalendars(self):
 
         # Disable notifications during provisioning
         if hasattr(self, "clientNotifier"):
             self.clientNotifier.disableNotify()
 
-        def setupFreeBusy(_):
+        def setupFreeBusy(_, child):
             # Default calendar is initially opaque to freebusy
             child.writeDeadProperty(caldavxml.ScheduleCalendarTransp(caldavxml.Opaque()))
 
@@ -307,15 +290,17 @@
             return self
 
         try:
-            self.provision()
+            d = self.provision()
 
             childName = "calendar"
             childURL = joinURL(self.url(), childName)
-            child = self.provisionChild(childName)
-            assert isinstance(child, CalDAVResource), "Child %r is not a %s: %r" % (childName, CalDAVResource.__name__, child)
+            d.addCallback(lambda _: self.provisionChild(childName))
+            
+            def _makeChild(child):
+                assert isinstance(child, CalDAVResource), "Child %r is not a %s: %r" % (childName, CalDAVResource.__name__, child)
+                return child.createCalendarCollection().addCallback(setupFreeBusy, child)
 
-            d = child.createCalendarCollection()
-            d.addCallback(setupFreeBusy)
+            d.addCallback(_makeChild)
         except:
             # We want to make sure to re-enable notifications, so do so
             # if there is an immediate exception above, or via errback, below

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/directory.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/directory.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/directory.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -35,7 +35,7 @@
 from twisted.cred.error import UnauthorizedLogin
 from twisted.cred.checkers import ICredentialsChecker
 from twisted.web2.dav.auth import IPrincipalCredentials
-from twisted.internet.defer import succeed
+from twisted.internet.defer import succeed, maybeDeferred
 
 from twistedcaldav.log import LoggingMixIn
 from twistedcaldav.directory.idirectory import IDirectoryService, IDirectoryRecord
@@ -107,13 +107,16 @@
                 credentials.authzPrincipal.principalURL(),
             )
         else:
-            if credentials.authnPrincipal.record.verifyCredentials(credentials.credentials):
-                return (
-                    credentials.authnPrincipal.principalURL(),
-                    credentials.authzPrincipal.principalURL(),
-                )
-            else:
-                raise UnauthorizedLogin("Incorrect credentials for %s" % (credentials.credentials.username,)) 
+            d = maybeDeferred(credentials.authnPrincipal.record.verifyCredentials, credentials.credentials)
+            def _verify(authed):
+                if authed:
+                    return (
+                        credentials.authnPrincipal.principalURL(),
+                        credentials.authzPrincipal.principalURL(),
+                        )
+                else:
+                    raise UnauthorizedLogin("Incorrect credentials for %s" % (credentials.credentials.username,)) 
+            return d.addCallback(_verify)
 
     def recordTypes(self):
         raise NotImplementedError("Subclass must implement recordTypes()")

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/principal.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/principal.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -37,7 +37,7 @@
 from twisted.cred.credentials import UsernamePassword
 from twisted.python.failure import Failure
 from twisted.internet.defer import inlineCallbacks, returnValue
-from twisted.internet.defer import succeed
+from twisted.internet.defer import succeed, fail
 from twisted.web2.auth.digest import DigestedCredentials
 from twisted.web2 import responsecode
 from twisted.web2.http import HTTPError
@@ -348,7 +348,7 @@
             return self.putChildren.get(name, None)
 
     def listChildren(self):
-        return self.directory.recordTypes()
+        return succeed(self.directory.recordTypes())
 
     ##
     # ACL
@@ -405,10 +405,10 @@
                     for shortName in record.shortNames:
                         yield shortName
 
-            return _recordShortnameExpand()
+            return succeed(_recordShortnameExpand())
         else:
             # Not a listable collection
-            raise HTTPError(responsecode.FORBIDDEN)
+            return fail(HTTPError(responsecode.FORBIDDEN))
 
     ##
     # ACL
@@ -479,7 +479,7 @@
 
     def listChildren(self):
         # Not a listable collection
-        raise HTTPError(responsecode.FORBIDDEN)
+        return fail(HTTPError(responsecode.FORBIDDEN))
 
     ##
     # ACL
@@ -811,7 +811,7 @@
         return None
 
     def listChildren(self):
-        return ()
+        return succeed(())
 
 
 class DirectoryCalendarPrincipalResource (DirectoryPrincipalResource, CalendarPrincipalResource):
@@ -838,10 +838,13 @@
         returnValue(result)
 
     def extraDirectoryBodyItems(self, request):
-        return "".join((
-            """\nCalendar homes:\n"""          , format_list(format_link(u) for u in self.calendarHomeURLs()),
-            """\nCalendar user addresses:\n""" , format_list(format_link(a) for a in self.calendarUserAddresses()),
-        ))
+        d = self.calendarHomeURLs()
+        def _gotURLs(homeURLs):
+            return "".join((
+                    """\nCalendar homes:\n"""          , format_list(format_link(u) for u in homeURLs),
+                    """\nCalendar user addresses:\n""" , format_list(format_link(a) for a in self.calendarUserAddresses()),
+                    ))
+        return d.addCallbacks(_gotURLs)
 
     ##
     # CalDAV
@@ -877,22 +880,22 @@
             return False
 
     def scheduleInbox(self, request):
-        home = self.calendarHome()
-        if home is None:
-            return succeed(None)
+        d = self.calendarHome()
+        def _gotHome(home):
+            if home is None:
+                return None
+            return home.getChild("inbox")
 
-        inbox = home.getChild("inbox")
-        if inbox is None:
-            return succeed(None)
+        return d.addCallback(_gotHome)
 
-        return succeed(inbox)
-
     def calendarHomeURLs(self):
-        home = self.calendarHome()
-        if home is None:
-            return ()
-        else:
-            return (home.url(),)
+        d = self.calendarHome()
+        def _gotHome(home):
+            if home is None:
+                return ()
+            else:
+                return (home.url(),)
+        return d.addCallback(_gotHome)
 
     def scheduleInboxURL(self):
         return self._homeChildURL("inbox/")
@@ -907,11 +910,13 @@
             return None
 
     def _homeChildURL(self, name):
-        home = self.calendarHome()
-        if home is None:
-            return None
-        else:
-            return joinURL(home.url(), name)
+        d = self.calendarHome()
+        def _gotHome(home):
+            if home is None:
+                return None
+            else:
+                return joinURL(home.url(), name)
+        return d.addCallback(_gotHome)
 
     def calendarHome(self):
         # FIXME: self.record.service.calendarHomesCollection smells like a hack
@@ -920,7 +925,7 @@
         if hasattr(service, "calendarHomesCollection"):
             return service.calendarHomesCollection.homeForDirectoryRecord(self.record)
         else:
-            return None
+            return succeed(None)
 
 
     ##
@@ -938,10 +943,9 @@
 
     def listChildren(self):
         if config.EnableProxyPrincipals:
-            return ("calendar-proxy-read", "calendar-proxy-write")
+            return succeed(("calendar-proxy-read", "calendar-proxy-write"))
         else:
-            return ()
-
+            return succeed(())
 ##
 # Utilities
 ##

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/test/test_principal.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/test/test_principal.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/directory/test/test_principal.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -17,7 +17,7 @@
 import os
 
 from twisted.cred.credentials import UsernamePassword
-from twisted.internet.defer import inlineCallbacks
+from twisted.internet.defer import inlineCallbacks, gatherResults
 from twisted.web2.dav import davxml
 from twisted.web2.dav.fileop import rmdir
 from twisted.web2.dav.resource import AccessDeniedError
@@ -105,34 +105,39 @@
             principalCollections = provisioningResource.principalCollections()
             self.assertEquals(set((provisioningURL,)), set(pc.principalCollectionURL() for pc in principalCollections))
 
-            recordTypes = set(provisioningResource.listChildren())
-            self.assertEquals(recordTypes, set(directory.recordTypes()))
+            d = provisioningResource.listChildren()
+            def _gotProvisioningChildren(children):
+                recordTypes = set(children)
+                self.assertEquals(recordTypes, set(directory.recordTypes()))
 
-            for recordType in recordTypes:
-                #print "   -> %s" % (recordType,)
-                typeResource = provisioningResource.getChild(recordType)
-                self.failUnless(isinstance(typeResource, DirectoryPrincipalTypeProvisioningResource))
+                for recordType in recordTypes:
+                    #print "   -> %s" % (recordType,)
+                    typeResource = provisioningResource.getChild(recordType)
+                    self.failUnless(isinstance(typeResource, DirectoryPrincipalTypeProvisioningResource))
 
-                typeURL = provisioningURL + recordType + "/"
-                self.assertEquals(typeURL, typeResource.principalCollectionURL())
+                    typeURL = provisioningURL + recordType + "/"
+                    self.assertEquals(typeURL, typeResource.principalCollectionURL())
 
-                principalCollections = typeResource.principalCollections()
-                self.assertEquals(set((provisioningURL,)), set(pc.principalCollectionURL() for pc in principalCollections))
+                    principalCollections = typeResource.principalCollections()
+                    self.assertEquals(set((provisioningURL,)), set(pc.principalCollectionURL() for pc in principalCollections))
+                    d = typeResource.listChildren()
+                    def _gotTypeChildren(children):
+                        shortNames = set(children)
+                        self.assertEquals(shortNames, set(r.shortNames[0] for r in directory.listRecords(recordType)))
 
-                shortNames = set(typeResource.listChildren())
-                self.assertEquals(shortNames, set(r.shortNames[0] for r in directory.listRecords(recordType)))
+                        for shortName in shortNames:
+                            #print "     -> %s" % (shortName,)
+                            recordResource = typeResource.getChild(shortName)
+                            self.failUnless(isinstance(recordResource, DirectoryPrincipalResource))
 
-                for shortName in shortNames:
-                    #print "     -> %s" % (shortName,)
-                    recordResource = typeResource.getChild(shortName)
-                    self.failUnless(isinstance(recordResource, DirectoryPrincipalResource))
+                            recordURL = typeURL + shortName + "/"
+                            self.assertIn(recordURL, (recordResource.principalURL(),) + tuple(recordResource.alternateURIs()))
 
-                    recordURL = typeURL + shortName + "/"
-                    self.assertIn(recordURL, (recordResource.principalURL(),) + tuple(recordResource.alternateURIs()))
+                            principalCollections = recordResource.principalCollections()
+                            self.assertEquals(set((provisioningURL,)), set(pc.principalCollectionURL() for pc in principalCollections))
+                    
+            return d.addCallback(_gotProvisioningChildren)
 
-                    principalCollections = recordResource.principalCollections()
-                    self.assertEquals(set((provisioningURL,)), set(pc.principalCollectionURL() for pc in principalCollections))
-
     def test_allRecords(self):
         """
         Test of a test routine...
@@ -331,12 +336,15 @@
         DirectoryPrincipalResource.scheduleInboxURL(),
         DirectoryPrincipalResource.scheduleOutboxURL()
         """
+        ds = []
         # No calendar home provisioner should result in no calendar homes.
         for provisioningResource, recordType, recordResource, record in self._allRecords():
             if record.enabledForCalendaring:
-                self.failIf(tuple(recordResource.calendarHomeURLs()))
-                self.failIf(recordResource.scheduleInboxURL())
-                self.failIf(recordResource.scheduleOutboxURL())
+                d = recordResource.calendarHomeURLs()
+                d.addCallback(lambda u: self.assertEqual(len(u), 0))
+                ds.append(d)
+                ds.append(recordResource.scheduleInboxURL().addCallback(self.failIf))
+                ds.append(recordResource.scheduleOutboxURL().addCallback(self.failIf))
 
         # Need to create a calendar home provisioner for each service.
         calendarRootResources = {}
@@ -356,33 +364,32 @@
         # Calendar home provisioners should result in calendar homes.
         for provisioningResource, recordType, recordResource, record in self._allRecords():
             if record.enabledForCalendaring:
-                homeURLs = tuple(recordResource.calendarHomeURLs())
-                self.failUnless(homeURLs)
+                d = gatherResults([recordResource.calendarHomeURLs(),
+                                  recordResource.scheduleInboxURL(),
+                                  recordResource.scheduleOutboxURL()])
+                def _gotURLs(homeURLs, inboxURL, outboxURL):
+                    calendarRootURL = calendarRootResources[record.service.__class__.__name__].url()
 
-                calendarRootURL = calendarRootResources[record.service.__class__.__name__].url()
+                    self.failUnless(inboxURL)
+                    self.failUnless(outboxURL)
 
-                inboxURL = recordResource.scheduleInboxURL()
-                outboxURL = recordResource.scheduleOutboxURL()
+                    for homeURL in homeURLs:
+                        self.failUnless(homeURL.startswith(calendarRootURL))
 
-                self.failUnless(inboxURL)
-                self.failUnless(outboxURL)
+                        if inboxURL and inboxURL.startswith(homeURL):
+                            self.failUnless(len(inboxURL) > len(homeURL))
+                            self.failUnless(inboxURL.endswith("/"))
+                            inboxURL = None
 
-                for homeURL in homeURLs:
-                    self.failUnless(homeURL.startswith(calendarRootURL))
+                        if outboxURL and outboxURL.startswith(homeURL):
+                            self.failUnless(len(outboxURL) > len(homeURL))
+                            self.failUnless(outboxURL.endswith("/"))
+                            outboxURL = None
 
-                    if inboxURL and inboxURL.startswith(homeURL):
-                        self.failUnless(len(inboxURL) > len(homeURL))
-                        self.failUnless(inboxURL.endswith("/"))
-                        inboxURL = None
+                    self.failIf(inboxURL)
+                    self.failIf(outboxURL)
+        return gatherResults(ds)
 
-                    if outboxURL and outboxURL.startswith(homeURL):
-                        self.failUnless(len(outboxURL) > len(homeURL))
-                        self.failUnless(outboxURL.endswith("/"))
-                        outboxURL = None
-
-                self.failIf(inboxURL)
-                self.failIf(outboxURL)
-
     @inlineCallbacks
     def test_defaultAccessControlList_principals(self):
         """
@@ -403,8 +410,8 @@
 
             for args in _authReadOnlyPrivileges(self, provisioningResource, provisioningResource.principalCollectionURL()):
                 yield self._checkPrivileges(*args)
-
-            for recordType in provisioningResource.listChildren():
+            children = yield provisioningResource.listChildren()
+            for recordType in children:
                 #print "   -> %s" % (recordType,)
                 typeResource = provisioningResource.getChild(recordType)
 

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/extensions.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/extensions.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/extensions.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -529,7 +529,7 @@
 
         children = []
         basepath = request.urlForResource(self)
-        childnames = list(self.listChildren())
+        childnames = yield self.listChildren()
         for childname in childnames:
             if names and childname not in names:
                 continue
@@ -880,37 +880,39 @@
         ]
 
         even = Alternator()
-        for name in sorted(self.listChildren()):
-            child = self.getChild(name)
+        d = self.listChildren()
+        def _gotChildren(children):
+            for name in sorted(children):
+                child = self.getChild(name)
 
-            url, name, size, lastModified, contentType = self.getChildDirectoryEntry(child, name)
+                url, name, size, lastModified, contentType = self.getChildDirectoryEntry(child, name)
 
-            # FIXME: gray out resources that are not readable
+                # FIXME: gray out resources that are not readable
+                output.append(
+                    """<tr class="%(even)s">"""
+                    """<td><a href="%(url)s">%(name)s</a></td>"""
+                    """<td align="right">%(size)s</td>"""
+                    """<td>%(lastModified)s</td>"""
+                    """<td>%(type)s</td>"""
+                    """</tr>"""
+                    % {
+                        "even": even.state() and "even" or "odd",
+                        "url": url,
+                        "name": cgi.escape(name),
+                        "size": size,
+                        "lastModified": lastModified,
+                        "type": contentType,
+                    }
+                )
+
             output.append(
-                """<tr class="%(even)s">"""
-                """<td><a href="%(url)s">%(name)s</a></td>"""
-                """<td align="right">%(size)s</td>"""
-                """<td>%(lastModified)s</td>"""
-                """<td>%(type)s</td>"""
-                """</tr>"""
-                % {
-                    "even": even.state() and "even" or "odd",
-                    "url": url,
-                    "name": cgi.escape(name),
-                    "size": size,
-                    "lastModified": lastModified,
-                    "type": contentType,
-                }
+                """</table></div>"""
+                """<div class="directory-listing">"""
+                """<h1>Properties</h1>"""
+                """<table>"""
+                """<tr><th>Name</th> <th>Value</th></tr>"""
             )
 
-        output.append(
-            """</table></div>"""
-            """<div class="directory-listing">"""
-            """<h1>Properties</h1>"""
-            """<table>"""
-            """<tr><th>Name</th> <th>Value</th></tr>"""
-        )
-
         def gotProperties(qnames):
             ds = []
 
@@ -986,9 +988,10 @@
             d = DeferredList(ds)
             d.addCallback(gotValues)
             return d
-
-        d = self.listProperties(request)
-        d.addCallback(gotProperties)
+        d.addCallback(
+            _gotChildren).addCallback(
+            lambda _: self.listProperties(request)).addCallback(
+            gotProperties)
         return d
 
     def getChildDirectoryEntry(self, child, name):
@@ -1116,6 +1119,7 @@
         cache[property.qname()] = None
         self.propertyStore.set(property)
         cache[property.qname()] = property
+        return succeed(None)
 
     def contains(self, qname):
         #self.log_debug("Contains: %r, %r" % (self.resource.fp.path, qname))
@@ -1155,3 +1159,6 @@
             )
         return self._data
 
+
+    def flushCache(self):
+        del self._data

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/freebusyurl.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/freebusyurl.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/freebusyurl.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -211,7 +211,7 @@
                 break
 
         # Get inbox details
-        inboxURL = principal.scheduleInboxURL()
+        inboxURL = yield principal.scheduleInboxURL(request)
         if inboxURL is None:
             raise HTTPError(StatusResponse(responsecode.INTERNAL_SERVER_ERROR, "No schedule inbox URL for principal: %s" % (principal,)))
         try:

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/icaldav.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/icaldav.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/icaldav.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -135,14 +135,14 @@
             free-busy for this principal's calendar user.
         """
 
-    def scheduleInboxURL():
+    def scheduleInboxURL(request=None):
         """
         Get the schedule INBOX URL for this principal's calendar user.
-        @return: a string containing the URL from the schedule-inbox-URL property.
+        @return: a Deferred that fires with a string containing the URL from the schedule-inbox-URL property.
         """
 
-    def scheduleOutboxURL():
+    def scheduleOutboxURL(request=None):
         """
         Get the schedule OUTBOX URL for this principal's calendar user.
-        @return: a string containing the URL from the schedule-outbox-URL property.
+        @return: a Deferred that fires with string containing the URL from the schedule-outbox-URL property.
         """

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/index.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/index.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/index.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -42,7 +42,7 @@
 
 from vobject.icalendar import utc
 
-from twisted.internet.defer import maybeDeferred, succeed
+from twisted.internet.defer import maybeDeferred, succeed, returnValue
 
 from twistedcaldav.ical import Component
 from twistedcaldav.query import calendarquery
@@ -199,7 +199,7 @@
             assert result is None, "More than one resource with UID %s in calendar collection %r" % (uid, self)
             result = name
 
-        return result
+        return succeed(result)
 
     def resourceUIDForName(self, name):
         """
@@ -321,15 +321,16 @@
                 rowiter = self._db_execute("select DISTINCT RESOURCE.NAME, RESOURCE.UID, RESOURCE.TYPE" + qualifiers[0], *qualifiers[1])
 
         # Check result for missing resources
-
+        rows = []
         for row in rowiter:
             name = row[0]
             if self.resource.getChild(name.encode("utf-8")):
-                yield row
+                rows.append(row)
             else:
                 log.err("Calendar resource %s is missing from %s. Removing from index."
                         % (name, self.resource))
                 self.deleteResource(name)
+        return succeed(rows)
 
     def bruteForceSearch(self):
         """
@@ -340,17 +341,17 @@
         rowiter = self._db_execute("select NAME, UID, TYPE from RESOURCE")
 
         # Check result for missing resources:
-
+        rows = []
         for row in rowiter:
             name = row[0]
             if self.resource.getChild(name.encode("utf-8")):
-                yield row
+                rows.append(row)
             else:
                 log.err("Calendar resource %s is missing from %s. Removing from index."
                         % (name, self.resource))
                 self.deleteResource(name)
+        return succeed(rows)
 
-
     def _db_version(self):
         """
         @return: the schema version assigned to this index.
@@ -484,10 +485,12 @@
         Given a resource name, remove it from the database and re-add it
         with a longer expansion.
         """
-        calendar = self.resource.getChild(name).iCalendar()
-        self._add_to_db(name, calendar, expand_until=expand_until, reCreate=True)
-        self._db_commit()
-
+        d = self.resource.getChild(name).iCalendar()
+        def _gotCalendar(calendar):
+            self._add_to_db(name, calendar, expand_until=expand_until, reCreate=True)
+            self._db_commit()
+        return d.addCallback(_gotCalendar)
+        
     def _add_to_db(self, name, calendar, cursor = None, expand_until=None, reCreate=False):
         """
         Records the given calendar resource in the index with the given name.
@@ -775,8 +778,8 @@
         @return: True if the UID is not in the index and is not reserved,
             False otherwise.
         """
-        rname = self.resourceNameForUID(uid)
-        return (rname is None or rname in names)
+        return self.resourceNameForUID(uid).addCallback(
+            lambda rname: rname is None or rname in names)
 
     def _db_type(self):
         """
@@ -887,7 +890,7 @@
         """
 
         # iTIP does not require unique UIDs
-        return True
+        return succeed(True)
 
     def _db_type(self):
         """

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/memcacheprops.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/memcacheprops.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/memcacheprops.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -182,23 +182,25 @@
         self.log_debug("Building cache for %s" % (self.collection,))
 
         cache = {}
-
+        ds = []
         for childName in childNames:
-            child = self.collection.getChild(childName)
-            if child is None:
-                continue
+            d = self.collection.getChild(childName)
+            def _gotChild(child):
+                if child is not None:
+                    propertyStore = child.deadProperties()
+                    props = {}
+                    for qname in propertyStore.list(cache=False):
+                        props[qname] = propertyStore.get(qname, cache=False)
 
-            propertyStore = child.deadProperties()
-            props = {}
-            for qname in propertyStore.list(cache=False):
-                props[qname] = propertyStore.get(qname, cache=False)
+                    cache[child.fp.path] = props
+            d.addCallback(_gotChild)
+            ds.append(d)
+        def _collectedChildren(_):
+            self._storeCache(cache)
+            return cache
+        return DeferredList(ds).addCallback(_collectedChildren)
 
-            cache[child.fp.path] = props
 
-        self._storeCache(cache)
-
-        return cache
-
     def setProperty(self, child, property, delete=False):
         propertyCache, key, childCache, token = self.childCache(child)
 

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/method/delete_common.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/method/delete_common.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/method/delete_common.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -143,7 +143,7 @@
         lock = None
         if not self.internal_request:
             # Get data we need for implicit scheduling
-            calendar = delresource.iCalendar()
+            calendar = yield delresource.iCalendar()
             scheduler = ImplicitScheduler()
             do_implicit_action, _ignore = (yield scheduler.testImplicitSchedulingDELETE(self.request, delresource, calendar))
             if do_implicit_action:
@@ -205,8 +205,9 @@
 
         errors = ResponseQueue(deluri, "DELETE", responsecode.NO_CONTENT)
 
-        for childname in delresource.listChildren():
+        children = yield delresource.listChildren()
 
+        for childname in children:
             childurl = joinURL(deluri, childname)
             child = (yield self.request.locateChildResource(delresource, childname))
 

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/method/get.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/method/get.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/method/get.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -20,7 +20,7 @@
 
 __all__ = ["http_GET"]
 
-from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.internet.defer import inlineCallbacks, returnValue, succeed
 from twisted.web2.dav import davxml
 from twisted.web2.http import HTTPError
 from twisted.web2.http import Response

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/method/propfind.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/method/propfind.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/method/propfind.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -24,11 +24,10 @@
 """
 WebDAV PROPFIND method
 """
-
 __all__ = ["http_PROPFIND"]
 
 from twisted.python.failure import Failure
-from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.internet.defer import inlineCallbacks, returnValue, succeed
 from twisted.web2.http import HTTPError
 from twisted.web2 import responsecode
 from twisted.web2.http import StatusResponse

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/method/put_common.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/method/put_common.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/method/put_common.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -116,7 +116,7 @@
                         self.destination_created = False
                     if self.destination_index_deleted:
                         # Must read in calendar for destination being re-indexed
-                        self.storer.doDestinationIndex(self.storer.destination.iCalendar())
+                        self.storer.destination.iCalendar().addCallback(self.storer.doDestinationIndex)
                         self.destination_index_deleted = False
                         log.debug("Rollback: destination re-indexed %s" % (self.storer.destination.fp.path,))
                     if self.source_index_deleted:
@@ -313,7 +313,7 @@
                         raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "supported-calendar-data")))
                 
                     # At this point we need the calendar data to do more tests
-                    self.calendar = self.source.iCalendar()
+                    self.calendar = yield self.source.iCalendar()
                 else:
                     try:
                         if type(self.calendar) in (types.StringType, types.UnicodeType,):
@@ -357,7 +357,7 @@
 
                 # FIXME: We need this here because we have to re-index the destination. Ideally it
                 # would be better to copy the index entries from the source and add to the destination.
-                self.calendar = self.source.iCalendar()
+                self.calendar = yield self.source.iCalendar()
 
             # Check access
             if self.destinationcal and config.EnablePrivateEvents:
@@ -368,7 +368,7 @@
 
         elif self.sourcecal:
             self.source_index = self.sourceparent.index()
-            self.calendar = self.source.iCalendar()
+            self.calendar = yield self.source.iCalendar()
     
     @inlineCallbacks
     def validCopyMoveOperation(self):
@@ -573,6 +573,7 @@
                 
         return succeed(None)
 
+    @inlineCallbacks
     def noUIDConflict(self, uid):
         """
         Check that the UID of the new calendar object conforms to the requirements of
@@ -595,7 +596,7 @@
         # UID must be unique
         index = self.destinationparent.index()
         if not index.isAllowedUID(uid, oldname, self.destination.fp.basename()):
-            rname = index.resourceNameForUID(uid)
+            rname = yield index.resourceNameForUID(uid)
             # This can happen if two simultaneous PUTs occur with the same UID.
             # i.e. one PUT has reserved the UID but has not yet written the resource,
             # the other PUT tries to reserve and fails but no index entry exists yet.
@@ -613,7 +614,7 @@
                     result = False
                     message = "Cannot overwrite calendar resource %s with different UID %s" % (rname, olduid)
         
-        return result, message, rname
+        returnValue((result, message, rname))
 
     @inlineCallbacks
     def checkQuota(self):
@@ -702,11 +703,9 @@
             if old_has_private_comments and not new_has_private_comments:
                 # Transfer old comments to new calendar
                 log.debug("Private Comments properties were entirely removed by the client. Restoring existing properties.")
-                old_calendar = self.destination.iCalendar()
-                self.calendar.transferProperties(old_calendar, (
-                    "X-CALENDARSERVER-PRIVATE-COMMENT",
-                    "X-CALENDARSERVER-ATTENDEE-COMMENT",
-                ))
+                self.destination.iCalendar().addCallback(self.calendar.transferProperties,
+                                                         "X-CALENDARSERVER-PRIVATE-COMMENT",
+                                                         "X-CALENDARSERVER-ATTENDEE-COMMENT")
                 self.calendardata = None
         
         return new_has_private_comments
@@ -948,7 +947,7 @@
                 # UID conflict check - note we do this after reserving the UID to avoid a race condition where two requests
                 # try to write the same calendar data to two different resource URIs.
                 if not self.isiTIP:
-                    result, message, rname = self.noUIDConflict(self.uid)
+                    result, message, rname = yield self.noUIDConflict(self.uid)
                     if not result:
                         log.err(message)
                         raise HTTPError(ErrorResponse(responsecode.FORBIDDEN,

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/method/report_calquery.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/method/report_calquery.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/method/report_calquery.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -173,11 +173,13 @@
                 try:
                     # Get list of children that match the search and have read
                     # access
+                    results = yield calresource.index().indexedSearch(filter)
                     names = [name for name, ignore_uid, ignore_type
-                        in calresource.index().indexedSearch(filter)]
+                        in results]
                 except IndexedSearchException:
+                    results = yield calresource.index().bruteForceSearch()
                     names = [name for name, ignore_uid, ignore_type
-                        in calresource.index().bruteForceSearch()]
+                        in results]
                     index_query_ok = False
 
                 if not names:
@@ -200,7 +202,7 @@
                     child_path_name = urllib.unquote(child_uri_name)
                     
                     if generate_calendar_data or not index_query_ok:
-                        calendar = calresource.iCalendar(child_path_name)
+                        calendar = yield calresource.iCalendar(child_path_name)
                         assert calendar is not None, "Calendar %s is missing from calendar collection %r" % (child_uri_name, self)
                     else:
                         calendar = None
@@ -224,7 +226,7 @@
             # Check private events access status
             isowner = (yield calresource.isOwner(request, adminprincipals=True, readprincipals=True))
 
-            calendar = calresource.iCalendar()
+            calendar = yield calresource.iCalendar()
             yield queryCalendarObjectResource(calresource, uri, None, calendar, timezone)
 
         returnValue(True)

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/method/report_common.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/method/report_common.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/method/report_common.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -253,9 +253,9 @@
                 access = None
 
             if calendar:
-                propvalue = property.elementFromCalendarWithAccessRestrictions(calendar, access, timezone)
+                propvalue = yield property.elementFromCalendarWithAccessRestrictions(calendar, access, timezone)
             else:
-                propvalue = property.elementFromResourceWithAccessRestrictions(resource, access, timezone)
+                propvalue = yield property.elementFromResourceWithAccessRestrictions(resource, access, timezone)
             if propvalue is None:
                 raise ValueError("Invalid CalDAV:calendar-data for request: %r" % (property,))
             properties_by_status[responsecode.OK].append(propvalue)
@@ -352,9 +352,9 @@
     filteredaces = (yield calresource.inheritedACEsforChildren(request))
 
     try:
-        resources = calresource.index().indexedSearch(filter, fbtype=True)
+        resources = yield calresource.index().indexedSearch(filter, fbtype=True)
     except IndexedSearchException:
-        resources = calresource.index().bruteForceSearch()
+        resources = yield calresource.index().bruteForceSearch()
 
     # We care about separate instances for VEVENTs only
     aggregated_resources = {}
@@ -367,7 +367,6 @@
 
         # Check privileges - must have at least CalDAV:read-free-busy
         child = (yield request.locateChildResource(calresource, name))
-
         # TODO: for server-to-server we bypass this right now as we have no way to authorize external users.
         if not servertoserver:
             try:
@@ -418,7 +417,7 @@
                     fbinfo[fbtype_index_mapper.get(fbtype, 0)].append(clipped)
                 
         else:
-            calendar = calresource.iCalendar(name)
+            calendar = yield ncalresource.iCalendar(name)
             
             # The calendar may come back as None if the resource is being changed, or was deleted
             # between our initial index query and getting here. For now we will ignore this error, but in

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/resource.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/resource.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/resource.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -316,7 +316,7 @@
             principal = (yield self.ownerPrincipal(request))
             
             # Map owner to their inbox
-            inboxURL = principal.scheduleInboxURL()
+            inboxURL = yield principal.scheduleInboxURL()
             if inboxURL:
                 inbox = (yield request.locateResource(inboxURL))
                 myurl = (yield self.canonicalURL(request))
@@ -501,18 +501,18 @@
             ca.addCallback(lambda ign: child)
             return ca
 
-        def gotChild(child, childpath):
+        def gotChild(child, childpath, children):
             if child.isCalendarCollection():
                 callback(child, childpath)
             elif child.isCollection():
                 if depth == "infinity":
                     fc = child.findCalendarCollections(depth, request, callback, privileges)
-                    fc.addCallback(lambda x: reactor.callLater(0, getChild))
+                    fc.addCallback(lambda x: reactor.callLater(0, getChild, children))
                     return fc
 
-            reactor.callLater(0, getChild)
+            reactor.callLater(0, getChild, children)
 
-        def getChild():
+        def getChild(children):
             try:
                 childname = children.pop()
             except IndexError:
@@ -521,15 +521,14 @@
                 childpath = joinURL(basepath, childname)
                 child = request.locateResource(childpath)
                 child.addCallback(checkPrivileges)
-                child.addCallbacks(gotChild, checkPrivilegesError, (childpath,))
+                child.addCallbacks(gotChild, checkPrivilegesError, (childpath, children))
                 child.addErrback(completionDeferred.errback)
 
         completionDeferred = Deferred()
 
         if depth != "0" and self.isCollection():
             basepath = request.urlForResource(self)
-            children = self.listChildren()
-            getChild()
+            self.listChildren().addCallback(getChild)
         else:
             completionDeferred.callback(None)
 
@@ -554,7 +553,7 @@
         
         # For backwards compatibility we need to sync this up with the calendar-free-busy-set on the inbox
         principal = (yield self.ownerPrincipal(request))
-        inboxURL = principal.scheduleInboxURL()
+        inboxURL = yield principal.scheduleInboxURL()
         if inboxURL:
             inbox = (yield request.locateResource(inboxURL))
             inbox.processFreeBusyCalendar(request.path, False)
@@ -567,7 +566,7 @@
         
         # For backwards compatibility we need to sync this up with the calendar-free-busy-set on the inbox
         principal = (yield self.ownerPrincipal(request))
-        inboxURL = principal.scheduleInboxURL()
+        inboxURL = yield principal.scheduleInboxURL()
         if inboxURL:
             (_ignore_scheme, _ignore_host, destination_path, _ignore_query, _ignore_fragment) = urlsplit(normalizeURL(destination_uri))
 
@@ -596,7 +595,7 @@
         
         # Not allowed to delete the default calendar
         principal = (yield self.ownerPrincipal(request))
-        inboxURL = principal.scheduleInboxURL()
+        inboxURL = yield principal.scheduleInboxURL()
         if inboxURL:
             inbox = (yield request.locateResource(inboxURL))
             default = (yield inbox.readProperty((caldav_namespace, "schedule-default-calendar-URL"), request))
@@ -618,14 +617,18 @@
         an infinite loop.  A subclass must override one of both of these
         methods.
         """
-        calendar_data = self.iCalendarText(name)
+        d = self.iCalendarText(name)
+        def _gotData(calendar_data):
+            if calendar_data is None:
+                return None
 
-        if calendar_data is None: return None
+            try:
+                return iComponent.fromString(calendar_data)
+            except ValueError:
+                return None
 
-        try:
-            return iComponent.fromString(calendar_data)
-        except ValueError:
-            return None
+        d.addCallback(_gotData)
+        return d
 
     def iCalendarRolledup(self, request):
         """
@@ -648,7 +651,7 @@
         an infinite loop.  A subclass must override one of both of these
         methods.
         """
-        return str(self.iCalendar(name))
+        return self.iCalendar(name).addCallback(str)
 
     def iCalendarXML(self, name=None):
         """
@@ -656,7 +659,7 @@
         This implementation returns an XML element constructed from the object
         returned by L{iCalendar} when given the same arguments.
         """
-        return caldavxml.CalendarData.fromCalendar(self.iCalendar(name))
+        return self.iCalendar(name).addCallback(caldavxml.CalendarData.fromCalendar)
 
     def iCalendarAddressDoNormalization(self, ical):
         """
@@ -855,8 +858,9 @@
 
         if namespace == caldav_namespace:
             if name == "calendar-home-set":
+                urls = yield self.calendarHomeURLs()
                 returnValue(caldavxml.CalendarHomeSet(
-                    *[davxml.HRef(url) for url in self.calendarHomeURLs()]
+                    *[davxml.HRef(url) for url in urls]
                 ))
 
             elif name == "calendar-user-address-set":
@@ -865,14 +869,14 @@
                 ))
 
             elif name == "schedule-inbox-URL":
-                url = self.scheduleInboxURL()
+                url = yield self.scheduleInboxURL()
                 if url is None:
                     returnValue(None)
                 else:
                     returnValue(caldavxml.ScheduleInboxURL(davxml.HRef(url)))
 
             elif name == "schedule-outbox-URL":
-                url = self.scheduleOutboxURL()
+                url = yield self.scheduleOutboxURL()
                 if url is None:
                     returnValue(None)
                 else:
@@ -961,14 +965,14 @@
         """
         @return: the deferred schedule inbox for this principal.
         """
-        return request.locateResource(self.scheduleInboxURL())
+        return self.scheduleInboxURL().addCallback(request.locateResource)
 
     def scheduleInboxURL(self):
         if self.hasDeadProperty((caldav_namespace, "schedule-inbox-URL")):
             inbox = self.readDeadProperty((caldav_namespace, "schedule-inbox-URL"))
-            return str(inbox.children[0])
+            return succeed(str(inbox.children[0]))
         else:
-            return None
+            return succeed(None)
 
     def scheduleOutboxURL(self):
         """
@@ -976,9 +980,9 @@
         """
         if self.hasDeadProperty((caldav_namespace, "schedule-outbox-URL")):
             outbox = self.readDeadProperty((caldav_namespace, "schedule-outbox-URL"))
-            return str(outbox.children[0])
+            return succeed(str(outbox.children[0]))
         else:
-            return None
+            return succeed(None)
 
     def dropboxURL(self):
         """
@@ -986,9 +990,9 @@
         """
         if self.hasDeadProperty((calendarserver_namespace, "dropbox-home-URL")):
             inbox = self.readDeadProperty((caldav_namespace, "dropbox-home-URL"))
-            return str(inbox.children[0])
+            return succeed(str(inbox.children[0]))
         else:
-            return None
+            return succeed(None)
 
     ##
     # Quota

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/implicit.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/implicit.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/implicit.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -69,7 +69,8 @@
         self.internal_request = internal_request
 
         existing_resource = resource.exists()
-        existing_type = "schedule" if self.checkSchedulingObjectResource(resource) else "calendar"
+        schedulingObject = yield self.checkSchedulingObjectResource(resource)
+        existing_type = "schedule" if schedulingObject else "calendar"
         new_type = "schedule" if (yield self.checkImplicitState()) else "calendar"
 
         if existing_type == "calendar":
@@ -86,7 +87,7 @@
             # Also make sure that we return the new calendar being written rather than the old one
             # when the implicit action is executed
             self.return_calendar = calendar
-            self.calendar = resource.iCalendar()
+            self.calendar = yield resource.iCalendar()
             yield self.checkImplicitState()
         
         # Attendees are not allowed to overwrite one type with another
@@ -106,8 +107,9 @@
         new_type = "schedule" if (yield self.checkImplicitState()) else "calendar"
 
         dest_exists = destresource.exists()
-        dest_is_implicit = self.checkSchedulingObjectResource(destresource)
-        src_is_implicit = self.checkSchedulingObjectResource(srcresource) or new_type == "schedule"
+        dest_is_implicit = yield self.checkSchedulingObjectResource(destresource)
+        src_is_implicit = yield self.checkSchedulingObjectResource(srcresource)
+        src_is_implicit = src_is_implicit or new_type == "schedule"
 
         if srccal and destcal:
             if src_is_implicit and dest_exists or dest_is_implicit:
@@ -136,8 +138,9 @@
 
         new_type = "schedule" if (yield self.checkImplicitState()) else "calendar"
 
-        dest_is_implicit = self.checkSchedulingObjectResource(destresource)
-        src_is_implicit = self.checkSchedulingObjectResource(srcresource) or new_type == "schedule"
+        dest_is_implicit = yield self.checkSchedulingObjectResource(destresource)
+        src_is_implicit = yield self.checkSchedulingObjectResource(srcresource)
+        src_is_implicit = src_is_implicit or new_type == "schedule"
 
         if srccal and destcal:
             if src_is_implicit or dest_is_implicit:
@@ -165,11 +168,13 @@
 
         yield self.checkImplicitState()
 
-        resource_type = "schedule" if self.checkSchedulingObjectResource(resource) else "calendar"
+        schedulingObject = yield self.checkSchedulingObjectResource(resource)
+        resource_type = "schedule" if schedulingObject else "calendar"
         self.action = "remove" if resource_type == "schedule" else "none"
 
         returnValue((self.action != "none", False,))
 
+    @inlineCallbacks
     def checkSchedulingObjectResource(self, resource):
         
         if resource and resource.exists():
@@ -178,24 +183,24 @@
             except HTTPError:
                 implicit = None
             if implicit is not None:
-                return implicit != "false"
+                returnValue(implicit != "false")
             else:
-                calendar = resource.iCalendar()
+                calendar = yield resource.iCalendar()
                 # Get the ORGANIZER and verify it is the same for all components
                 try:
                     organizer = calendar.validOrganizerForScheduling()
                 except ValueError:
                     # We have different ORGANIZERs in the same iCalendar object - this is an error
-                    return False
+                    returnValue(False)
                 organizerPrincipal = resource.principalForCalendarUserAddress(organizer) if organizer else None
                 resource.writeDeadProperty(TwistedSchedulingObjectResource("true" if organizerPrincipal != None else "false"))
                 log.debug("Implicit - checked scheduling object resource state for UID: '%s', result: %s" % (
                     calendar.resourceUID(),
                     "true" if organizerPrincipal != None else "false",
                 ))
-                return organizerPrincipal != None
+                returnValue(organizerPrincipal != None)
 
-        return False
+        returnValue(False)
         
     @inlineCallbacks
     def checkImplicitState(self):
@@ -367,7 +372,7 @@
 
         # Get owner's calendar-home
         calendar_owner_principal = (yield self.resource.ownerPrincipal(self.request))
-        calendar_home = calendar_owner_principal.calendarHome()
+        calendar_home = yield calendar_owner_principal.calendarHome()
         
         check_parent_uri = parentForURL(check_uri)[:-1] if check_uri else None
 
@@ -379,12 +384,13 @@
 
         @inlineCallbacks
         def queryCalendarCollection(collection, collection_uri):
-            rname = collection.index().resourceNameForUID(self.uid)
+            rname = yield collection.index().resourceNameForUID(self.uid)
             if rname:
                 child = (yield self.request.locateResource(joinURL(collection_uri, rname)))
                 if child == check_resource:
                     returnValue(True)
-                matched_type = "schedule" if self.checkSchedulingObjectResource(child) else "calendar"
+                schedulingObject = yield self.checkSchedulingObjectResource(child)
+                matched_type = "schedule" if schedulingObject else "calendar"
                 if (
                     collection_uri != check_parent_uri and
                     (type == "schedule" or matched_type == "schedule")
@@ -452,7 +458,7 @@
         """
         
         # Find outbox
-        outboxURL = principal.scheduleOutboxURL()
+        outboxURL = yield principal.scheduleOutboxURL()
         outbox = (yield self.request.locateResource(outboxURL))
         yield outbox.authorize(self.request, (caldavxml.ScheduleSend(),))
 
@@ -481,7 +487,7 @@
         elif self.action == "modify":
 
             # Read in existing data
-            self.oldcalendar = self.resource.iCalendar()
+            self.oldcalendar = yield self.resource.iCalendar()
             
             # Significant change
             no_change, self.changed_rids, reinvites, recurrence_reschedule = self.isOrganizerChangeInsignificant()
@@ -827,7 +833,7 @@
         self.organizer_calendar = None
         calendar_resource, _ignore_name, _ignore_collection, _ignore_uri = (yield getCalendarObjectForPrincipals(self.request, self.organizerPrincipal, self.uid))
         if calendar_resource:
-            self.organizer_calendar = calendar_resource.iCalendar()
+            self.organizer_calendar = yield calendar_resource.iCalendar()
         
     def isAttendeeChangeInsignificant(self):
         """

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/processing.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/processing.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/processing.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -687,7 +687,7 @@
         calendar_resource, _ignore_name, _ignore_collection, _ignore_uri = (yield getCalendarObjectForPrincipals(self.request, self.originator.principal, self.uid))
         if not calendar_resource:
             raise ImplicitProcessorException("5.1;Service unavailable")
-        originator_calendar = calendar_resource.iCalendar()
+        originator_calendar = yield calendar_resource.iCalendar()
 
         # Get attendee's view of that
         originator_calendar.attendeesView((self.recipient.cuaddr,))

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/scheduler.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/scheduler.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/scheduler.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -15,9 +15,8 @@
 ##
 
 from twext.web2.dav.davxml import ErrorResponse
+from twisted.internet.defer import inlineCallbacks, returnValue, fail, succeed
 
-from twisted.internet.defer import inlineCallbacks, returnValue
-
 from twisted.python.failure import Failure
 
 from twisted.web2 import responsecode
@@ -488,7 +487,7 @@
             else:
                 # Map recipient to their inbox
                 inbox = None
-                inboxURL = principal.scheduleInboxURL()
+                inboxURL = yield principal.scheduleInboxURL()
                 if inboxURL:
                     inbox = (yield self.request.locateResource(inboxURL))
 
@@ -509,7 +508,7 @@
         # Verify that the ORGANIZER's cu address maps to a valid user
         organizer = self.calendar.getOrganizer()
         if organizer:
-            organizerPrincipal = self.resource.principalForCalendarUserAddress(organizer)
+            organizerPrincipal = yield self.resource.principalForCalendarUserAddress(organizer)
             if organizerPrincipal:
                 outboxURL = organizerPrincipal.scheduleOutboxURL()
                 if outboxURL:
@@ -533,16 +532,20 @@
             raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "organizer-allowed")))
 
     def checkOrganizerAsOriginator(self):
-
+        def _checkoutboxurl(outboxuri):
+            if outboxuri != self.request.uri:
+                log.err("Wrong outbox for ORGANIZER in calendar data: %s" % (self.calendar,))
+                raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "organizer-allowed")))
+            return outboxuri
+                
         # Make sure that the ORGANIZER is local
         if not isinstance(self.organizer, LocalCalendarUser):
             log.err("ORGANIZER is not local to server in calendar data: %s" % (self.calendar,))
             raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "organizer-allowed")))
 
         # Make sure that the ORGANIZER's Outbox is the request URI
-        if self.doingPOST and self.organizer.principal.scheduleOutboxURL() != self.request.uri:
-            log.err("Wrong outbox for ORGANIZER in calendar data: %s" % (self.calendar,))
-            raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "organizer-allowed")))
+        if self.doingPOST:
+            return self.organizer.principal.scheduleOutboxURL().addCallback(_checkoutboxurl) 
 
     def checkAttendeeAsOriginator(self):
         """
@@ -556,19 +559,23 @@
         # Must have only one
         if len(attendees) != 1:
             log.err("Wrong number of ATTENDEEs in calendar data: %s" % (self.calendar,))
-            raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "attendee-allowed")))
+            return fail(HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "attendee-allowed"))))
         attendee = attendees[0]
     
         # Attendee's Outbox MUST be the request URI
         attendeePrincipal = self.resource.principalForCalendarUserAddress(attendee)
-        if attendeePrincipal:
-            if self.doingPOST and attendeePrincipal.scheduleOutboxURL() != self.request.uri:
-                log.err("ATTENDEE in calendar data does not match owner of Outbox: %s" % (self.calendar,))
+        d = attendeePrincipal.scheduleOutboxURL(self.request)
+        def _gotOutboxURL(outboxURL):
+            if attendeePrincipal:
+                if self.doingPOST and outboxURL != self.request.uri:
+                    log.err("ATTENDEE in calendar data does not match owner of Outbox: %s" % (self.calendar,))
+                    raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "attendee-allowed")))
+            else:
+                log.err("Unknown ATTENDEE in calendar data: %s" % (self.calendar,))
                 raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "attendee-allowed")))
-        else:
-            log.err("Unknown ATTENDEE in calendar data: %s" % (self.calendar,))
-            raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "attendee-allowed")))
     
+        return d.addCallback(_gotOutboxURL)
+
     def securityChecks(self):
         """
         Check that the originator has the appropriate rights to send this type of iTIP message.
@@ -576,15 +583,18 @@
     
         # Prevent spoofing of ORGANIZER with specific METHODs when local
         if self.calendar.propertyValue("METHOD") in ("PUBLISH", "REQUEST", "ADD", "CANCEL", "DECLINECOUNTER"):
-            self.checkOrganizerAsOriginator()
+            return self.checkOrganizerAsOriginator()
     
         # Prevent spoofing when doing reply-like METHODs
         elif self.calendar.propertyValue("METHOD") in ("REPLY", "COUNTER", "REFRESH"):
-            self.checkAttendeeAsOriginator()
+            return self.checkAttendeeAsOriginator()
             
         else:
             log.err("Unknown iTIP METHOD for security checks: %s" % (self.calendar.propertyValue("METHOD"),))
-            raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-data"), description="Unknown iTIP METHOD for security checks"))
+            return fail(HTTPError(ErrorResponse(
+                       responsecode.FORBIDDEN,
+                       (caldav_namespace, "valid-calendar-data"),
+                       description="Unknown iTIP METHOD for security checks")))
 
     def finalChecks(self):
         """
@@ -700,7 +710,7 @@
             else:
                 # Map recipient to their inbox
                 inbox = None
-                inboxURL = principal.scheduleInboxURL()
+                inboxURL = yield principal.scheduleInboxURL()
                 if inboxURL:
                     inbox = (yield self.request.locateResource(inboxURL))
 
@@ -887,7 +897,7 @@
             else:
                 # Map recipient to their inbox
                 inbox = None
-                inboxURL = principal.scheduleInboxURL()
+                inboxURL = yield principal.scheduleInboxURL()
                 if inboxURL:
                     inbox = (yield self.request.locateResource(inboxURL))
 

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/utils.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/utils.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/scheduling/utils.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -30,27 +30,28 @@
     result["calendar_collection_uri"] = None
     if principal:
         # Get principal's calendar-home
-        calendar_home = principal.calendarHome()
+        calendar_home = yield principal.calendarHome()
         
         # FIXME: because of the URL->resource request mapping thing, we have to force the request
         # to recognize this resource
         request._rememberResource(calendar_home, calendar_home.url())
 
         # Run a UID query against the UID
-
-        def queryCalendarCollection(collection, uri):
-            rname = collection.index().resourceNameForUID(uid)
+        def queryCalendarCollection(rname, collection, uri):
             if rname:
-                result["resource"] = collection.getChild(rname)
+                def _setResource(rsrc):
+                    result["resource"] = rsrc
+                d = collection.getChild(rname).addCallback(_setResource)
                 result["resource_name"] = rname
                 result["calendar_collection"] = collection
                 result["calendar_collection_uri"] = uri
-                return succeed(False)
+                return d
             else:
                 return succeed(True)
-        
+        def getResourceName(collection, uri):
+            return collection.index().resourceNameForUID(uid).addCallback(queryCalendarCollection, collection, uri)
         # NB We are by-passing privilege checking here. That should be OK as the data found is not
         # exposed to the user.
-        yield report_common.applyToCalendarCollections(calendar_home, request, calendar_home.url(), "infinity", queryCalendarCollection, None)
+        yield report_common.applyToCalendarCollections(calendar_home, request, calendar_home.url(), "infinity", getResourceName, None)
 
     returnValue((result["resource"], result["resource_name"], result["calendar_collection"], result["calendar_collection_uri"],))

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/static.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/static.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -34,14 +34,15 @@
     "TimezoneServiceFile",
 ]
 
-import datetime
 import os
+import datetime
 import errno
 from urlparse import urlsplit
 
 from twext.web2.dav.davxml import ErrorResponse
+from twisted.internet.defer import (fail, succeed, inlineCallbacks, returnValue,
+                                    maybeDeferred, Deferred)
 
-from twisted.internet.defer import fail, succeed, inlineCallbacks, returnValue, maybeDeferred
 from twisted.python.failure import Failure
 from twisted.web2 import responsecode, http, http_headers
 from twisted.web2.http import HTTPError, StatusResponse
@@ -86,6 +87,14 @@
     """
     CalDAV-accessible L{DAVFile} resource.
     """
+
+    @classmethod
+    def fetch(cls, request, path, *args, **kwargs):
+        """
+        stuff etc
+        """
+        return succeed(cls(path, *args, **kwargs))
+
     def __repr__(self):
         if self.isCalendarCollection():
             return "<%s (calendar collection): %s>" % (self.__class__.__name__, self.fp.path)
@@ -258,8 +267,8 @@
 
             tzids = set()
             isowner = (yield self.isOwner(request, adminprincipals=True, readprincipals=True))
-
-            for name, uid, type in self.index().bruteForceSearch(): #@UnusedVariable
+            searchResults = yield self.index().bruteForceSearch()
+            for name, uid, type in searchResults: #@UnusedVariable
                 try:
                     child = yield request.locateChildResource(self, name)
                     child = IDAVResource(child)
@@ -274,7 +283,7 @@
                         continue
 
                     # Get the access filtered view of the data
-                    caldata = child.iCalendarTextFiltered(isowner)
+                    caldata = yield child.iCalendarTextFiltered(isowner)
                     try:
                         subcalendar = iComponent.fromString(caldata)
                     except ValueError:
@@ -314,7 +323,7 @@
     def iCalendarText(self, name=None):
         if self.isPseudoCalendarCollection():
             if name is None:
-                return str(self.iCalendar())
+                return self.iCalendar().addCallback(str)
 
             try:
                 calendar_file = self.fp.child(name).open()
@@ -323,7 +332,7 @@
                 raise
 
         elif self.isCollection():
-            return None
+            return succeed(None)
 
         else:
             if name is not None:
@@ -337,10 +346,10 @@
         finally:
             calendar_file.close()
 
-        return calendar_data
+        return succeed(calendar_data)
 
     def iCalendarXML(self, name=None):
-        return caldavxml.CalendarData.fromCalendar(self.iCalendarText(name))
+        return self.iCalendarText(name).addCallback(caldavxml.CalendarData.fromCalendar)
 
     def supportedPrivileges(self, request):
         # read-free-busy support on calendar collection and calendar object resources
@@ -377,10 +386,9 @@
     ##
 
     def listChildren(self):
-        return [
-            child for child in super(CalDAVFile, self).listChildren()
-            if not child.startswith(".")
-        ]
+        return super(CalDAVFile, self).listChildren().addCallback(
+            lambda children: [child for child in children
+                              if not child.startswith(".")])
 
     def propertyCollection(self):
         if not hasattr(self, "_propertyCollection"):
@@ -389,48 +397,34 @@
 
     def createSimilarFile(self, path):
         if path == self.fp.path:
-            return self
+            return succeed(self)
 
-        similar = super(CalDAVFile, self).createSimilarFile(path)
+        d = maybeDeferred(super(CalDAVFile, self).createSimilarFile, path)
+        def _gotFile(similar):
+            if isCalendarCollectionResource(self):
+                #
+                # Override DELETE, MOVE
+                #
+                for method in ("DELETE", "MOVE"):
+                    method = "http_" + method
+                    original = getattr(similar, method)
 
-        if isCalendarCollectionResource(self):
-            #
-            # Override the dead property store
-            #
-            superDeadProperties = similar.deadProperties
+                    @inlineCallbacks
+                    def override(request, original=original):
 
-            def deadProperties():
-                if not hasattr(similar, "_dead_properties"):
-                    similar._dead_properties = self.propertyCollection().propertyStoreForChild(
-                        similar,
-                        superDeadProperties(caching=False)
-                    )
-                return similar._dead_properties
+                        # Call original method (which is deferred)
+                        response = (yield original(request))
 
-            similar.deadProperties = deadProperties
+                        # Wipe the cache
+                        similar.deadProperties().flushCache()
 
-            #
-            # Override DELETE, MOVE
-            #
-            for method in ("DELETE", "MOVE"):
-                method = "http_" + method
-                original = getattr(similar, method)
+                        returnValue(response)
 
-                @inlineCallbacks
-                def override(request, original=original):
+                    setattr(similar, method, override)
 
-                    # Call original method (which is deferred)
-                    response = (yield original(request))
+            return similar
+        return d.addCallback(_gotFile)
 
-                    # Wipe the cache
-                    similar.deadProperties().flushCache()
-
-                    returnValue(response)
-
-                setattr(similar, method, override)
-
-        return similar
-
     def updateCTag(self):
         assert self.isCollection()
         try:
@@ -554,21 +548,20 @@
 
 class AutoProvisioningFileMixIn (AutoProvisioningResourceMixIn):
     def provision(self):
-        self.provisionFile()
-        return super(AutoProvisioningFileMixIn, self).provision()
+        d = self.provisionFile()
+        super(AutoProvisioningFileMixIn, self).provision()
+        return d
 
-
-    def provisionFile(self):
+    def provisionFile(self, request=None):
         if hasattr(self, "_provisioned_file"):
-            return False
+            return succeed(False)
         else:
             self._provisioned_file = True
 
         fp = self.fp
-
         fp.restat(False)
         if fp.exists():
-            return False
+            return succeed(False)
 
         log.msg("Provisioning file: %s" % (self,))
 
@@ -593,7 +586,7 @@
             fp.open("w").close()
             fp.restat(False)
 
-        return True
+        return succeed(True)
 
 class CalendarHomeProvisioningFile (AutoProvisioningFileMixIn, DirectoryCalendarHomeProvisioningResource, DAVFile):
     """
@@ -653,56 +646,57 @@
         assert len(name) > 4, "Directory record has an invalid GUID: %r" % (name,)
         
         childPath = self.fp.child(name[0:2]).child(name[2:4]).child(name)
-        child = self.homeResourceClass(childPath.path, self, record)
+        d = self.homeResourceClass.fetch(None, childPath.path, self, record)
+        def _gotChild(child):
+            if not child.exists():
+                self.provision()
 
-        if not child.exists():
-            self.provision()
+                if not childPath.parent().isdir():
+                    childPath.parent().makedirs()
 
-            if not childPath.parent().isdir():
-                childPath.parent().makedirs()
+                for oldPath in (
+                    # Pre 2.0: All in one directory
+                    self.fp.child(name),
+                    # Pre 1.2: In types hierarchy instead of the GUID hierarchy
+                    self.parent.getChild(record.recordType).fp.child(record.shortNames[0]),
+                ):
+                    if oldPath.exists():
+                        # The child exists at an old location.  Move to new location.
+                        log.msg("Moving calendar home from old location %r to new location %r." % (oldPath, childPath))
+                        try:
+                            oldPath.moveTo(childPath)
+                        except (OSError, IOError), e:
+                            log.err("Error moving calendar home %r: %s" % (oldPath, e))
+                            raise HTTPError(StatusResponse(
+                                responsecode.INTERNAL_SERVER_ERROR,
+                                "Unable to move calendar home."
+                            ))
+                        child.fp.restat(False)
+                        break
+                else:
+                    #
+                    # NOTE: provisionDefaultCalendars() returns a deferred, which we are ignoring.
+                    # The result being that the default calendars will be present at some point
+                    # in the future, not necessarily right now, and we don't have a way to wait
+                    # on that to finish.
+                    #
+                    child.provisionDefaultCalendars()
 
-            for oldPath in (
-                # Pre 2.0: All in one directory
-                self.fp.child(name),
-                # Pre 1.2: In types hierarchy instead of the GUID hierarchy
-                self.parent.getChild(record.recordType).fp.child(record.shortNames[0]),
-            ):
-                if oldPath.exists():
-                    # The child exists at an old location.  Move to new location.
-                    log.msg("Moving calendar home from old location %r to new location %r." % (oldPath, childPath))
-                    try:
-                        oldPath.moveTo(childPath)
-                    except (OSError, IOError), e:
-                        log.err("Error moving calendar home %r: %s" % (oldPath, e))
+                    #
+                    # Try to work around the above a little by telling the client that something
+                    # when wrong temporarily if the child isn't provisioned right away.
+                    #
+                    if not child.exists():
                         raise HTTPError(StatusResponse(
-                            responsecode.INTERNAL_SERVER_ERROR,
-                            "Unable to move calendar home."
+                            responsecode.SERVICE_UNAVAILABLE,
+                            "Provisioning calendar home."
                         ))
-                    child.fp.restat(False)
-                    break
-            else:
-                #
-                # NOTE: provisionDefaultCalendars() returns a deferred, which we are ignoring.
-                # The result being that the default calendars will be present at some point
-                # in the future, not necessarily right now, and we don't have a way to wait
-                # on that to finish.
-                #
-                child.provisionDefaultCalendars()
 
-                #
-                # Try to work around the above a little by telling the client that something
-                # when wrong temporarily if the child isn't provisioned right away.
-                #
-                if not child.exists():
-                    raise HTTPError(StatusResponse(
-                        responsecode.SERVICE_UNAVAILABLE,
-                        "Provisioning calendar home."
-                    ))
+                assert child.exists()
 
-            assert child.exists()
+            return child
+        return d.addCallback(_gotChild)
 
-        return child
-
     def createSimilarFile(self, path):
         raise HTTPError(responsecode.NOT_FOUND)
 
@@ -746,21 +740,26 @@
         }.get(name, None)
 
         if cls is not None:
-            child = cls(self.fp.child(name).path, self)
-            child.cacheNotifier = self.cacheNotifier
-            child.clientNotifier = self.clientNotifier
-            return child
+            d = cls.fetch(None, self.fp.child(name).path, self)
+            def _gotChild(child):
+                child.cacheNotifier = self.cacheNotifier
+                child.clientNotifier = self.clientNotifier
+                return child
+            return d.addCallback(_gotChild)
 
         return self.createSimilarFile(self.fp.child(name).path)
 
+
     def createSimilarFile(self, path):
         if path == self.fp.path:
-            return self
+            return succeed(self)
         else:
-            similar = CalDAVFile(path, principalCollections=self.principalCollections())
-            similar.cacheNotifier = self.cacheNotifier
-            similar.clientNotifier = self.clientNotifier
-            return similar
+            d = CalDAVFile.fetch(None, path, principalCollections=self.principalCollections())
+            def _gotChild(similar):
+                similar.cacheNotifier = self.cacheNotifier
+                similar.clientNotifier = self.clientNotifier
+                return similar
+            return d.addCallback(_gotChild)
 
     def getChild(self, name):
         # This avoids finding case variants of put children on case-insensitive filesystems.

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_collectioncontents.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_collectioncontents.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_collectioncontents.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -192,9 +192,11 @@
         fd.close()
         fd = open(os.path.join(colpath, "bogus"), "w")
         fd.close()
-        children = self.site.resource.listChildren()
-        self.assertTrue("bogus" in children)
-        self.assertFalse("._bogus" in children)
+        d = self.site.resource.listChildren()
+        def _gotChildren(children):
+            self.assertTrue("bogus" in children)
+            self.assertFalse("._bogus" in children)
+        return d.addCallback(_gotChildren)
 
     def test_fail_dot_file_put_in_calendar(self):
         """

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_index.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_index.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_index.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -426,13 +426,15 @@
                    )
               )
 
-            resources = self.db.indexedSearch(filter, fbtype=True)
-            index_results = set()
-            for _ignore_name, _ignore_uid, type, test_organizer, float, start, end, fbtype in resources:
-                self.assertEqual(test_organizer, organizer, msg=description)
-                index_results.add((float, start, end, fbtype,))
+            d = self.db.indexedSearch(filter, fbtype=True)
+            def _gotSearchResults(resources):
+                index_results = set()
+                for _ignore_name, _ignore_uid, type, test_organizer, float, start, end, fbtype in resources:
+                    self.assertEqual(test_organizer, organizer, msg=description)
+                    index_results.add((float, start, end, fbtype,))
 
-            self.assertEqual(set(instances), index_results, msg=description)
+                self.assertEqual(set(instances), index_results, msg=description)
+            return d.addCallback(_gotSearchResults)
 
 class SQLIndexUpgradeTests (twistedcaldav.test.util.TestCase):
     """

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_memcacheprops.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_memcacheprops.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_memcacheprops.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -27,6 +27,7 @@
 import os
 
 from twisted.web2.http import HTTPError
+from twisted.internet.defer import succeed
 
 from twistedcaldav.memcacheprops import MemcachePropertyCollection
 from twistedcaldav.test.util import InMemoryPropertyStore
@@ -48,7 +49,7 @@
         return self.children.iterkeys()
 
     def getChild(self, childName):
-        return self.children[childName]
+        return succeed(self.children[childName])
 
     def propertyCollection(self):
         if not hasattr(self, "_propertyCollection"):

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_sql.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_sql.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_sql.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -182,9 +182,11 @@
         fd.close()
         fd = open(os.path.join(colpath, "test"), "w")
         fd.close()
-        children = self.site.resource.listChildren()
-        self.assertTrue("test" in children)
-        self.assertFalse(db_prefix + "sqlite" in children)
+        d = self.site.resource.listChildren()
+        def _gotChildren(children):
+            self.assertTrue("test" in children)
+            self.assertFalse(db_prefix + "sqlite" in children)
+        return d.addCallback(_gotChildren)
 
     def test_duplicate_create(self):
         dbname = self.mktemp()

Modified: CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_static.py
===================================================================
--- CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_static.py	2009-08-12 18:26:25 UTC (rev 4492)
+++ CalendarServer/branches/more-deferreds-3/twistedcaldav/test/test_static.py	2009-08-13 19:22:56 UTC (rev 4493)
@@ -38,8 +38,10 @@
 
 
     def test_childrenHaveCacheNotifier(self):
-        child = self.calendarHome.createSimilarFile('/fake/path')
-        self.assertEquals(child.cacheNotifier, self.calendarHome.cacheNotifier)
+        d = self.calendarHome.createSimilarFile('/fake/path')
+        def _gotResource(child):
+            self.assertEquals(child.cacheNotifier, self.calendarHome.cacheNotifier)
+        return d.addCallback(_gotResource)
 
 
 class CalDAVFileTests(TestCase):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090813/96d5b95d/attachment-0001.html>


More information about the calendarserver-changes mailing list