[CalendarServer-changes] [6373] CalendarServer/branches/users/glyph/more-deferreds-7

source_changes at macosforge.org source_changes at macosforge.org
Fri Sep 24 08:53:10 PDT 2010


Revision: 6373
          http://trac.macosforge.org/projects/calendarserver/changeset/6373
Author:   glyph at apple.com
Date:     2010-09-24 08:53:08 -0700 (Fri, 24 Sep 2010)
Log Message:
-----------
more async

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/more-deferreds-7/twext/web2/dav/resource.py
    CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/directory/test/test_principal.py
    CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/extensions.py
    CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/method/put_addressbook_common.py
    CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/method/put_common.py
    CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/resource.py
    CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/schedule.py
    CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/scheduling/implicit.py
    CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/sharing.py
    CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/storebridge.py
    CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/scheduling.py
    CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/sql.py
    CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/test/common.py
    CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/test/test_file.py
    CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/test/test_sql.py
    CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/util.py
    CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/icalendarstore.py
    CalendarServer/branches/users/glyph/more-deferreds-7/txdav/carddav/datastore/test/common.py
    CalendarServer/branches/users/glyph/more-deferreds-7/txdav/carddav/datastore/test/test_sql.py
    CalendarServer/branches/users/glyph/more-deferreds-7/txdav/carddav/datastore/util.py
    CalendarServer/branches/users/glyph/more-deferreds-7/txdav/common/datastore/sql_legacy.py

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/twext/web2/dav/resource.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/twext/web2/dav/resource.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twext/web2/dav/resource.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -629,7 +629,7 @@
 
         completionDeferred = Deferred()
         basepath = request.urlForResource(self)
-        children = list(self.listChildren())
+        children = []
 
         def checkPrivilegesError(failure):
             failure.trap(AccessDeniedError)
@@ -679,7 +679,10 @@
                 d.addCallbacks(gotChild, checkPrivilegesError, (childpath,))
                 d.addErrback(completionDeferred.errback)
 
-        getChild()
+        def gotChildren(listChildrenResult):
+            children[:] = list(listChildrenResult)
+            getChild()
+        maybeDeferred(self.listChildren).addCallback(gotChildren)
 
         return completionDeferred
 
@@ -722,7 +725,7 @@
 
         children = []
         basepath = request.urlForResource(self)
-        childnames = list(self.listChildren())
+        childnames = list((yield self.listChildren()))
         for childname in childnames:
             if names and childname not in names:
                 continue

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/directory/test/test_principal.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/directory/test/test_principal.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/directory/test/test_principal.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -68,6 +68,8 @@
 
         calendaruserproxy.ProxyDBService = calendaruserproxy.ProxySqliteDB(os.path.abspath(self.mktemp()))
 
