[CalendarServer-changes] [4705] CalendarServer/branches/more-deferreds-4/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Wed Nov 4 20:15:00 PST 2009


Revision: 4705
          http://trac.macosforge.org/projects/calendarserver/changeset/4705
Author:   cdaboo at apple.com
Date:     2009-11-04 20:14:57 -0800 (Wed, 04 Nov 2009)
Log Message:
-----------
Various defer fixes.

Modified Paths:
--------------
    CalendarServer/branches/more-deferreds-4/twistedcaldav/index.py
    CalendarServer/branches/more-deferreds-4/twistedcaldav/method/put_common.py
    CalendarServer/branches/more-deferreds-4/twistedcaldav/test/test_index.py

Modified: CalendarServer/branches/more-deferreds-4/twistedcaldav/index.py
===================================================================
--- CalendarServer/branches/more-deferreds-4/twistedcaldav/index.py	2009-11-04 23:58:08 UTC (rev 4704)
+++ CalendarServer/branches/more-deferreds-4/twistedcaldav/index.py	2009-11-05 04:14:57 UTC (rev 4705)
@@ -267,14 +267,14 @@
         results = self._db_values_for_sql(statement, *names)
         return results
 
-
+    @inlineCallbacks
     def testAndUpdateIndex(self, minDate):
         # Find out if the index is expanded far enough
         names = self.notExpandedBeyond(minDate)
         # Actually expand recurrence max
         for name in names:
             self.log_info("Search falls outside range of index for %s %s" % (name, minDate))
-            self.reExpandResource(name, minDate)
+            yield self.reExpandResource(name, minDate)
 
     @inlineCallbacks
     def indexedSearch(self, filter, fbtype=False):
@@ -301,7 +301,7 @@
                     maxDate = maxDate.date()
                     if isStartDate:
                         maxDate += datetime.timedelta(days=365)
-                    self.testAndUpdateIndex(maxDate)
+                    yield self.testAndUpdateIndex(maxDate)
             else:
                 # We cannot handler this filter in an indexed search
                 raise IndexedSearchException()
@@ -501,17 +501,16 @@
         """
         return self._db_values_for_sql("select NAME from RESOURCE where RECURRANCE_MAX < :1", minDate)
 
+    @inlineCallbacks
     def reExpandResource(self, name, expand_until):
         """
         Given a resource name, remove it from the database and re-add it
         with a longer expansion.
         """
-        d = self.resource.getChild(name)
-        d.addCallback(lambda r: r.iCalendar())
-        def _gotCalendar(calendar):
-            self._add_to_db(name, calendar, expand_until=expand_until, reCreate=True)
-            self._db_commit()
-        return d.addCallback(_gotCalendar)
+        child = (yield self.resource.getChild(name))
+        calendar = (yield child.iCalendar())
+        self._add_to_db(name, calendar, expand_until=expand_until, reCreate=True)
+        self._db_commit()
         
     def _add_to_db(self, name, calendar, cursor = None, expand_until=None, reCreate=False):
         """

Modified: CalendarServer/branches/more-deferreds-4/twistedcaldav/method/put_common.py
===================================================================
--- CalendarServer/branches/more-deferreds-4/twistedcaldav/method/put_common.py	2009-11-04 23:58:08 UTC (rev 4704)
+++ CalendarServer/branches/more-deferreds-4/twistedcaldav/method/put_common.py	2009-11-05 04:14:57 UTC (rev 4705)
@@ -86,6 +86,7 @@
             self.source_index_deleted = False
             self.destination_index_deleted = False
         
