[CalendarServer-changes] [6432] CalendarServer/branches/users/glyph/more-deferreds-7
source_changes at macosforge.org
source_changes at macosforge.org
Sun Oct 17 05:25:08 PDT 2010
Revision: 6432
http://trac.macosforge.org/projects/calendarserver/changeset/6432
Author: glyph at apple.com
Date: 2010-10-17 05:25:04 -0700 (Sun, 17 Oct 2010)
Log Message:
-----------
fix issues discovered by CalDAVTester
Modified Paths:
--------------
CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/method/put_addressbook_common.py
CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/method/report_addressbook_query.py
CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/notifications.py
CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/resource.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/base/datastore/sql.py
CalendarServer/branches/users/glyph/more-deferreds-7/txdav/common/datastore/sql.py
CalendarServer/branches/users/glyph/more-deferreds-7/txdav/common/datastore/sql_legacy.py
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-10-17 08:21:32 UTC (rev 6431)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/method/put_addressbook_common.py 2010-10-17 12:25:04 UTC (rev 6432)
@@ -356,7 +356,7 @@
# Retrieve information from the source, in case we have to delete
# it.
sourceProperties = dict(source.newStoreProperties().iteritems())
- sourceText = source.vCardText()
+ sourceText = yield source.vCardText()
# Delete the original source if needed (for example, if this is a
# same-calendar MOVE of a calendar object, implemented as an
Modified: CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/method/report_addressbook_query.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/method/report_addressbook_query.py 2010-10-17 08:21:32 UTC (rev 6431)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/method/report_addressbook_query.py 2010-10-17 12:25:04 UTC (rev 6432)
@@ -214,7 +214,7 @@
index_query_ok = addrresource.index().searchValid(filter)
# Get list of children that match the search and have read access
- names = [name for name, ignore_uid in addrresource.index().search(filter)] #@UnusedVariable
+ names = [name for name, ignore_uid in (yield addrresource.index().search(filter))] #@UnusedVariable
if not names:
return
Modified: CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/notifications.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/notifications.py 2010-10-17 08:21:32 UTC (rev 6431)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/notifications.py 2010-10-17 12:25:04 UTC (rev 6432)
@@ -90,12 +90,15 @@
# Update database
self.notificationsDB().addOrUpdateRecord(NotificationRecord(uid, rname, xmltype.name))
+
def getNotifictionMessages(self, request, componentType=None, returnLatestVersion=True):
return succeed([])
+
def getNotifictionMessageByUID(self, request, uid):
return maybeDeferred(self.notificationsDB().recordForUID, uid)
+
@inlineCallbacks
def deleteNotifictionMessageByUID(self, request, uid):
@@ -104,6 +107,7 @@
if record:
yield self.deleteNotification(request, record)
+
@inlineCallbacks
def deleteNotifictionMessageByName(self, request, rname):
@@ -114,15 +118,17 @@
returnValue(None)
+
@inlineCallbacks
def deleteNotification(self, request, record):
yield self._deleteNotification(request, record.name)
- self.notificationsDB().removeRecordForUID(record.uid)
-
+ yield self.notificationsDB().removeRecordForUID(record.uid)
+
+
def removedNotifictionMessage(self, request, rname):
- self.notificationsDB().removeRecordForName(rname)
- return succeed(None)
-
+ return maybeDeferred(self.notificationsDB().removeRecordForName, rname)
+
+
class NotificationRecord(object):
def __init__(self, uid, name, xmltype):
Modified: CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/resource.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/resource.py 2010-10-17 08:21:32 UTC (rev 6431)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/resource.py 2010-10-17 12:25:04 UTC (rev 6432)
@@ -1566,9 +1566,6 @@
raise NotImplementedError
- def vCardXML(self, name=None):
- return carddavxml.AddressData.fromAddressData(self.vCardText(name))
-
def supportedPrivileges(self, request):
# read-free-busy support on calendar collection and calendar object resources
if self.isCollection():
@@ -2111,10 +2108,11 @@
# Do normal child types
returnValue((yield self.makeRegularChild(name)))
+
+ @inlineCallbacks
def createNotificationsCollection(self):
-
txn = self._associatedTransaction
- notifications = txn.notificationsWithUID(self._newStoreHome.uid())
+ notifications = yield txn.notificationsWithUID(self._newStoreHome.uid())
from twistedcaldav.storebridge import StoreNotificationCollectionResource
similar = StoreNotificationCollectionResource(
@@ -2123,7 +2121,7 @@
principalCollections = self.principalCollections(),
)
self.propagateTransaction(similar)
- return similar
+ returnValue(similar)
def makeRegularChild(self, name):
raise NotImplementedError
Modified: CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/sharing.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/sharing.py 2010-10-17 08:21:32 UTC (rev 6431)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/sharing.py 2010-10-17 12:25:04 UTC (rev 6432)
@@ -552,7 +552,7 @@
sharee = self.principalForCalendarUserAddress(record.userid)
if sharee is None:
raise ValueError("sharee is None but userid was valid before")
- notifications = self._associatedTransaction.notificationsWithUID(
+ notifications = yield self._associatedTransaction.notificationsWithUID(
sharee.principalUID()
)
Modified: CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/storebridge.py 2010-10-17 08:21:32 UTC (rev 6431)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/twistedcaldav/storebridge.py 2010-10-17 12:25:04 UTC (rev 6432)
@@ -24,7 +24,8 @@
from urlparse import urlsplit
-from twisted.internet.defer import succeed, inlineCallbacks, returnValue
+from twisted.internet.defer import succeed, inlineCallbacks, returnValue,\
+ maybeDeferred
from twisted.internet.protocol import Protocol
from twisted.python.log import err as logDefaultException
from twisted.python.util import FancyEqMixin
@@ -172,7 +173,7 @@
# FIXME: direct tests
try:
- md5 = self._newStoreObject.md5()
+ md5 = yield self._newStoreObject.md5()
if md5:
returnValue(ETag(md5))
else:
@@ -334,19 +335,24 @@
def name(self):
return self._newStoreCalendar.name()
+
+ @inlineCallbacks
def etag(self):
- return ETag(self._newStoreCalendar.md5())
+ returnValue(ETag((yield self._newStoreCalendar.md5())))
+
def lastModified(self):
return self._newStoreCalendar.modified()
+
def creationDate(self):
return self._newStoreCalendar.created()
+
def getSyncToken(self):
return self._newStoreCalendar.syncToken()
-
+
def provisionFile(self):
pass
@@ -498,7 +504,7 @@
that refer to permissions not referenced by attendees in the iCalendar
data.
"""
- attendees = self._newStoreCalendarObject.component().getAttendees()
+ attendees = (yield self._newStoreCalendarObject.component()).getAttendees()
attendees = [attendee.split("urn:uuid:")[-1] for attendee in attendees]
document = yield davXMLFromStream(request.stream)
for ace in document.root_element.children:
@@ -553,7 +559,7 @@
yield self._newStoreCalendarObject.attendeesCanManageAttachments()
)
originalACEs = list(originalACL.children)
- cuas = (self._newStoreCalendarObject.component()).getAttendees()
+ cuas = (yield self._newStoreCalendarObject.component()).getAttendees()
newACEs = []
for calendarUserAddress in cuas:
principal = self.principalForCalendarUserAddress(
@@ -650,10 +656,11 @@
self._newStoreAttachment = self._newStoreObject = attachment
+ @inlineCallbacks
def etag(self):
# FIXME: test
- md5 = self._newStoreAttachment.md5()
- return ETag(md5)
+ md5 = yield self._newStoreAttachment.md5()
+ returnValue(ETag(md5))
def contentType(self):
@@ -733,18 +740,24 @@
def name(self):
return self._newStoreCalendar.name()
+
+ @inlineCallbacks
def etag(self):
- return ETag(self._newStoreCalendar.md5())
+ returnValue(ETag((yield self._newStoreCalendar.md5())))
+
def lastModified(self):
return self._newStoreCalendar.modified()
+
def creationDate(self):
return self._newStoreCalendar.created()
+
def getSyncToken(self):
return self._newStoreCalendar.syncToken()
+
def isCollection(self):
return True
@@ -773,7 +786,7 @@
isowner = (yield self.isOwner(request, adminprincipals=True, readprincipals=True))
accessPrincipal = (yield self.resourceOwnerPrincipal(request))
- for name, uid, type in self.index().bruteForceSearch(): #@UnusedVariable
+ for name, uid, type in (yield self.index().bruteForceSearch()): #@UnusedVariable
try:
child = yield request.locateChildResource(self, name)
except TypeError:
@@ -807,7 +820,7 @@
# Cache the data
data = str(calendar)
- data = self.getSyncToken() + "\r\n" + data
+ data = (yield self.getSyncToken()) + "\r\n" + data
returnValue(calendar)
@@ -1443,18 +1456,24 @@
def name(self):
return self._newStoreAddressBook.name()
+
+ @inlineCallbacks
def etag(self):
- return ETag(self._newStoreAddressBook.md5())
+ returnValue(ETag((yield self._newStoreAddressBook.md5())))
+
def lastModified(self):
return self._newStoreAddressBook.modified()
+
def creationDate(self):
return self._newStoreAddressBook.created()
+
def getSyncToken(self):
return self._newStoreAddressBook.syncToken()
+
def isCollection(self):
return True
@@ -1710,9 +1729,10 @@
return True
+ @inlineCallbacks
def quotaSize(self, request):
# FIXME: tests
- return succeed(len(self._newStoreObject.vCardText()))
+ returnValue(len((yield self._newStoreObject.vCardText())))
def vCardText(self, ignored=None):
@@ -1724,13 +1744,15 @@
return self.vCardText()
+ @inlineCallbacks
def render(self, request):
- output = self.vCardText()
+ output = yield self.vCardText()
response = Response(200, {}, output)
response.headers.setHeader("content-type", self.contentType())
- return response
+ returnValue(response)
+
@requiresPermissions(fromParent=[davxml.Unbind()])
def http_DELETE(self, request):
"""
@@ -1901,12 +1923,15 @@
self._initializeWithNotifications(notifications, home)
+ @inlineCallbacks
def makeChild(self, name):
"""
- Create a L{NotificationObjectFile} or L{ProtoNotificationObjectFile} based on a
- path object.
+ Create a L{NotificationObjectFile} or L{ProtoNotificationObjectFile}
+ based on the name of a notification.
"""
- newStoreObject = self._newStoreNotifications.notificationObjectWithName(name)
+ newStoreObject = (
+ yield self._newStoreNotifications.notificationObjectWithName(name)
+ )
if newStoreObject is not None:
similar = StoreNotificationObjectFile(newStoreObject, self)
@@ -1919,7 +1944,7 @@
# FIXME: tests should be failing without this line.
# Specifically, http_PUT won't be committing its transaction properly.
self.propagateTransaction(similar)
- return similar
+ returnValue(similar)
@inlineCallbacks
@@ -1969,15 +1994,21 @@
def _indexWhatChanged(self, revision, depth):
return self._newStoreNotifications.resourceNamesSinceToken(revision)
+
def addNotification(self, request, uid, xmltype, xmldata):
+ return maybeDeferred(
+ self._newStoreNotifications.writeNotificationObject,
+ uid, xmltype, xmldata
+ )
- self._newStoreNotifications.writeNotificationObject(uid, xmltype, xmldata)
- return succeed(None)
def deleteNotification(self, request, record):
- self._newStoreNotifications.removeNotificationObjectWithName(record.name)
- return succeed(None)
+ return maybeDeferred(
+ self._newStoreNotifications.removeNotificationObjectWithName,
+ record.name
+ )
+
class StoreProtoNotificationCollectionResource(NotificationCollectionResource):
"""
A resource representing a notification collection which hasn't yet been created.
@@ -2076,6 +2107,7 @@
return True
+ @inlineCallbacks
def etag(self):
# FIXME: far too slow to be used for real, but I needed something to
# placate the etag computation in the case where the file doesn't exist
@@ -2083,20 +2115,21 @@
# FIXME: direct tests
try:
- md5 = self._newStoreObject.md5()
+ md5 = yield self._newStoreObject.md5()
if md5:
- return ETag(md5)
+ returnValue(ETag(md5))
else:
- return ETag(
- hashlib.new("md5", self.text()).hexdigest(),
+ returnValue(ETag(
+ hashlib.new("md5", (yield self.text())).hexdigest(),
weak=False
- )
+ ))
except NoSuchObjectResourceError:
# FIXME: a workaround for the fact that DELETE still rudely vanishes
# the calendar object out from underneath the store, and doesn't
# call storeRemove.
- return None
+ returnValue(None)
+
def contentType(self):
return self._newStoreObject.contentType()
@@ -2109,13 +2142,15 @@
def creationDate(self):
return self._newStoreObject.created()
+
def newStoreProperties(self):
return self._newStoreObject.properties()
+ @inlineCallbacks
def quotaSize(self, request):
# FIXME: tests
- return succeed(len(self._newStoreObject.xmldata()))
+ returnValue(len((yield self._newStoreObject.xmldata())))
def text(self, ignored=None):
@@ -2124,9 +2159,14 @@
@requiresPermissions(davxml.Read())
+ @inlineCallbacks
def http_GET(self, request):
- return Response(OK, {"content-type":self.contentType()}, MemoryStream(self.text()))
+ returnValue(
+ Response(OK, {"content-type":self.contentType()},
+ MemoryStream((yield self.text())))
+ )
+
@requiresPermissions(fromParent=[davxml.Unbind()])
def http_DELETE(self, request):
"""
Modified: CalendarServer/branches/users/glyph/more-deferreds-7/txdav/base/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/txdav/base/datastore/sql.py 2010-10-17 08:21:32 UTC (rev 6431)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/txdav/base/datastore/sql.py 2010-10-17 12:25:04 UTC (rev 6432)
@@ -13,12 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
##
-from twisted.internet.defer import Deferred
"""
Logic common to SQL implementations.
"""
+from twisted.internet.defer import Deferred
from inspect import getargspec
def _getarg(argname, argspec, args, kw):
Modified: CalendarServer/branches/users/glyph/more-deferreds-7/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/glyph/more-deferreds-7/txdav/common/datastore/sql.py 2010-10-17 08:21:32 UTC (rev 6431)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/txdav/common/datastore/sql.py 2010-10-17 12:25:04 UTC (rev 6432)
@@ -602,13 +602,13 @@
@inlineCallbacks
def syncToken(self):
- revision = yield self._txn.execSQL(
+ revision = (yield self._txn.execSQL(
"""
select max(%(column_REVISION)s) from %(name)s
where %(column_HOME_RESOURCE_ID)s = %%s
""" % self._revisionsTable,
[self._resourceID,]
- )[0][0]
+ ))[0][0]
returnValue("%s#%s" % (self._resourceID, revision))
@@ -896,13 +896,13 @@
@inlineCallbacks
def syncToken(self):
- revision = yield self._txn.execSQL(
+ revision = (yield self._txn.execSQL(
"""
select %(column_REVISION)s from %(name)s
where %(column_RESOURCE_ID)s = %%s and %(column_RESOURCE_NAME)s is null
""" % self._revisionsTable,
[self._resourceID,]
- )[0][0]
+ ))[0][0]
returnValue(("%s#%s" % (self._resourceID, revision,)))
@@ -1337,9 +1337,13 @@
def uid(self):
return self._uid
+
+ @inlineCallbacks
def notificationObjects(self):
- for name in self.listNotificationObjects():
- yield self.notificationObjectWithName(name)
+ L = []
+ for name in (yield self.listNotificationObjects()):
+ L.append((yield self.notificationObjectWithName(name)))
+ returnValue(L)
@inlineCallbacks
@@ -1372,7 +1376,7 @@
[uid, self._resourceID]))
if rows:
resourceID = rows[0][0]
- no = NotificationObject(self, resourceID)
+ no = NotificationObject(self, uid, resourceID)
yield no._loadPropertyStore()
returnValue(no)
else:
@@ -1385,7 +1389,7 @@
inserting = False
notificationObject = yield self.notificationObjectWithUID(uid)
if notificationObject is None:
- notificationObject = NotificationObject(self, None)
+ notificationObject = NotificationObject(self, uid, None)
inserting = True
yield notificationObject.setData(uid, xmltype, xmldata, inserting=inserting)
if inserting:
@@ -1421,13 +1425,13 @@
@inlineCallbacks
def syncToken(self):
- revision = yield self._txn.execSQL(
+ revision = (yield self._txn.execSQL(
"""
select %(column_REVISION)s from %(name)s
where %(column_HOME_RESOURCE_ID)s = %%s and %(column_RESOURCE_NAME)s is null
""" % self._revisionsTable,
[self._resourceID,]
- )[0][0]
+ ))[0][0]
returnValue("%s#%s" % (self._resourceID, revision,))
@@ -1576,8 +1580,9 @@
compareAttributes = '_resourceID _home'.split()
- def __init__(self, home, resourceID):
+ def __init__(self, home, uid, resourceID):
self._home = home
+ self._uid = uid
self._resourceID = resourceID
@@ -1594,6 +1599,10 @@
return self._home
+ def uid(self):
+ return self._uid
+
+
def name(self):
return self.uid() + ".xml"
@@ -1633,10 +1642,6 @@
return self._fieldQuery("XML_DATA")
- def uid(self):
- return self._fieldQuery("NOTIFICATION_UID")
-
-
def properties(self):
return self._propertyStore
@@ -1661,6 +1666,7 @@
),
)
+
def contentType(self):
"""
The content type of NotificationObjects is text/xml.
@@ -1668,8 +1674,9 @@
return MimeType.fromString("text/xml")
+ @inlineCallbacks
def md5(self):
- return hashlib.md5(self.xmldata()).hexdigest()
+ returnValue(hashlib.md5((yield self.xmldata())).hexdigest())
@inlineCallbacks
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-10-17 08:21:32 UTC (rev 6431)
+++ CalendarServer/branches/users/glyph/more-deferreds-7/txdav/common/datastore/sql_legacy.py 2010-10-17 12:25:04 UTC (rev 6432)
@@ -63,11 +63,18 @@
self._collection = notificationsCollection
+ @inlineCallbacks
def _recordForObject(self, notificationObject):
- return NotificationRecord(
- notificationObject.uid(),
- notificationObject.name(),
- notificationObject._fieldQuery("XML_TYPE")) if notificationObject else None
+ if notificationObject:
+ returnValue(
+ NotificationRecord(
+ notificationObject.uid(),
+ notificationObject.name(),
+ (yield notificationObject._fieldQuery("XML_TYPE"))
+ )
+ )
+ else:
+ returnValue(None)
def recordForName(self, name):
@@ -76,18 +83,19 @@
)
+ @inlineCallbacks
def recordForUID(self, uid):
- return self._recordForObject(
- self._collection.notificationObjectWithUID(uid)
- )
+ returnValue((yield self._recordForObject(
+ (yield self._collection.notificationObjectWithUID(uid))
+ )))
def removeRecordForUID(self, uid):
- self._collection.removeNotificationObjectWithUID(uid)
+ return self._collection.removeNotificationObjectWithUID(uid)
def removeRecordForName(self, name):
- self._collection.removeNotificationObjectWithName(name)
+ return self._collection.removeNotificationObjectWithName(name)
@@ -514,8 +522,8 @@
splithost = record.hosturl.split('/')
ownerUID = splithost[3]
ownerCollectionName = splithost[4]
- ownerHome = self._getHomeWithUID(ownerUID)
- ownerCollection = ownerHome.childWithName(ownerCollectionName)
+ ownerHome = yield self._getHomeWithUID(ownerUID)
+ ownerCollection = yield ownerHome.childWithName(ownerCollectionName)
collectionResourceID = ownerCollection._resourceID
if record.sharetype == 'I':
@@ -524,7 +532,7 @@
# invitation. The invitation's UID is the same as the share UID. I
# just need to update its 'localname', i.e.
# XXX_BIND.XXX_RESOURCE_NAME.
-
+
yield self._txn.execSQL(
"""
update %(name)s
@@ -535,7 +543,6 @@
[record.localname, self._home._resourceID, collectionResourceID]
)
elif record.sharetype == 'D':
-
# There is no bind entry already so add one.
yield self._txn.execSQL(
@@ -939,7 +946,7 @@
"""
obj = yield self.calendar.calendarObjectWithName(name)
yield obj.updateDatabase(
- obj.component(), expand_until=expand_until, reCreate=True
+ (yield obj.component()), expand_until=expand_until, reCreate=True
)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20101017/e12648ba/attachment-0001.html>
More information about the calendarserver-changes
mailing list