+
+    @inlineCallbacks
     def test_hierarchy(self):
         """
         DirectoryPrincipalProvisioningResource.listChildren(),
@@ -92,7 +94,7 @@
             principalCollections = provisioningResource.principalCollections()
             self.assertEquals(set((provisioningURL,)), set(pc.principalCollectionURL() for pc in principalCollections))
 
-            recordTypes = set(provisioningResource.listChildren())
+            recordTypes = set((yield provisioningResource.listChildren()))
             self.assertEquals(recordTypes, set(directory.recordTypes()))
 
             for recordType in recordTypes:
@@ -106,7 +108,7 @@
                 principalCollections = typeResource.principalCollections()
                 self.assertEquals(set((provisioningURL,)), set(pc.principalCollectionURL() for pc in principalCollections))
 
-                shortNames = set(typeResource.listChildren())
+                shortNames = set((yield typeResource.listChildren()))
                 self.assertEquals(shortNames, set(r.shortNames[0] for r in directory.listRecords(recordType)))
 
                 for shortName in shortNames:
@@ -426,7 +428,7 @@
             for args in _authReadOnlyPrivileges(self, provisioningResource, provisioningResource.principalCollectionURL()):
                 yield self._checkPrivileges(*args)
 
-            for recordType in provisioningResource.listChildren():
+            for recordType in (yield provisioningResource.listChildren()):
                 #print "   -> %s" % (recordType,)
                 typeResource = provisioningResource.getChild(recordType)
 

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/extensions.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/extensions.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/extensions.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -521,7 +521,7 @@
         ]
 
         even = Alternator()
-        for name in sorted(self.listChildren()):
+        for name in sorted((yield self.listChildren())):
             child = self.getChild(name)
 
             url, name, size, lastModified, contentType = self.getChildDirectoryEntry(child, name, request)

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/method/put_addressbook_common.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/method/put_addressbook_common.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/method/put_addressbook_common.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -297,8 +297,8 @@
 
         # UID must be unique
         index = self.destinationparent.index()
-        if not index.isAllowedUID(uid, oldname, self.destination.name()):
-            rname = index.resourceNameForUID(uid)
+        if not (yield index.isAllowedUID(uid, oldname, self.destination.name())):
+            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.

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/method/put_common.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/method/put_common.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/method/put_common.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -596,8 +596,8 @@
         
         # UID must be unique 
         index = self.destinationparent.index() 
-        if not index.isAllowedUID(uid, oldname, self.destination.name()): 
-            rname = index.resourceNameForUID(uid) 
+        if not (yield index.isAllowedUID(uid, oldname, self.destination.name())): 
+            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. 

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/resource.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/resource.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/resource.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -1012,8 +1012,11 @@
 
         if depth != "0" and self.isCollection():
             basepath = request.urlForResource(self)
-            children = list(self.listChildren())
-            getChild()
+            children = []
+            def gotChildren(childNames):
+                children[:] = list(childNames)
+                getChild()
+            maybeDeferred(self.listChildren).addCallback(gotChildren)
         else:
             completionDeferred.callback(None)
 
@@ -1025,7 +1028,7 @@
 
         if depth != "0" and self.isCollection():
             basepath = request.urlForResource(self)
-            for childname in self.listChildren():
+            for childname in (yield self.listChildren()):
                 childpath = joinURL(basepath, childname)
                 child = (yield request.locateResource(childpath))
                 if privileges:
@@ -2099,16 +2102,19 @@
     def makeRegularChild(self, name):
         raise NotImplementedError
 
+
+    @inlineCallbacks
     def listChildren(self):
         """
         @return: a sequence of the names of all known children of this resource.
         """
         children = set(self._provisionedChildren.keys())
         children.update(self._provisionedLinks.keys())
-        children.update(self.allShareNames())
-        children.update(self._newStoreHome.listChildren())
-        return children
+        children.update((yield self.allShareNames()))
+        children.update((yield self._newStoreHome.listChildren()))
+        returnValue(children)
 
+
     def readProperty(self, property, request):
         if type(property) is tuple:
             qname = property

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/schedule.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/schedule.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/schedule.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -154,7 +154,7 @@
             if not self.hasDeadProperty(property):
                 top = self.parent.url()
                 values = []
-                for cal in self.parent._newStoreHome.calendars():
+                for cal in (yield self.parent._newStoreHome.calendars()):
                     prop = cal.properties().get(PropertyName.fromString(ScheduleCalendarTransp.sname())) 
                     if prop == ScheduleCalendarTransp(Opaque()):
                         values.append(HRef(joinURL(top, cal.name())))
@@ -261,7 +261,7 @@
         defaultCalendarURL = joinURL(calendarHomeURL, "calendar")
         defaultCalendar = (yield request.locateResource(defaultCalendarURL))
         if defaultCalendar is None or not defaultCalendar.exists():
-            getter = iter(self.parent._newStoreHome.calendars())
+            getter = iter((yield self.parent._newStoreHome.calendars()))
             # FIXME: the back-end should re-provision a default calendar here.
             # Really, the dead property shouldn't be necessary, and this should
             # be entirely computed by a back-end method like 'defaultCalendar()'

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/scheduling/implicit.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/scheduling/implicit.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/scheduling/implicit.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -395,7 +395,7 @@
 
         @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:

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/sharing.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/sharing.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/sharing.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -939,27 +939,35 @@
     A mix-in for calendar/addressbook homes that defines the operations for
     manipulating a sharee's set of shared calendars.
     """
-    
 
+
+    @inlineCallbacks
     def provisionShare(self, name):
-        
         # Try to find a matching share
         child = None