+        @inlineCallbacks
         def Rollback(self):
             """
             Rollback the server state. Do not allow this to raise another exception. If
@@ -116,7 +117,7 @@
                         self.destination_created = False
                     if self.destination_index_deleted:
                         # Must read in calendar for destination being re-indexed
-                        self.storer.destination.iCalendar().addCallback(self.storer.doDestinationIndex)
+                        self.storer.doDestinationIndex((yield self.storer.destination.iCalendar()))
                         self.destination_index_deleted = False
                         log.debug("Rollback: destination re-indexed %s" % (self.storer.destination.fp.path,))
                     if self.source_index_deleted:
@@ -307,13 +308,13 @@
             if not self.sourcecal:
                 # Valid content type check on the source resource if its not in a calendar collection
                 if self.source is not None:
-                    result, message = yield self.validContentType()
+                    result, message = (yield self.validContentType())
                     if not result:
                         log.err(message)
                         raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "supported-calendar-data")))
                 
                     # At this point we need the calendar data to do more tests
-                    self.calendar = yield self.source.iCalendar()
+                    self.calendar = (yield self.source.iCalendar())
                 else:
                     try:
                         if type(self.calendar) in (types.StringType, types.UnicodeType,):
@@ -357,7 +358,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 = yield self.source.iCalendar()
+                self.calendar = (yield self.source.iCalendar())
 
             # Check access
             if self.destinationcal and config.EnablePrivateEvents:
@@ -368,7 +369,7 @@
 
         elif self.sourcecal:
             self.source_index = self.sourceparent.index()
-            self.calendar = yield self.source.iCalendar()
+            self.calendar = (yield self.source.iCalendar())
     
     @inlineCallbacks
     def validCopyMoveOperation(self):
@@ -452,7 +453,7 @@
         """
         result = True
         message = ""
-        content_type = yield maybeDeferred(self.source.contentType)
+        content_type = (yield maybeDeferred(self.source.contentType))
         if (content_type is None or
             not ((content_type.mediaType == "text") and
                  (content_type.mediaSubtype == "calendar"))):
@@ -599,9 +600,9 @@
 
         # UID must be unique
         index = self.destinationparent.index()
-        isAllowed = yield index.isAllowedUID(uid, oldname, self.destination.fp.basename())
+        isAllowed = (yield index.isAllowedUID(uid, oldname, self.destination.fp.basename()))
         if not isAllowed:
-            rname = yield 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.
@@ -959,7 +960,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 = yield self.noUIDConflict(self.uid)
+                    result, message, rname = (yield self.noUIDConflict(self.uid))
                     if not result:
                         log.err(message)
                         raise HTTPError(ErrorResponse(responsecode.FORBIDDEN,
@@ -1095,7 +1096,7 @@
             if self.destinationcal:
                 result = (yield self.doDestinationIndex(self.calendar))
                 if result is not None:
-                    self.rollback.Rollback()
+                    yield self.rollback.Rollback()
                     returnValue(result)
     
             # Delete the original source if needed.
@@ -1125,7 +1126,7 @@
             # Roll back changes to original server state. Note this may do nothing
             # if the rollback has already occurred or changes already committed.
             if self.rollback:
-                self.rollback.Rollback()
+                yield self.rollback.Rollback()
 
             if isinstance(err, InvalidOverriddenInstanceError):
                 raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-data"), description="Invalid overridden instance"))
@@ -1135,4 +1136,7 @@
                         NumberOfRecurrencesWithinLimits(PCDATAElement(str(err.max_allowed)))
                     ))
             else:
+                # Important - we have to raise the original exception again, we cannot just use plain
+                # "raise" here as we have inlineCallbacks in use and those blow away the re-raised
+                # exception
                 raise err

Modified: CalendarServer/branches/more-deferreds-4/twistedcaldav/test/test_index.py
===================================================================
--- CalendarServer/branches/more-deferreds-4/twistedcaldav/test/test_index.py	2009-11-04 23:58:08 UTC (rev 4704)
+++ CalendarServer/branches/more-deferreds-4/twistedcaldav/test/test_index.py	2009-11-05 04:14:57 UTC (rev 4705)
@@ -16,7 +16,7 @@
 
 from twisted.internet import reactor
 from twisted.internet.task import deferLater
-from twisted.internet.defer import succeed
+from twisted.internet.defer import succeed, inlineCallbacks
 
 from twistedcaldav.ical import Component
 from twistedcaldav.index import Index, default_future_expansion_duration,\
@@ -101,6 +101,7 @@
         return d
 
 
+    @inlineCallbacks
     def test_index(self):
         data = (
             (
@@ -251,7 +252,7 @@
             else:
                 self.assertFalse(self.db.resourceExists(name), msg=description)
 
-        self.db.testAndUpdateIndex(datetime.date(2020, 1, 1))
+        yield self.db.testAndUpdateIndex(datetime.date(2020, 1, 1))
         for description, name, calendar_txt, reCreate, ok in data:
             if ok:
                 self.assertTrue(self.db.resourceExists(name), msg=description)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20091104/c225d996/attachment-0001.html>


More information about the calendarserver-changes mailing list