-        shares = self.allShares()
+        shares = yield self.allShares()
         if name in shares:
             from twistedcaldav.sharedcollection import SharedCollectionResource
             child = SharedCollectionResource(self, shares[name])
             self.putChild(name, child)
-        return child
+        returnValue(child)
 
+
+    @inlineCallbacks
     def allShares(self):
         if not hasattr(self, "_allShares"):
-            self._allShares = dict([(share.localname, share) for share in self.sharesDB().allRecords()])
-        return self._allShares
+            allShareRecords = yield self.sharesDB().allRecords()
+            self._allShares = dict([(share.localname, share) for share in
+                                    allShareRecords])
+        returnValue(self._allShares)
 
+
+    @inlineCallbacks
     def allShareNames(self):
-        return tuple(self.allShares().keys())
+        allShares = yield self.allShares()
+        returnValue(tuple(allShares.keys()))
 
+
     @inlineCallbacks
     def acceptInviteShare(self, request, hostUrl, inviteUID, displayname=None):
         

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/storebridge.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/storebridge.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -397,28 +397,32 @@
         return True
 
 
+    @inlineCallbacks
     def getChild(self, name):
-        calendarObject = self._newStoreHome.calendarObjectWithDropboxID(name)
+        calendarObject = yield self._newStoreHome.calendarObjectWithDropboxID(name)
         if calendarObject is None:
-            return NoDropboxHere()
+            returnValue(NoDropboxHere())
         objectDropbox = CalendarObjectDropbox(
             calendarObject, principalCollections=self.principalCollections()
         )
         self.propagateTransaction(objectDropbox)
-        return objectDropbox
+        returnValue(objectDropbox)
 
 
     def resourceType(self,):
         return davxml.ResourceType.dropboxhome #@UndefinedVariable
 
 
+    @inlineCallbacks
     def listChildren(self):
         l = []
-        for everyCalendar in self._newStoreHome.calendars():
-            for everyObject in everyCalendar.calendarObjects():
+        for everyCalendar in (yield self._newStoreHome.calendars()):
+            for everyObject in (yield everyCalendar.calendarObjects()):
                 l.append(everyObject.dropboxID())
-        return l
+        returnValue(l)
 
+
+
 class NoDropboxHere(_GetChildHelper):
 
     def isCollection(self):
@@ -842,7 +846,7 @@
 
         errors = ResponseQueue(where, "DELETE", NO_CONTENT)
 
-        for childname in self.listChildren():
+        for childname in (yield self.listChildren()):
 
             childurl = joinURL(where, childname)
 
@@ -1360,13 +1364,17 @@
         self.propagateTransaction(similar)
         return similar
 
+
+    @inlineCallbacks
     def listChildren(self):
         """
         @return: a sequence of the names of all known children of this resource.
         """
         children = set(self.putChildren.keys())
-        children.update(self._newStoreAddressBook.listAddressbookObjects())
-        return sorted(children)
+        children.update(
+            (yield self._newStoreAddressBook.listAddressbookObjects())
+        )
+        returnValue(sorted(children))
 
 
 
@@ -1471,7 +1479,7 @@
 
         errors = ResponseQueue(where, "DELETE", NO_CONTENT)
 
-        for childname in self.listChildren():
+        for childname in (yield self.listChildren()):
 
             childurl = joinURL(where, childname)
 
@@ -1863,16 +1871,17 @@
         self.propagateTransaction(similar)
         return similar
 
+
+    @inlineCallbacks
     def listChildren(self):
         """
         @return: a sequence of the names of all known children of this resource.
         """
         children = set(self.putChildren.keys())
         children.update(self._newStoreNotifications.listNotificationObjects())
-        return children
+        returnValue(children)
 
 
-
     def quotaSize(self, request):
         # FIXME: tests, workingness
         return succeed(0)
@@ -1894,11 +1903,12 @@
         self._initializeWithNotifications(notifications, home)
 
 
+    @inlineCallbacks
     def listChildren(self):
         l = []
-        for notification in self._newStoreNotifications.notificationObjects():
+        for notification in (yield self._newStoreNotifications.notificationObjects()):
             l.append(notification.name())
-        return l
+        returnValue(l)
 
     def isCollection(self):
         return True

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/scheduling.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/scheduling.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/scheduling.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -73,10 +73,15 @@
 #        # FIXME: wrap?
 #        return self._calendarHome.properties()
 
+    @inlineCallbacks
     def calendars(self):
-        for calendar in super(ImplicitCalendarHome, self).calendars():
-            yield ImplicitCalendar(self, calendar)
+        superCalendars = (yield super(ImplicitCalendarHome, self).calendars())
+        wrapped = []
+        for calendar in superCalendars:
+            wrapped.append(ImplicitCalendar(self, calendar))
+        returnValue(wrapped)
 
+
     def createCalendarWithName(self, name):
         self._calendarHome.createCalendarWithName(name)
 

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/sql.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/sql.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -14,6 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 ##
+from twisted.internet.defer import inlineCallbacks, returnValue
 
 __all__ = [
     "CalendarHome",
@@ -75,14 +76,15 @@
     calendars = CommonHome.children
     listCalendars = CommonHome.listChildren
 
+    @inlineCallbacks
     def calendarObjectWithDropboxID(self, dropboxID):
         """
         Implement lookup with brute-force scanning.
         """
-        for calendar in self.calendars():
-            for calendarObject in calendar.calendarObjects():
+        for calendar in (yield self.calendars()):
+            for calendarObject in (yield calendar.calendarObjects()):
                 if dropboxID == calendarObject.dropboxID():
-                    return calendarObject
+                    returnValue(calendarObject)
 
 
     def createdHome(self):

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/test/common.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/test/common.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -511,6 +511,7 @@
         )
 
 
+    @inlineCallbacks
     def test_calendarObjectsWithRemovedObject(self):
         """
         L{ICalendar.calendarObjects} skips those objects which have been
@@ -519,7 +520,7 @@
         """
         calendar1 = yield self.calendarUnderTest()
         calendar1.removeCalendarObjectWithName("2.ics")
-        calendarObjects = list(calendar1.calendarObjects())
+        calendarObjects = list((yield calendar1.calendarObjects()))
         self.assertEquals(set(o.name() for o in calendarObjects),
                           set(calendar1_objectNames) - set(["2.ics"]))
 
@@ -567,11 +568,11 @@
         calendar = yield self.calendarUnderTest()
         for name in calendar1_objectNames:
             uid = (u'uid' + name.rstrip(".ics"))
-            self.assertNotIdentical(calendar.calendarObjectWithUID(uid),
+            self.assertNotIdentical((yield calendar.calendarObjectWithUID(uid)),
                                     None)
             calendar.removeCalendarObjectWithUID(uid)
             self.assertEquals(
-                calendar.calendarObjectWithUID(uid),
+                (yield calendar.calendarObjectWithUID(uid)),
                 None
             )
             self.assertEquals(
@@ -735,9 +736,11 @@
         L{ICalendarHome.createCalendarWithName}.
         """
         home = yield self.homeUnderTest()
-        before = set(x.name() for x in home.calendars())
+        allCalendars = yield home.calendars()
+        before = set(x.name() for x in allCalendars)
         home.createCalendarWithName("new-name")
-        after = set(x.name() for x in home.calendars())
+        allCalendars = yield home.calendars()
+        after = set(x.name() for x in allCalendars)
         self.assertEquals(before | set(['new-name']), after)
 
 
@@ -1045,7 +1048,7 @@
         home = yield self.homeUnderTest()
         cal = yield self.calendarUnderTest()
         fromName = yield cal.calendarObjectWithName(objName)
-        fromDropbox = home.calendarObjectWithDropboxID("some-dropbox-id")
+        fromDropbox = yield home.calendarObjectWithDropboxID("some-dropbox-id")
         self.assertEquals(fromName, fromDropbox)
 
 
@@ -1202,7 +1205,7 @@
             self.assertIdentical(
                 (yield calendar2.calendarObjectWithName(resourceName)), None)
             self.assertIdentical(
-                calendar2.calendarObjectWithUID(obj.uid()), None)
+                (yield calendar2.calendarObjectWithUID(obj.uid())), None)
 
 
     @inlineCallbacks

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/test/test_file.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/test/test_file.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/test/test_file.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -197,8 +197,8 @@
         self.home1.createCalendarWithName("calendar2")
         calendar = yield self.home1.calendarWithName("calendar2")
         index = calendar._index
-        yield self.assertEquals(set(index.calendarObjects()),
-                                set(calendar.calendarObjects()))
+        yield self.assertEquals(set((yield index.calendarObjects())),
+                                set((yield calendar.calendarObjects())))
         yield self.txn.commit()
         self.txn = self.calendarStore.newTransaction()
         self.home1 = yield self.txn.calendarHomeWithUID("home1")
@@ -212,6 +212,7 @@
                           set((yield calendar.calendarObjects())))
 
 
+    @inlineCallbacks
     def test_calendarObjectWithName_dot(self):
         """
         Filenames starting with "." are reserved by this
@@ -220,22 +221,25 @@
         """
         name = ".foo.ics"
         self.home1._path.child(name).touch()
-        self.assertEquals(self.calendar1.calendarObjectWithName(name), None)
+        self.assertEquals(
+            (yield self.calendar1.calendarObjectWithName(name)),
+            None)
 
 
     @featureUnimplemented
+    @inlineCallbacks
     def test_calendarObjectWithUID_exists(self):
         """
         Find existing calendar object by name.
         """
-        calendarObject = self.calendar1.calendarObjectWithUID("1")
+        calendarObject = yield self.calendar1.calendarObjectWithUID("1")
         self.failUnless(
             isinstance(calendarObject, CalendarObject),
             calendarObject
         )
         self.assertEquals(
             calendarObject.component(),
-            self.calendar1.calendarObjectWithName("1.ics").component()
+            (yield self.calendar1.calendarObjectWithName("1.ics")).component()
         )
 
 
@@ -253,13 +257,14 @@
 
 
     @featureUnimplemented
+    @inlineCallbacks
     def test_createCalendarObjectWithName_uidconflict(self):
         """
         Attempt to create a calendar object with a conflicting UID
         should raise.
         """
         name = "foo.ics"
-        assert self.calendar1.calendarObjectWithName(name) is None
+        assert (yield self.calendar1.calendarObjectWithName(name)) is None
         component = VComponent.fromString(event1modified_text)
         self.assertRaises(
             ObjectResourceUIDAlreadyExistsError,
@@ -378,7 +383,7 @@
         """
         self.addCleanup(self.txn.commit)
         modifiedComponent = VComponent.fromString(event1modified_text)
-        self.calendar1.calendarObjectWithName("1.ics").setComponent(
+        (yield self.calendar1.calendarObjectWithName("1.ics")).setComponent(
             modifiedComponent
         )
         self.assertIdentical(
@@ -488,5 +493,5 @@
         Adding a dotfile to the calendar home should not increase
         """
         (yield self.homeUnderTest())._path.child(".foo").createDirectory()
-        self.test_calendarObjects()
+        yield self.test_calendarObjects()
 

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/test/test_sql.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/test/test_sql.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -158,10 +158,12 @@
             "new-home", create=True
         )
         migrateHome(fromHome, toHome, lambda x: x.component())
-        self.assertEquals(set([c.name() for c in toHome.calendars()]),
+        toCalendars = yield toHome.calendars()
+        self.assertEquals(set([c.name() for c in toCalendars]),
                           set([k for k in self.requirements['home1'].keys()
                                if self.requirements['home1'][k] is not None]))
-        for c in fromHome.calendars():
+        fromCalendars = yield fromHome.calendars()
+        for c in fromCalendars:
             self.assertPropertiesSimilar(
                 c, (yield toHome.calendarWithName(c.name())),
                 builtinProperties

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/util.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/util.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/datastore/util.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -119,7 +119,7 @@
     @return: a L{Deferred} which fires when the calendar has migrated.
     """
     outCalendar.properties().update(inCalendar.properties())
-    for calendarObject in inCalendar.calendarObjects():
+    for calendarObject in (yield inCalendar.calendarObjects()):
         
         try:
             outCalendar.createCalendarObjectWithName(
@@ -128,7 +128,7 @@
     
             # Only the owner's properties are migrated, since previous releases of
             # calendar server didn't have per-user properties.
-            outObject = outCalendar.calendarObjectWithName(
+            outObject = yield outCalendar.calendarObjectWithName(
                 calendarObject.name())
             outObject.properties().update(calendarObject.properties())
     
@@ -187,7 +187,8 @@
     outHome.removeCalendarWithName("calendar")
     outHome.removeCalendarWithName("inbox")
     outHome.properties().update(inHome.properties())
-    for calendar in inHome.calendars():
+    inCalendars = yield inHome.calendars()
+    for calendar in inCalendars:
         name = calendar.name()
         if name == "outbox":
             continue

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/icalendarstore.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/icalendarstore.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/txdav/caldav/icalendarstore.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -202,8 +202,9 @@
         in this calendar.
 
         @param uid: a string.
-        @return: an L{ICalendarObject} or C{None} if no such calendar
-            object exists.
+
+        @return: a L{Deferred} firing an L{ICalendarObject} or C{None} if no
+            such calendar object exists.
         """
 
     def createCalendarObjectWithName(name, component):

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/txdav/carddav/datastore/test/common.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/txdav/carddav/datastore/test/common.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/txdav/carddav/datastore/test/common.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -603,15 +603,18 @@
         )
 
 
+    @inlineCallbacks
     def test_addressbooksAfterAddAddressBook(self):
         """
         L{IAddressBookHome.addressbooks} includes addressbooks recently added with
         L{IAddressBookHome.createAddressBookWithName}.
         """
         home = self.homeUnderTest()
-        before = set(x.name() for x in home.addressbooks())
+        allAddressbooks = yield home.addressbooks()
+        before = set(x.name() for x in allAddressbooks)
         home.createAddressBookWithName("new-name")
-        after = set(x.name() for x in home.addressbooks())
+        allAddressbooks = yield home.addressbooks()
+        after = set(x.name() for x in allAddressbooks)
         self.assertEquals(before | set(['new-name']), after)
 
 

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/txdav/carddav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/txdav/carddav/datastore/test/test_sql.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/txdav/carddav/datastore/test/test_sql.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -15,8 +15,8 @@
 ##
 
 """
-Tests for txdav.caldav.datastore.postgres, mostly based on
-L{txdav.caldav.datastore.test.common}.
+Tests for L{txdav.carddav.datastore.sql}, mostly based on
+L{txdav.carddav.datastore.test.common}.
 """
 
 import time
@@ -132,7 +132,7 @@
             "home1").addressbookWithName("addressbook_1")
         toHome = yield self.transactionUnderTest().addressbookHomeWithUID(
             "new-home", create=True)
-        toAddressbook = toHome.addressbookWithName("addressbook")
+        toAddressbook = yield toHome.addressbookWithName("addressbook")
         _migrateAddressbook(fromAddressbook, toAddressbook,
                             lambda x: x.component())
         self.assertAddressbooksSimilar(fromAddressbook, toAddressbook)
@@ -162,10 +162,12 @@
             "new-home", create=True
         )
         migrateHome(fromHome, toHome, lambda x: x.component())
-        self.assertEquals(set([c.name() for c in toHome.addressbooks()]),
+        toAddressbooks = yield toHome.addressbooks()
+        self.assertEquals(set([c.name() for c in toAddressbooks]),
                           set([k for k in self.requirements['home1'].keys()
                                if self.requirements['home1'][k] is not None]))
-        for c in fromHome.addressbooks():
+        fromAddressbooks = yield fromHome.addressbooks()
+        for c in fromAddressbooks:
             self.assertPropertiesSimilar(
                 c, toHome.addressbookWithName(c.name()),
                 builtinProperties

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/txdav/carddav/datastore/util.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/txdav/carddav/datastore/util.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/txdav/carddav/datastore/util.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -18,6 +18,7 @@
 """
 Utility logic common to multiple backend implementations.
 """
+from twisted.internet.defer import inlineCallbacks
 
 from twistedcaldav.vcard import Component as VCard
 from twistedcaldav.vcard import InvalidVCardDataError
@@ -61,6 +62,7 @@
         raise InvalidObjectResourceError(e)
 
 
+ at inlineCallbacks
 def _migrateAddressbook(inAddressbook, outAddressbook, getComponent):
     """
     Copy all addressbook objects and properties in the given input addressbook
@@ -72,7 +74,8 @@
     @param getComponent: a 1-argument callable; see L{migrateHome}.
     """
     outAddressbook.properties().update(inAddressbook.properties())
-    for addressbookObject in inAddressbook.addressbookObjects():
+    inObjects = yield inAddressbook.addressbookObjects()
+    for addressbookObject in inObjects:
         
         try:
             outAddressbook.createAddressBookObjectWithName(
@@ -81,8 +84,8 @@
     
             # Only the owner's properties are migrated, since previous releases of
             # addressbook server didn't have per-user properties.
-            outAddressbook.addressbookObjectWithName(
-                addressbookObject.name()).properties().update(
+            (yield outAddressbook.addressbookObjectWithName(
+                addressbookObject.name())).properties().update(
                     addressbookObject.properties())
 
         except InternalDataStoreError:
@@ -93,15 +96,18 @@
             ))
 
 
+
+ at inlineCallbacks
 def migrateHome(inHome, outHome, getComponent=lambda x:x.component()):
     outHome.removeAddressBookWithName("addressbook")
     outHome.properties().update(inHome.properties())
-    for addressbook in inHome.addressbooks():
+    inAddressbooks = inHome.addressbooks()
+    for addressbook in inAddressbooks:
         name = addressbook.name()
         outHome.createAddressBookWithName(name)
-        outAddressbook = outHome.addressbookWithName(name)
+        outAddressbook = yield outHome.addressbookWithName(name)
         try:
-            _migrateAddressbook(addressbook, outAddressbook, getComponent)
+            yield _migrateAddressbook(addressbook, outAddressbook, getComponent)
         except InternalDataStoreError:
             log.error("  Failed to migrate address book: %s/%s" % (inHome.name(), name,))
 

Modified: CalendarServer/branches/users/glyph/more-deferreds-7/txdav/common/datastore/sql_legacy.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/txdav/common/datastore/sql_legacy.py	2010-09-24 14:29:42 UTC (rev 6372)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/txdav/common/datastore/sql_legacy.py	2010-09-24 15:53:08 UTC (rev 6373)
@@ -26,7 +26,7 @@
 from twistedcaldav.sharing import SharedCollectionRecord
 
 from twisted.python import hashlib
-from twisted.internet.defer import succeed
+from twisted.internet.defer import succeed, inlineCallbacks, returnValue
 
 from twext.python.log import Logger, LoggingMixIn
 
@@ -851,6 +851,7 @@
             return self.reserver.isReservedUID(uid)
 
 
+    @inlineCallbacks
     def isAllowedUID(self, uid, *names):
         """
         Checks to see whether to allow an operation which would add the
@@ -863,23 +864,26 @@
             False otherwise.
         """
         if self.calendar._name == "inbox":
-            return True
+            returnValue(True)
         else:
-            rname = self.resourceNameForUID(uid)
-            return (rname is None or rname in names)
+            rname = yield self.resourceNameForUID(uid)
+            returnValue(rname is None or rname in names)
 
+
+    @inlineCallbacks
     def resourceUIDForName(self, name):
-        obj = self.calendar.calendarObjectWithName(name)
+        obj = yield self.calendar.calendarObjectWithName(name)
         if obj is None:
-            return None
-        return obj.uid()
+            returnValue(None)
+        returnValue(obj.uid())
 
 
+    @inlineCallbacks
     def resourceNameForUID(self, uid):
-        obj = self.calendar.calendarObjectWithUID(uid)
+        obj = yield self.calendar.calendarObjectWithUID(uid)
         if obj is None:
-            return None
-        return obj.name()
+            returnValue(None)
+        returnValue(obj.name())
 
 
     def notExpandedBeyond(self, minDate):
@@ -1144,11 +1148,12 @@
         return (rname is None or rname in names)
 
 
+    @inlineCallbacks
     def resourceUIDForName(self, name):
-        obj = self.addressbook.addressbookObjectWithName(name)
+        obj = yield self.addressbook.addressbookObjectWithName(name)
         if obj is None:
-            return None
-        return obj.uid()
+            returnValue(None)
+        returnValue(obj.uid())
 
 
     def resourceNameForUID(self, uid):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100924/411bade0/attachment-0001.html>


More information about the calendarserver-changes mailing list