[CalendarServer-changes] [2668] CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jul 7 14:14:06 PDT 2008
Revision: 2668
http://trac.macosforge.org/projects/calendarserver/changeset/2668
Author: cdaboo at apple.com
Date: 2008-07-07 14:14:05 -0700 (Mon, 07 Jul 2008)
Log Message:
-----------
Kill all deferredGenerators in favor of inlineCallbacks. This will simplify things as we move forward.
Modified Paths:
--------------
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/directory/principal.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/extensions.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/fileops.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/freebusyurl.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/itip.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/copymove.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/get.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/mkcalendar.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/propfind.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/put.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/put_common.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_calquery.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_common.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_freebusy.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_multiget.py
CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/resource.py
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/directory/principal.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/directory/principal.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -32,9 +32,8 @@
from urlparse import urlparse
from twisted.python.failure import Failure
-from twisted.internet.defer import deferredGenerator
+from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.internet.defer import succeed
-from twisted.internet.defer import waitForDeferred
from twisted.web2 import responsecode
from twisted.web2.http import HTTPError
from twisted.web2.dav import davxml
@@ -145,7 +144,7 @@
return self.getChild(uidsResourceName).getChild(uid)
def _principalForURI(self, uri):
- scheme, netloc, path, params, query, fragment = urlparse(uri)
+ scheme, netloc, path, _ignore_params, _ignore_query, _ignore_fragment = urlparse(uri)
if scheme == "":
pass
@@ -411,22 +410,16 @@
# HTTP
##
- @deferredGenerator
+ @inlineCallbacks
def renderDirectoryBody(self, request):
- d = waitForDeferred(super(DirectoryPrincipalResource, self).renderDirectoryBody(request))
- yield d
- output = d.getResult()
+ output = (yield super(DirectoryPrincipalResource, self).renderDirectoryBody(request))
- d = waitForDeferred(self.groupMembers())
- yield d
- members = d.getResult()
+ members = (yield self.groupMembers())
- d = waitForDeferred(self.groupMemberships())
- yield d
- memberships = d.getResult()
+ memberships = (yield self.groupMemberships())
- yield "".join((
+ returnValue("".join((
"""<div class="directory-listing">"""
"""<h1>Principal Details</h1>"""
"""<pre><blockquote>"""
@@ -448,7 +441,7 @@
"""\nGroup memberships:\n""" , format_principals(memberships),
"""</pre></blockquote></div>""",
output
- ))
+ )))
##
# DAV
@@ -502,7 +495,6 @@
if record not in records:
records.add(record)
- myRecordType = self.record.recordType
for relative in getattr(record, method)():
if relative not in records:
found = self.parent.principalForRecord(relative)
@@ -523,7 +515,7 @@
def groupMembers(self):
return succeed(self._getRelatives("members"))
- @deferredGenerator
+ @inlineCallbacks
def groupMemberships(self):
groups = self._getRelatives("groups")
@@ -534,9 +526,7 @@
# Get proxy group UIDs and map to principal resources
proxies = []
- d = waitForDeferred(self._calendar_user_proxy_index().getMemberships(self.principalUID()))
- yield d
- memberships = d.getResult()
+ memberships = (yield self._calendar_user_proxy_index().getMemberships(self.principalUID()))
for uid in memberships:
subprincipal = self.parent.principalForUID(uid)
if subprincipal:
@@ -544,7 +534,7 @@
groups.update(proxies)
- yield groups
+ returnValue(groups)
def principalCollections(self):
return self.parent.principalCollections()
@@ -580,22 +570,16 @@
"""
Directory calendar principal resource.
"""
- @deferredGenerator
+ @inlineCallbacks
def renderDirectoryBody(self, request):
- d = waitForDeferred(super(DirectoryPrincipalResource, self).renderDirectoryBody(request))
- yield d
- output = d.getResult()
+ output = (yield super(DirectoryPrincipalResource, self).renderDirectoryBody(request))
- d = waitForDeferred(self.groupMembers())
- yield d
- members = d.getResult()
+ members = (yield self.groupMembers())
- d = waitForDeferred(self.groupMemberships())
- yield d
- memberships = d.getResult()
+ memberships = (yield self.groupMemberships())
- yield "".join((
+ returnValue("".join((
"""<div class="directory-listing">"""
"""<h1>Principal Details</h1>"""
"""<pre><blockquote>"""
@@ -619,7 +603,7 @@
"""\nCalendar user addresses:\n""" , format_list(format_link(a) for a in self.calendarUserAddresses()),
"""</pre></blockquote></div>""",
output
- ))
+ )))
##
# CalDAV
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/extensions.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/extensions.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/extensions.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -33,7 +33,7 @@
import cgi
import time
-from twisted.internet.defer import succeed, deferredGenerator, waitForDeferred, DeferredList
+from twisted.internet.defer import succeed, DeferredList, inlineCallbacks, returnValue
from twisted.internet.defer import maybeDeferred
from twisted.web2 import responsecode
from twisted.web2.http import HTTPError, Response, RedirectResponse
@@ -118,6 +118,7 @@
return super(SudoSACLMixin, self).findPrincipalForAuthID(authid)
+ @inlineCallbacks
def authorizationPrincipal(self, request, authid, authnPrincipal):
"""
Determine the authorization principal for the given request and authentication principal.
@@ -165,8 +166,7 @@
if authzPrincipal is not None:
log.msg("Allow proxy: user '%s' as '%s'" % (authid, authz,))
- yield authzPrincipal
- return
+ returnValue(authzPrincipal)
else:
log.msg("Could not find authorization user id: '%s'" %
(authz,))
@@ -179,14 +179,10 @@
raise HTTPError(responsecode.FORBIDDEN)
else:
# No proxy - do default behavior
- d = waitForDeferred(super(SudoSACLMixin, self).authorizationPrincipal(request, authid, authnPrincipal))
- yield d
- yield d.getResult()
- return
+ result = (yield super(SudoSACLMixin, self).authorizationPrincipal(request, authid, authnPrincipal))
+ returnValue(result)
- authorizationPrincipal = deferredGenerator(authorizationPrincipal)
-
def updateCacheTokenOnCallback(f):
def fun(self, *args, **kwargs):
def _updateToken(response):
@@ -222,7 +218,8 @@
def http_ACL(self, request):
return super(DAVResource, self).http_ACL(request)
-
+
+ @inlineCallbacks
def findChildrenFaster(self, depth, request, okcallback, badcallback, names, privileges, inherited_aces):
"""
See L{IDAVResource.findChildren}.
@@ -244,14 +241,11 @@
assert depth in ("0", "1", "infinity"), "Invalid depth: %s" % (depth,)
if depth == "0" or not self.isCollection():
- yield None
- return
+ returnValue(None)
# First find all depth 1 children
#children = []
- #d = waitForDeferred(self.findChildren("1", request, lambda x, y: children.append((x, y)), privileges=None, inherited_aces=None))
- #yield d
- #d.getResult()
+ #yield self.findChildren("1", request, lambda x, y: children.append((x, y)), privileges=None, inherited_aces=None)
children = []
basepath = request.urlForResource(self)
@@ -260,9 +254,7 @@
if names and childname not in names:
continue
childpath = joinURL(basepath, childname)
- d = waitForDeferred(request.locateChildResource(self, childname))
- yield d
- child = d.getResult()
+ child = (yield request.locateChildResource(self, childname))
if child is None:
children.append((None, childpath + "/"))
else:
@@ -274,21 +266,15 @@
# Generate (acl,supported_privs) map
aclmap = {}
for resource, url in children:
- acl = waitForDeferred(resource.accessControlList(request, inheritance=False, inherited_aces=inherited_aces))
- yield acl
- acl = acl.getResult()
- supportedPrivs = waitForDeferred(resource.supportedPrivileges(request))
- yield supportedPrivs
- supportedPrivs = supportedPrivs.getResult()
+ acl = (yield resource.accessControlList(request, inheritance=False, inherited_aces=inherited_aces))
+ supportedPrivs = (yield resource.supportedPrivileges(request))
aclmap.setdefault((pickle.dumps(acl), supportedPrivs), (acl, supportedPrivs, []))[2].append((resource, url))
# Now determine whether each ace satisfies privileges
#print aclmap
allowed_collections = []
for items in aclmap.itervalues():
- checked = waitForDeferred(self.checkACLPrivilege(request, items[0], items[1], privileges, inherited_aces))
- yield checked
- checked = checked.getResult()
+ checked = (yield self.checkACLPrivilege(request, items[0], items[1], privileges, inherited_aces))
if checked:
for resource, url in items[2]:
if okcallback:
@@ -303,22 +289,16 @@
# TODO: Depth: infinity support
if depth == "infinity":
for collection, url in allowed_collections:
- collection_inherited_aces = waitForDeferred(collection.inheritedACEsforChildren(request))
- yield collection_inherited_aces
- collection_inherited_aces = collection_inherited_aces.getResult()
- d = waitForDeferred(collection.findChildrenFaster(depth, request, okcallback, badcallback, names, privileges, inherited_aces=collection_inherited_aces))
- yield d
- d.getResult()
+ collection_inherited_aces = (yield collection.inheritedACEsforChildren(request))
+ yield collection.findChildrenFaster(depth, request, okcallback, badcallback, names, privileges, inherited_aces=collection_inherited_aces)
- yield None
-
- findChildrenFaster = deferredGenerator(findChildrenFaster)
+ returnValue(None)
+ @inlineCallbacks
def checkACLPrivilege(self, request, acl, privyset, privileges, inherited_aces):
if acl is None:
- yield False
- return
+ returnValue(False)
principal = self.currentPrincipal(request)
@@ -338,9 +318,7 @@
if not self.matchPrivilege(davxml.Privilege(privilege), ace.privileges, privyset):
continue
- match = waitForDeferred(self.matchPrincipal(principal, ace.principal, request))
- yield match
- match = match.getResult()
+ match = (yield self.matchPrincipal(principal, ace.principal, request))
if match:
if ace.invert:
@@ -354,10 +332,8 @@
if not ace.allow:
denied.append(privilege)
- yield len(denied) + len(pending) == 0
+ returnValue(len(denied) + len(pending) == 0)
- checkACLPrivilege = deferredGenerator(checkACLPrivilege)
-
def fullAccessControlList(self, acl, inherited_aces):
"""
See L{IDAVResource.accessControlList}.
@@ -395,7 +371,7 @@
return acl
- @deferredGenerator
+ @inlineCallbacks
def matchPrincipal(self, principal1, principal2, request):
"""
Implementation of DAVResource.matchPrincipal that caches the principal match
@@ -412,12 +388,10 @@
match = request.matchPrincipalCache.get(cache_key, None)
if match is None:
- match = waitForDeferred(super(DAVResource, self).matchPrincipal(principal1, principal2, request))
- yield match
- match = match.getResult()
+ match = (yield super(DAVResource, self).matchPrincipal(principal1, principal2, request))
request.matchPrincipalCache[cache_key] = match
- yield match
+ returnValue(match)
class DAVPrincipalResource (SuperDAVPrincipalResource, LoggingMixIn):
"""
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/fileops.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/fileops.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/fileops.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -13,15 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
##
-from twisted.internet.defer import deferredGenerator
-from twisted.web2.dav.fileop import put
-from twisted.internet.defer import waitForDeferred
-from twisted.web2.dav.fileop import copy
"""
Various file utilities.
"""
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.web2.dav.fileop import copy
+from twisted.web2.dav.fileop import put
from twisted.web2.dav.xattrprops import xattrPropertyStore
# This class simulates a DAVFile with enough information for use with xattrPropertyStore.
@@ -30,7 +29,7 @@
def __init__(self, fp):
self.fp = fp
- at deferredGenerator
+ at inlineCallbacks
def putWithXAttrs(stream, filepath):
"""
Write a file to a possibly existing path and preserve any xattrs at that path.
@@ -50,9 +49,7 @@
xold = None
# First do the actual file copy
- d = waitForDeferred(put(stream, filepath))
- yield d
- response = d.getResult()
+ response = (yield put(stream, filepath))
# Restore original xattrs.
if props:
@@ -61,9 +58,9 @@
xnew.set(prop)
xnew = None
- yield response
+ returnValue(response)
- at deferredGenerator
+ at inlineCallbacks
def copyWithXAttrs(source_filepath, destination_filepath, destination_uri):
"""
Copy a file from one path to another and also copy xattrs we care about.
@@ -77,14 +74,12 @@
"""
# First do the actual file copy
- d = waitForDeferred(copy(source_filepath, destination_filepath, destination_uri, "0"))
- yield d
- response = d.getResult()
+ response = (yield copy(source_filepath, destination_filepath, destination_uri, "0"))
# Now copy over xattrs.
copyXAttrs(source_filepath, destination_filepath)
- yield response
+ returnValue(response)
def copyToWithXAttrs(from_fp, to_fp):
"""
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/freebusyurl.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/freebusyurl.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/freebusyurl.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -22,8 +22,7 @@
"FreeBusyURLResource",
]
-from twisted.internet.defer import deferredGenerator
-from twisted.internet.defer import waitForDeferred
+from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.python import log
from twisted.web2 import responsecode
from twisted.web2.dav import davxml
@@ -128,15 +127,13 @@
"""
return self._processFBURL(request)
- @deferredGenerator
+ @inlineCallbacks
def _processFBURL(self, request):
#
# Check authentication and access controls
#
- x = waitForDeferred(self.authorize(request, (davxml.Read(),)))
- yield x
- x.getResult()
+ yield self.authorize(request, (davxml.Read(),))
# Extract query parameters from the URL
args = ('start', 'end', 'duration', 'token', 'format', 'user',)
@@ -212,9 +209,7 @@
if inboxURL is None:
raise HTTPError(StatusResponse(responsecode.INTERNAL_SERVER_ERROR, "No schedule inbox URL for principal: %s" % (principal,)))
try:
- inbox = waitForDeferred(request.locateResource(inboxURL))
- yield inbox
- inbox = inbox.getResult()
+ inbox = (yield request.locateResource(inboxURL))
except:
log.err("No schedule inbox for principal: %s" % (principal,))
inbox = None
@@ -230,18 +225,16 @@
attendeeProp = Property("ATTENDEE", scheduler.organizer.cuaddr)
- d = waitForDeferred(scheduler.generateAttendeeFreeBusyResponse(
+ fbresult = (yield scheduler.generateAttendeeFreeBusyResponse(
scheduler.organizer,
None,
None,
attendeeProp,
True,
))
- yield d
- fbresult = d.getResult()
response = Response()
response.stream = MemoryStream(str(fbresult))
response.headers.setHeader("content-type", MimeType.fromString("%s; charset=utf-8" % (self.format,)))
- yield response
+ returnValue(response)
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/itip.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/itip.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/itip.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -72,7 +72,7 @@
@param inbox: the L{ScheduleInboxFile} for the principal's Inbox.
@param calendar: the L{Component} for the iTIP message we are processing.
@param child: the L{CalDAVFile} for the iTIP message resource already saved to the Inbox.
- @return: L{Deferred} that is a L{deferredGenerator}
+ @return: L{Deferred}
"""
method = calendar.propertyValue("METHOD")
@@ -99,7 +99,6 @@
def processRequest(self):
"""
Process a METHOD=REQUEST.
- This is a deferredGenerator function so use yield whenever we have a deferred.
Steps:
@@ -253,7 +252,6 @@
def processAdd(self):
"""
Process a METHOD=ADD.
- This is a deferredGenerator function so use yield whenever we have a deferred.
"""
log.info("Auto-processing iTIP ADD for: %s" % (str(self.principal),))
@@ -263,7 +261,6 @@
def processCancel(self):
"""
Process a METHOD=CANCEL.
- This is a deferredGenerator function so use yield whenever we have a deferred.
Policy find all components that match UID, SEQ and R-ID and remove them.
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/copymove.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/copymove.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/copymove.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -22,7 +22,7 @@
from urlparse import urlsplit
-from twisted.internet.defer import deferredGenerator, waitForDeferred
+from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.web2 import responsecode
from twisted.web2.filter.location import addLocation
from twisted.web2.dav import davxml
@@ -37,6 +37,7 @@
log = Logger()
+ at inlineCallbacks
def http_COPY(self, request):
"""
Special handling of COPY request if parents are calendar collections.
@@ -45,35 +46,22 @@
the destination if its a calendar collection.
"""
- r = waitForDeferred(checkForCalendarAction(self, request))
- yield r
- result, sourcecal, sourceparent, destination_uri, destination, destinationcal, destinationparent = r.getResult()
+ result, sourcecal, sourceparent, destination_uri, destination, destinationcal, destinationparent = (yield checkForCalendarAction(self, request))
if not result or not destinationcal:
# Do default WebDAV action
- d = waitForDeferred(super(CalDAVFile, self).http_COPY(request))
- yield d
- yield d.getResult()
- return
+ result = (yield super(CalDAVFile, self).http_COPY(request))
+ returnValue(result)
#
# Check authentication and access controls
#
- x = waitForDeferred(self.authorize(request, (davxml.Read(),), recurse=True))
- yield x
- x.getResult()
+ yield self.authorize(request, (davxml.Read(),), recurse=True)
if destination.exists():
- x = waitForDeferred(destination.authorize(request, (davxml.WriteContent(), davxml.WriteProperties()), recurse=True))
- yield x
- x.getResult()
+ yield destination.authorize(request, (davxml.WriteContent(), davxml.WriteProperties()), recurse=True)
else:
- destparent = waitForDeferred(request.locateResource(parentForURL(destination_uri)))
- yield destparent
- destparent = destparent.getResult()
-
- x = waitForDeferred(destparent.authorize(request, (davxml.Bind(),)))
- yield x
- x.getResult()
+ destparent = (yield request.locateResource(parentForURL(destination_uri)))
+ yield destparent.authorize(request, (davxml.Bind(),))
# Check for existing destination resource
overwrite = request.headers.getHeader("overwrite", True)
@@ -112,12 +100,10 @@
destinationparent = destinationparent,
destinationcal = destinationcal,
)
- x = waitForDeferred(storer.run())
- yield x
- yield x.getResult()
+ result = (yield storer.run())
+ returnValue(result)
-http_COPY = deferredGenerator(http_COPY)
-
+ at inlineCallbacks
def http_MOVE(self, request):
"""
Special handling of MOVE request if parent is a calendar collection.
@@ -125,40 +111,24 @@
since its effectively being deleted. We do need to do an index update for
the destination if its a calendar collection
"""
- r = waitForDeferred(checkForCalendarAction(self, request))
- yield r
- result, sourcecal, sourceparent, destination_uri, destination, destinationcal, destinationparent = r.getResult()
+ result, sourcecal, sourceparent, destination_uri, destination, destinationcal, destinationparent = (yield checkForCalendarAction(self, request))
if not result:
# Do default WebDAV action
- d = waitForDeferred(super(CalDAVFile, self).http_MOVE(request))
- yield d
- yield d.getResult()
- return
+ result = (yield super(CalDAVFile, self).http_MOVE(request))
+ returnValue(result)
#
# Check authentication and access controls
#
- parent = waitForDeferred(request.locateResource(parentForURL(request.uri)))
- yield parent
- parent = parent.getResult()
+ parent = (yield request.locateResource(parentForURL(request.uri)))
+ yield parent.authorize(request, (davxml.Unbind(),))
- x = waitForDeferred(parent.authorize(request, (davxml.Unbind(),)))
- yield x
- x.getResult()
-
if destination.exists():
- x = waitForDeferred(destination.authorize(request, (davxml.Bind(), davxml.Unbind()), recurse=True))
- yield x
- x.getResult()
+ yield destination.authorize(request, (davxml.Bind(), davxml.Unbind()), recurse=True)
else:
- destparent = waitForDeferred(request.locateResource(parentForURL(destination_uri)))
- yield destparent
- destparent = destparent.getResult()
+ destparent = (yield request.locateResource(parentForURL(destination_uri)))
+ yield destparent.authorize(request, (davxml.Bind(),))
- x = waitForDeferred(destparent.authorize(request, (davxml.Bind(),)))
- yield x
- x.getResult()
-
# Check for existing destination resource
overwrite = request.headers.getHeader("overwrite", True)
if destination.exists() and not overwrite:
@@ -198,12 +168,10 @@
destinationparent = destinationparent,
destinationcal = destinationcal,
)
- x = waitForDeferred(storer.run())
- yield x
- yield x.getResult()
+ result = (yield storer.run())
+ returnValue(result)
-http_MOVE = deferredGenerator(http_MOVE)
-
+ at inlineCallbacks
def checkForCalendarAction(self, request):
"""
Check to see whether the source or destination of the copy/move
@@ -237,9 +205,7 @@
))
# Check for parent calendar collection
- sourceparent = waitForDeferred(request.locateResource(parentForURL(request.uri)))
- yield sourceparent
- sourceparent = sourceparent.getResult()
+ sourceparent = (yield request.locateResource(parentForURL(request.uri)))
if isCalendarCollectionResource(sourceparent):
result = True
sourcecal = True
@@ -254,19 +220,13 @@
log.err(msg)
raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, msg))
- destination = waitForDeferred(request.locateResource(destination_uri))
- yield destination
- destination = destination.getResult()
+ destination = (yield request.locateResource(destination_uri))
# Check for parent calendar collection
destination_uri = urlsplit(destination_uri)[2]
- destinationparent = waitForDeferred(request.locateResource(parentForURL(destination_uri)))
- yield destinationparent
- destinationparent = destinationparent.getResult()
+ destinationparent = (yield request.locateResource(parentForURL(destination_uri)))
if isCalendarCollectionResource(destinationparent):
result = True
destinationcal = True
- yield (result, sourcecal, sourceparent, destination_uri, destination, destinationcal, destinationparent)
-
-checkForCalendarAction = deferredGenerator(checkForCalendarAction)
+ returnValue((result, sourcecal, sourceparent, destination_uri, destination, destinationcal, destinationparent))
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/get.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/get.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/get.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -47,7 +47,7 @@
yield self.authorize(request, (davxml.Read(),))
# Non DAV:owner's have limited access to the data
- isowner = yield self.isOwner(request)
+ isowner = (yield self.isOwner(request))
if not isowner:
# Now "filter" the resource calendar data through the CALDAV:calendar-data element and apply
@@ -60,5 +60,5 @@
returnValue(response)
# Do normal GET behavior
- response = yield super(CalDAVFile, self).http_GET(request)
+ response = (yield super(CalDAVFile, self).http_GET(request))
returnValue(response)
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/mkcalendar.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/mkcalendar.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/mkcalendar.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -20,7 +20,7 @@
__all__ = ["http_MKCALENDAR"]
-from twisted.internet.defer import deferredGenerator, waitForDeferred
+from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.python.failure import Failure
from twisted.web2 import responsecode
from twisted.web2.dav import davxml
@@ -34,6 +34,7 @@
log = Logger()
+ at inlineCallbacks
def http_MKCALENDAR(self, request):
"""
Respond to a MKCALENDAR request.
@@ -43,14 +44,9 @@
#
# Check authentication and access controls
#
- parent = waitForDeferred(request.locateResource(parentForURL(request.uri)))
- yield parent
- parent = parent.getResult()
+ parent = (yield request.locateResource(parentForURL(request.uri)))
+ yield parent.authorize(request, (davxml.Bind(),))
- x = waitForDeferred(parent.authorize(request, (davxml.Bind(),)))
- yield x
- x.getResult()
-
if self.exists():
log.err("Attempt to create collection where file exists: %s"
% (self.fp.path,))
@@ -71,13 +67,8 @@
# Read request body
#
try:
- doc = waitForDeferred(davXMLFromStream(request.stream))
- yield doc
- doc = doc.getResult()
-
- result = waitForDeferred(self.createCalendar(request))
- yield result
- result = result.getResult()
+ doc = (yield davXMLFromStream(request.stream))
+ yield self.createCalendar(request)
except ValueError, e:
log.err("Error while handling MKCALENDAR: %s" % (e,))
raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
@@ -103,9 +94,7 @@
if property.qname() == (caldavxml.caldav_namespace, "supported-calendar-component-set"):
self.writeDeadProperty(property)
else:
- p = waitForDeferred(self.writeProperty(property, request))
- yield p
- p.getResult()
+ yield self.writeProperty(property, request)
except HTTPError:
errors.add(Failure(), property)
got_an_error = True
@@ -119,6 +108,4 @@
errors.error()
raise HTTPError(MultiStatusResponse([errors.response()]))
- yield responsecode.CREATED
-
-http_MKCALENDAR = deferredGenerator(http_MKCALENDAR)
+ returnValue(responsecode.CREATED)
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/propfind.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/propfind.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/propfind.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -28,7 +28,7 @@
__all__ = ["http_PROPFIND"]
from twisted.python.failure import Failure
-from twisted.internet.defer import deferredGenerator, waitForDeferred
+from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.web2.http import HTTPError
from twisted.web2 import responsecode
from twisted.web2.http import StatusResponse
@@ -45,6 +45,7 @@
findChildrenFaster method to optimize child privilege checking.
"""
+ at inlineCallbacks
def http_PROPFIND(self, request):
"""
Respond to a PROPFIND request. (RFC 2518, section 8.1)
@@ -56,17 +57,13 @@
#
# Check authentication and access controls
#
- x = waitForDeferred(self.authorize(request, (davxml.Read(),)))
- yield x
- x.getResult()
+ yield self.authorize(request, (davxml.Read(),))
#
# Read request body
#
try:
- doc = waitForDeferred(davXMLFromStream(request.stream))
- yield doc
- doc = doc.getResult()
+ doc = (yield davXMLFromStream(request.stream))
except ValueError, e:
log.err("Error while handling PROPFIND body: %s" % (e,))
raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
@@ -116,23 +113,16 @@
# Do some optimization of access control calculation by determining any inherited ACLs outside of
# the child resource loop and supply those to the checkPrivileges on each child.
- filtered_aces = waitForDeferred(self.inheritedACEsforChildren(request))
- yield filtered_aces
- filtered_aces = filtered_aces.getResult()
+ filtered_aces = (yield self.inheritedACEsforChildren(request))
resources = [(self, my_url)]
- d = self.findChildrenFaster(depth, request, lambda x, y: resources.append((x, y)), None, None, (davxml.Read(),), inherited_aces=filtered_aces)
- x = waitForDeferred(d)
- yield x
- x.getResult()
+ yield self.findChildrenFaster(depth, request, lambda x, y: resources.append((x, y)), None, None, (davxml.Read(),), inherited_aces=filtered_aces)
for resource, uri in resources:
if search_properties is "names":
try:
- resource_properties = waitForDeferred(resource.listProperties(request))
- yield resource_properties
- resource_properties = resource_properties.getResult()
+ resource_properties = (yield resource.listProperties(request))
except:
log.err("Unable to get properties for resource %r" % (resource,))
raise
@@ -147,21 +137,15 @@
}
if search_properties is "all":
- properties_to_enumerate = waitForDeferred(resource.listAllprop(request))
- yield properties_to_enumerate
- properties_to_enumerate = properties_to_enumerate.getResult()
+ properties_to_enumerate = (yield resource.listAllprop(request))
else:
properties_to_enumerate = search_properties
for property in properties_to_enumerate:
- has = waitForDeferred(resource.hasProperty(property, request))
- yield has
- has = has.getResult()
+ has = (yield resource.hasProperty(property, request))
if has:
try:
- resource_property = waitForDeferred(resource.readProperty(property, request))
- yield resource_property
- resource_property = resource_property.getResult()
+ resource_property = (yield resource.readProperty(property, request))
except:
f = Failure()
@@ -196,9 +180,8 @@
#
# Return response
#
- yield MultiStatusResponse(xml_responses)
+ returnValue(MultiStatusResponse(xml_responses))
-http_PROPFIND = deferredGenerator(http_PROPFIND)
##
# Utilities
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/put.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/put.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/put.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -20,7 +20,7 @@
__all__ = ["http_PUT"]
-from twisted.internet.defer import deferredGenerator, waitForDeferred
+from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.web2 import responsecode
from twisted.web2.dav.http import ErrorResponse
from twisted.web2.dav.util import allDataFromStream, parentForURL
@@ -33,12 +33,11 @@
log = Logger()
+ at inlineCallbacks
def http_PUT(self, request):
parentURL = parentForURL(request.uri)
- parent = waitForDeferred(request.locateResource(parentURL))
- yield parent
- parent = parent.getResult()
+ parent = (yield request.locateResource(parentURL))
if isPseudoCalendarCollectionResource(parent):
self.fp.restat(False)
@@ -51,9 +50,7 @@
# Read the calendar component from the stream
try:
- d = waitForDeferred(allDataFromStream(request.stream))
- yield d
- calendardata = d.getResult()
+ calendardata = (yield allDataFromStream(request.stream))
# We must have some data at this point
if calendardata is None:
@@ -68,18 +65,13 @@
destinationparent = parent,
calendar = calendardata,
)
- d = waitForDeferred(storer.run())
- yield d
- yield d.getResult()
- return
+ result = (yield storer.run())
+ returnValue(result)
except ValueError, e:
log.err("Error while handling (calendar) PUT: %s" % (e,))
raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
else:
- d = waitForDeferred(super(CalDAVFile, self).http_PUT(request))
- yield d
- yield d.getResult()
-
-http_PUT = deferredGenerator(http_PUT)
+ result = (yield super(CalDAVFile, self).http_PUT(request))
+ returnValue(result)
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/put_common.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/put_common.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/put_common.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -23,10 +23,8 @@
import types
from twisted.internet import reactor
-from twisted.internet.defer import Deferred
-from twisted.internet.defer import deferredGenerator
-from twisted.internet.defer import maybeDeferred
-from twisted.internet.defer import waitForDeferred
+from twisted.internet.defer import Deferred, inlineCallbacks
+from twisted.internet.defer import maybeDeferred, returnValue
from twisted.python import failure
from twisted.python.filepath import FilePath
from twisted.web2 import responsecode
@@ -146,7 +144,7 @@
self.uid = uid
self.uri = uri
- @deferredGenerator
+ @inlineCallbacks
def reserve(self):
# Lets use a deferred for this and loop a few times if we cannot reserve so that we give
@@ -154,32 +152,26 @@
failure_count = 0
while(failure_count < 10):
try:
- d = waitForDeferred(self.index.reserveUID(self.uid))
- yield d
- d.getResult()
+ yield self.index.reserveUID(self.uid)
self.reserved = True
break
except ReservationError:
self.reserved = False
failure_count += 1
- d = Deferred()
+ pause = Deferred()
def _timedDeferred():
- d.callback(True)
+ pause.callback(True)
reactor.callLater(0.5, _timedDeferred)
- pause = waitForDeferred(d)
yield pause
- pause.getResult()
if self.uri and not self.reserved:
raise HTTPError(StatusResponse(responsecode.CONFLICT, "Resource: %s currently in use." % (self.uri,)))
- @deferredGenerator
+ @inlineCallbacks
def unreserve(self):
if self.reserved:
- d = waitForDeferred(self.index.unreserveUID(self.uid))
- yield d
- d.getResult()
+ yield self.index.unreserveUID(self.uid)
self.reserved = False
def __init__(
@@ -247,7 +239,7 @@
self.rollback = None
self.access = None
- @deferredGenerator
+ @inlineCallbacks
def fullValidation(self):
"""
Do full validation of source and destination calendar data.
@@ -313,9 +305,7 @@
# Check access
if self.destinationcal and config.EnablePrivateEvents:
- d = waitForDeferred(self.validAccess())
- yield d
- d.getResult()
+ yield self.validAccess()
def validResourceName(self):
"""
@@ -398,7 +388,7 @@
return result, message
- @deferredGenerator
+ @inlineCallbacks
def validAccess(self):
"""
Make sure that the X-CALENDARSERVER-ACCESS property is properly dealt with.
@@ -412,9 +402,7 @@
raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (calendarserver_namespace, "valid-access-restriction")))
# Only DAV:owner is able to set the property to other than PUBLIC
- d = waitForDeferred(self.destinationparent.owner(self.request))
- yield d
- parent_owner = d.getResult()
+ parent_owner = (yield self.destinationparent.owner(self.request))
authz = self.destinationparent.currentPrincipal(self.request)
if davxml.Principal(parent_owner) != authz and self.access != Component.ACCESS_PUBLIC:
@@ -468,7 +456,7 @@
return result, message, rname
- @deferredGenerator
+ @inlineCallbacks
def checkQuota(self):
"""
Get quota details for destination and source before we start messing with adding other files.
@@ -477,33 +465,25 @@
if self.request is None:
self.destquota = None
else:
- self.destquota = waitForDeferred(self.destination.quota(self.request))
- yield self.destquota
- self.destquota = self.destquota.getResult()
+ self.destquota = (yield self.destination.quota(self.request))
if self.destquota is not None and self.destination.exists():
- self.old_dest_size = waitForDeferred(self.destination.quotaSize(self.request))
- yield self.old_dest_size
- self.old_dest_size = self.old_dest_size.getResult()
+ self.old_dest_size = (yield self.destination.quotaSize(self.request))
else:
self.old_dest_size = 0
if self.request is None:
self.sourcequota = None
elif self.source is not None:
- self.sourcequota = waitForDeferred(self.source.quota(self.request))
- yield self.sourcequota
- self.sourcequota = self.sourcequota.getResult()
+ self.sourcequota = (yield self.source.quota(self.request))
if self.sourcequota is not None and self.source.exists():
- self.old_source_size = waitForDeferred(self.source.quotaSize(self.request))
- yield self.old_source_size
- self.old_source_size = self.old_source_size.getResult()
+ self.old_source_size = (yield self.source.quotaSize(self.request))
else:
self.old_source_size = 0
else:
self.sourcequota = None
self.old_source_size = 0
- yield None
+ returnValue(None)
def setupRollback(self):
"""
@@ -528,7 +508,7 @@
copyToWithXAttrs(self.source.fp, self.rollback.source_copy)
log.debug("Rollback: backing up source %s to %s" % (self.source.fp.path, self.rollback.source_copy.path))
- @deferredGenerator
+ @inlineCallbacks
def doStore(self):
# Do put or copy based on whether source exists
if self.source is not None:
@@ -538,9 +518,7 @@
self.calendardata = str(self.calendar)
md5 = MD5StreamWrapper(MemoryStream(self.calendardata))
response = maybeDeferred(putWithXAttrs, md5, self.destination.fp)
- response = waitForDeferred(response)
- yield response
- response = response.getResult()
+ response = (yield response)
# Update the MD5 value on the resource
if self.source is not None:
@@ -564,9 +542,9 @@
elif not self.destinationcal:
self.destination.removeDeadProperty(TwistedCalendarAccessProperty)
- yield IResponse(response)
+ returnValue(IResponse(response))
- @deferredGenerator
+ @inlineCallbacks
def doSourceDelete(self):
# Delete index for original item
if self.sourcecal:
@@ -582,35 +560,27 @@
# Update quota
if self.sourcequota is not None:
delete_size = 0 - self.old_source_size
- d = waitForDeferred(self.source.quotaSizeAdjust(self.request, delete_size))
- yield d
- d.getResult()
+ yield self.source.quotaSizeAdjust(self.request, delete_size)
# Change CTag on the parent calendar collection
if self.sourcecal:
- d = waitForDeferred(self.sourceparent.updateCTag())
- yield d
- d.getResult()
+ yield self.sourceparent.updateCTag()
- yield None
+ returnValue(None)
- @deferredGenerator
+ @inlineCallbacks
def doDestinationQuotaCheck(self):
# Get size of new/old resources
- new_dest_size = waitForDeferred(self.destination.quotaSize(self.request))
- yield new_dest_size
- new_dest_size = new_dest_size.getResult()
+ new_dest_size = (yield self.destination.quotaSize(self.request))
diff_size = new_dest_size - self.old_dest_size
if diff_size >= self.destquota[0]:
log.err("Over quota: available %d, need %d" % (self.destquota[0], diff_size))
raise HTTPError(ErrorResponse(responsecode.INSUFFICIENT_STORAGE_SPACE, (dav_namespace, "quota-not-exceeded")))
- d = waitForDeferred(self.destination.quotaSizeAdjust(self.request, diff_size))
- yield d
- d.getResult()
+ yield self.destination.quotaSizeAdjust(self.request, diff_size)
- yield None
+ returnValue(None)
def doSourceIndexRecover(self):
"""
@@ -671,7 +641,7 @@
self.rollback.destination_index_deleted = True
log.debug("Destination index removed %s" % (self.destination.fp.path,))
- @deferredGenerator
+ @inlineCallbacks
def run(self):
"""
Function that does common PUT/COPY/MOVE behavior.
@@ -683,18 +653,14 @@
reservation = None
# Handle all validation operations here.
- d = waitForDeferred(self.fullValidation())
- yield d
- d.getResult()
+ yield self.fullValidation()
# Reservation and UID conflict checking is next.
if self.destinationcal:
# Reserve UID
self.destination_index = self.destinationparent.index()
reservation = StoreCalendarObjectResource.UIDReservation(self.destination_index, self.uid, self.destination_uri)
- d = waitForDeferred(reservation.reserve())
- yield d
- d.getResult()
+ yield reservation.reserve()
# 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.
@@ -707,9 +673,7 @@
))
# Get current quota state.
- d = waitForDeferred(self.checkQuota())
- yield d
- d.getResult()
+ yield self.checkQuota()
# Initialize the rollback system
self.setupRollback()
@@ -729,52 +693,38 @@
"""
# Do the actual put or copy
- response = waitForDeferred(self.doStore())
- yield response
- response = response.getResult()
+ response = (yield self.doStore())
# Delete the original source if needed.
if self.deletesource:
- d = waitForDeferred(self.doSourceDelete())
- yield d
- d.getResult()
+ yield self.doSourceDelete()
# Index the new resource if storing to a calendar.
if self.destinationcal:
result = self.doDestinationIndex(self.calendar)
if result is not None:
self.rollback.Rollback()
- yield result
- return
+ returnValue(result)
# Do quota check on destination
if self.destquota is not None:
- d = waitForDeferred(self.doDestinationQuotaCheck())
- yield d
- d.getResult()
+ yield self.doDestinationQuotaCheck()
if self.destinationcal:
# Change CTag on the parent calendar collection
- d = waitForDeferred(self.destinationparent.updateCTag())
- yield d
- d.getResult()
+ yield self.destinationparent.updateCTag()
# Can now commit changes and forget the rollback details
self.rollback.Commit()
if reservation:
- d = waitForDeferred(reservation.unreserve())
- yield d
- d.getResult()
+ yield reservation.unreserve()
- yield response
- return
+ returnValue(response)
except Exception, err:
if reservation:
- d = waitForDeferred(reservation.unreserve())
- yield d
- d.getResult()
+ yield reservation.unreserve()
# Roll back changes to original server state. Note this may do nothing
# if the rollback has already occurred or changes already committed.
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -29,7 +29,7 @@
import string
-from twisted.internet.defer import deferredGenerator, waitForDeferred
+from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.web2 import responsecode
from twisted.web2.http import HTTPError, StatusResponse
from twisted.web2.dav import davxml
@@ -47,6 +47,7 @@
class NumberOfMatchesWithinLimits(Exception):
pass
+ at inlineCallbacks
def http_REPORT(self, request):
"""
Respond to a REPORT request. (RFC 3253, section 3.6)
@@ -59,9 +60,7 @@
# Read request body
#
try:
- doc = waitForDeferred(davXMLFromStream(request.stream))
- yield doc
- doc = doc.getResult()
+ doc = (yield davXMLFromStream(request.stream))
except ValueError, e:
log.err("Error while handling REPORT body: %s" % (e,))
raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, str(e)))
@@ -122,12 +121,7 @@
privileges = (davxml.Read(),)
if method_name == "report_urn_ietf_params_xml_ns_caldav_free_busy_query":
privileges = (caldavxml.ReadFreeBusy(),)
- x = waitForDeferred(self.authorize(request, privileges))
- yield x
- x.getResult()
+ yield self.authorize(request, privileges)
- d = waitForDeferred(method(request, doc.root_element))
- yield d
- yield d.getResult()
-
-http_REPORT = deferredGenerator(http_REPORT)
+ result = (yield method(request, doc.root_element))
+ returnValue(result)
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_calquery.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_calquery.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_calquery.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -22,7 +22,7 @@
import urllib
-from twisted.internet.defer import deferredGenerator, succeed, waitForDeferred
+from twisted.internet.defer import succeed, inlineCallbacks, returnValue
from twisted.web2 import responsecode
from twisted.web2.dav import davxml
from twisted.web2.dav.element.base import dav_namespace
@@ -40,6 +40,7 @@
max_number_of_results = 1000
+ at inlineCallbacks
def report_urn_ietf_params_xml_ns_caldav_calendar_query(self, request, calendar_query):
"""
Generate a calendar-query REPORT.
@@ -51,9 +52,7 @@
raise ValueError("{CalDAV:}calendar-query expected as root element, not %s." % (calendar_query.sname(),))
if not self.isCollection():
- parent = waitForDeferred(self.locateParent(request, request.uri))
- yield parent
- parent = parent.getResult()
+ parent = (yield self.locateParent(request, request.uri))
if not parent.isPseudoCalendarCollection():
log.err("calendar-query report is not allowed on a resource outside of a calendar collection %s" % (self,))
raise HTTPError(StatusResponse(responsecode.FORBIDDEN, "Must be calendar collection or calendar resource"))
@@ -99,6 +98,8 @@
raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-filter")))
matchcount = [0]
+
+ @inlineCallbacks
def doQuery(calresource, uri):
"""
Run a query on the specified calendar collection
@@ -144,25 +145,17 @@
if calresource.isPseudoCalendarCollection():
# Get the timezone property from the collection if one was not set in the query,
# and store in the query filter for later use
- has_prop = waitForDeferred(calresource.hasProperty((caldav_namespace, "calendar-timezone"), request))
- yield has_prop
- has_prop = has_prop.getResult()
+ has_prop = (yield calresource.hasProperty((caldav_namespace, "calendar-timezone"), request))
if query_tz is None and has_prop:
- tz = waitForDeferred(calresource.readProperty((caldav_namespace, "calendar-timezone"), request))
- yield tz
- tz = tz.getResult()
+ tz = (yield calresource.readProperty((caldav_namespace, "calendar-timezone"), request))
filter.settimezone(tz)
# Do some optimisation of access control calculation by determining any inherited ACLs outside of
# the child resource loop and supply those to the checkPrivileges on each child.
- filteredaces = waitForDeferred(calresource.inheritedACEsforChildren(request))
- yield filteredaces
- filteredaces = filteredaces.getResult()
+ filteredaces = (yield calresource.inheritedACEsforChildren(request))
# Check private events access status
- d = waitForDeferred(calresource.isOwner(request))
- yield d
- isowner = d.getResult()
+ isowner = (yield calresource.isOwner(request))
# Check for disabled access
if filteredaces is not None:
@@ -172,12 +165,11 @@
# Get list of children that match the search and have read access
names = [name for name, ignore_uid, ignore_type in calresource.index().search(filter)]
if not names:
- yield None
return
# Now determine which valid resources are readable and which are not
ok_resources = []
- d = calresource.findChildrenFaster(
+ yield calresource.findChildrenFaster(
"1",
request,
lambda x, y: ok_resources.append((x, y)),
@@ -186,9 +178,6 @@
(davxml.Read(),),
inherited_aces=filteredaces
)
- x = waitForDeferred(d)
- yield x
- x.getResult()
for child, child_uri in ok_resources:
child_uri_name = child_uri[child_uri.rfind("/") + 1:]
@@ -200,50 +189,32 @@
else:
calendar = None
- d = waitForDeferred(queryCalendarObjectResource(child, uri, child_uri_name, calendar, query_ok = index_query_ok, isowner=isowner))
- yield d
- d.getResult()
+ yield queryCalendarObjectResource(child, uri, child_uri_name, calendar, query_ok = index_query_ok, isowner=isowner)
else:
# Get the timezone property from the collection if one was not set in the query,
# and store in the query object for later use
if query_tz is None:
- parent = waitForDeferred(calresource.locateParent(request, uri))
- yield parent
- parent = parent.getResult()
+ parent = (yield calresource.locateParent(request, uri))
assert parent is not None and parent.isPseudoCalendarCollection()
- has_prop = waitForDeferred(parent.hasProperty((caldav_namespace, "calendar-timezone"), request))
- yield has_prop
- has_prop = has_prop.getResult()
+ has_prop = (yield parent.hasProperty((caldav_namespace, "calendar-timezone"), request))
if has_prop:
- tz = waitForDeferred(parent.readProperty((caldav_namespace, "calendar-timezone"), request))
- yield tz
- tz = tz.getResult()
+ tz = (yield parent.readProperty((caldav_namespace, "calendar-timezone"), request))
filter.settimezone(tz)
# Check private events access status
- d = waitForDeferred(calresource.isOwner(request))
- yield d
- isowner = d.getResult()
+ isowner = (yield calresource.isOwner(request))
calendar = calresource.iCalendar()
- d = waitForDeferred(queryCalendarObjectResource(calresource, uri, None, calendar))
- yield d
- d.getResult()
+ yield queryCalendarObjectResource(calresource, uri, None, calendar)
- doQuery = deferredGenerator(doQuery)
-
# Run report taking depth into account
try:
depth = request.headers.getHeader("depth", "0")
- d = waitForDeferred(report_common.applyToCalendarCollections(self, request, request.uri, depth, doQuery, (davxml.Read(),)))
- yield d
- d.getResult()
+ yield report_common.applyToCalendarCollections(self, request, request.uri, depth, doQuery, (davxml.Read(),))
except NumberOfMatchesWithinLimits:
log.err("Too many matching components in calendar-query report")
raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (dav_namespace, "number-of-matches-within-limits")))
- yield MultiStatusResponse(responses)
-
-report_urn_ietf_params_xml_ns_caldav_calendar_query = deferredGenerator(report_urn_ietf_params_xml_ns_caldav_calendar_query)
+ returnValue(MultiStatusResponse(responses))
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_common.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_common.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_common.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -32,7 +32,7 @@
from vobject.icalendar import utc
-from twisted.internet.defer import deferredGenerator, waitForDeferred
+from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.python.failure import Failure
from twisted.web2 import responsecode
from twisted.web2.dav import davxml
@@ -54,6 +54,7 @@
log = Logger()
+ at inlineCallbacks
def applyToCalendarCollections(resource, request, request_uri, depth, apply, privileges):
"""
Run an operation on all calendar collections, starting at the specified
@@ -71,11 +72,8 @@
# First check the privilege on this resource
try:
- d = waitForDeferred(resource.checkPrivileges(request, privileges))
- yield d
- d.getResult()
+ yield resource.checkPrivileges(request, privileges)
except AccessDeniedError:
- yield None
return
# When scanning we only go down as far as a calendar collection - not into one
@@ -85,17 +83,11 @@
resources = [(resource, request_uri)]
else:
resources = []
- d = waitForDeferred(resource.findCalendarCollections(depth, request, lambda x, y: resources.append((x, y)), privileges = privileges))
- yield d
- d.getResult()
+ yield resource.findCalendarCollections(depth, request, lambda x, y: resources.append((x, y)), privileges = privileges)
for calresource, uri in resources:
- d = waitForDeferred(apply(calresource, uri))
- yield d
- d.getResult()
+ yield apply(calresource, uri)
-applyToCalendarCollections = deferredGenerator(applyToCalendarCollections)
-
def responseForHref(request, responses, href, resource, calendar, propertiesForResource, propertyreq, isowner=True):
"""
Create an appropriate property status response for the given resource.
@@ -215,6 +207,7 @@
return result, message, generate_calendar_data
+ at inlineCallbacks
def _namedPropertiesForResource(request, props, resource, calendar=None, isowner=True):
"""
Return the specified properties on the specified resource.
@@ -258,15 +251,11 @@
else:
qname = property
- props = waitForDeferred(resource.listProperties(request))
- yield props
- props = props.getResult()
+ props = (yield resource.listProperties(request))
if qname in props:
try:
- prop = waitForDeferred(resource.readProperty(qname, request))
- yield prop
- prop = prop.getResult()
+ prop = (yield resource.readProperty(qname, request))
properties_by_status[responsecode.OK].append(prop)
except HTTPError:
f = Failure()
@@ -279,10 +268,9 @@
else:
properties_by_status[responsecode.NOT_FOUND].append(propertyName(qname))
- yield properties_by_status
+ returnValue(properties_by_status)
-_namedPropertiesForResource = deferredGenerator(_namedPropertiesForResource)
-
+ at inlineCallbacks
def generateFreeBusyInfo(request, calresource, fbinfo, timerange, matchtotal,
excludeuid=None, organizer=None, same_calendar_user=False,
servertoserver=False):
@@ -307,12 +295,9 @@
# TODO: for server-to-server we bypass this right now as we have no way to authorize external users.
if not servertoserver:
try:
- d = waitForDeferred(calresource.checkPrivileges(request, (caldavxml.ReadFreeBusy(),)))
- yield d
- d.getResult()
+ yield calresource.checkPrivileges(request, (caldavxml.ReadFreeBusy(),))
except AccessDeniedError:
- yield matchtotal
- return
+ returnValue(matchtotal)
#
# What we do is a fake calendar-query for VEVENT/VFREEBUSYs in the specified time-range.
@@ -333,36 +318,26 @@
# Get the timezone property from the collection, and store in the query filter
# for use during the query itself.
- has_prop = waitForDeferred(calresource.hasProperty((caldav_namespace, "calendar-timezone"), request))
- yield has_prop
- has_prop = has_prop.getResult()
+ has_prop = (yield calresource.hasProperty((caldav_namespace, "calendar-timezone"), request))
if has_prop:
- tz = waitForDeferred(calresource.readProperty((caldav_namespace, "calendar-timezone"), request))
- yield tz
- tz = tz.getResult()
+ tz = (yield calresource.readProperty((caldav_namespace, "calendar-timezone"), request))
else:
tz = None
tzinfo = filter.settimezone(tz)
# Do some optimisation of access control calculation by determining any inherited ACLs outside of
# the child resource loop and supply those to the checkPrivileges on each child.
- filteredaces = waitForDeferred(calresource.inheritedACEsforChildren(request))
- yield filteredaces
- filteredaces = filteredaces.getResult()
+ filteredaces = (yield calresource.inheritedACEsforChildren(request))
for name, uid, type in calresource.index().search(filter): #@UnusedVariable
# Check privileges - must have at least CalDAV:read-free-busy
- child = waitForDeferred(request.locateChildResource(calresource, name))
- yield child
- child = child.getResult()
+ 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:
- d = waitForDeferred(child.checkPrivileges(request, (caldavxml.ReadFreeBusy(),), inherited_aces=filteredaces))
- yield d
- d.getResult()
+ yield child.checkPrivileges(request, (caldavxml.ReadFreeBusy(),), inherited_aces=filteredaces)
except AccessDeniedError:
continue
@@ -401,10 +376,8 @@
else:
assert "Free-busy query returned unwanted component: %s in %r", (name, calresource,)
- yield matchtotal
+ returnValue(matchtotal)
-generateFreeBusyInfo = deferredGenerator(generateFreeBusyInfo)
-
def processEventFreeBusy(calendar, fbinfo, timerange, tzinfo):
"""
Extract free busy data from a VEVENT component.
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_freebusy.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_freebusy.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_freebusy.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -20,7 +20,7 @@
__all__ = ["report_urn_ietf_params_xml_ns_caldav_free_busy_query"]
-from twisted.internet.defer import deferredGenerator, waitForDeferred
+from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.web2 import responsecode
from twisted.web2.dav.element.base import dav_namespace
from twisted.web2.dav.http import ErrorResponse
@@ -35,6 +35,7 @@
log = Logger()
+ at inlineCallbacks
def report_urn_ietf_params_xml_ns_caldav_free_busy_query(self, request, freebusy): #@UnusedVariable
"""
Generate a free-busy REPORT.
@@ -55,6 +56,8 @@
fbinfo = ([], [], [])
matchcount = [0]
+
+ @inlineCallbacks
def generateFreeBusyInfo(calresource, uri): #@UnusedVariable
"""
Run a free busy report on the specified calendar collection
@@ -62,18 +65,12 @@
@param calresource: the L{CalDAVFile} for a calendar collection.
@param uri: the uri for the calendar collecton resource.
"""
- d = waitForDeferred(report_common.generateFreeBusyInfo(request, calresource, fbinfo, timerange, matchcount[0]))
- yield d
- matchcount[0] = d.getResult()
-
- generateFreeBusyInfo = deferredGenerator(generateFreeBusyInfo)
+ matchcount[0] = (yield report_common.generateFreeBusyInfo(request, calresource, fbinfo, timerange, matchcount[0]))
# Run report taking depth into account
try:
depth = request.headers.getHeader("depth", "0")
- d = waitForDeferred(report_common.applyToCalendarCollections(self, request, request.uri, depth, generateFreeBusyInfo, (caldavxml.ReadFreeBusy(),)))
- yield d
- d.getResult()
+ yield report_common.applyToCalendarCollections(self, request, request.uri, depth, generateFreeBusyInfo, (caldavxml.ReadFreeBusy(),))
except NumberOfMatchesWithinLimits:
log.err("Too many matching components in free-busy report")
raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (dav_namespace, "number-of-matches-within-limits")))
@@ -85,6 +82,4 @@
response.stream = MemoryStream(str(fbcalendar))
response.headers.setHeader("content-type", MimeType.fromString("text/calendar; charset=utf-8"))
- yield response
-
-report_urn_ietf_params_xml_ns_caldav_free_busy_query = deferredGenerator(report_urn_ietf_params_xml_ns_caldav_free_busy_query)
+ returnValue(response)
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_multiget.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_multiget.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/method/report_multiget.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -52,7 +52,7 @@
# Make sure target resource is of the right type
if not self.isCollection():
- parent = yield self.locateParent(request, request.uri)
+ parent = (yield self.locateParent(request, request.uri))
if not parent.isPseudoCalendarCollection():
log.err("calendar-multiget report is not allowed on a resource outside of a calendar collection %s" % (self,))
raise HTTPError(StatusResponse(responsecode.FORBIDDEN, "Must be calendar resource"))
@@ -105,14 +105,14 @@
# Do some optimisation of access control calculation by determining any inherited ACLs outside of
# the child resource loop and supply those to the checkPrivileges on each child.
- filteredaces = yield self.inheritedACEsforChildren(request)
+ filteredaces = (yield self.inheritedACEsforChildren(request))
# Check for disabled access
if filteredaces is None:
disabled = True
# Check private events access status
- isowner = yield self.isOwner(request)
+ isowner = (yield self.isOwner(request))
elif self.isCollection():
requestURIis = "collection"
@@ -191,13 +191,13 @@
responses.append(davxml.StatusResponse(href, davxml.Status.fromResponseCode(responsecode.NOT_FOUND)))
continue
- child = yield request.locateResource(resource_uri)
+ child = (yield request.locateResource(resource_uri))
if not child or not child.exists():
responses.append(davxml.StatusResponse(href, davxml.Status.fromResponseCode(responsecode.NOT_FOUND)))
continue
- parent = yield child.locateParent(request, resource_uri)
+ parent = (yield child.locateParent(request, resource_uri))
if not parent.isCalendarCollection() or not parent.index().resourceExists(name):
responses.append(davxml.StatusResponse(href, davxml.Status.fromResponseCode(responsecode.FORBIDDEN)))
@@ -216,17 +216,17 @@
# Do some optimisation of access control calculation by determining any inherited ACLs outside of
# the child resource loop and supply those to the checkPrivileges on each child.
- filteredaces = yield parent.inheritedACEsforChildren(request)
+ filteredaces = (yield parent.inheritedACEsforChildren(request))
# Check private events access status
- isowner = yield parent.isOwner(request)
+ isowner = (yield parent.isOwner(request))
else:
name = unquote(resource_uri[resource_uri.rfind("/") + 1:])
if (resource_uri != request.uri) or not self.exists():
responses.append(davxml.StatusResponse(href, davxml.Status.fromResponseCode(responsecode.NOT_FOUND)))
continue
- parent = yield self.locateParent(request, resource_uri)
+ parent = (yield self.locateParent(request, resource_uri))
if not parent.isPseudoCalendarCollection() or not parent.index().resourceExists(name):
responses.append(davxml.StatusResponse(href, davxml.Status.fromResponseCode(responsecode.FORBIDDEN)))
@@ -235,10 +235,10 @@
# Do some optimisation of access control calculation by determining any inherited ACLs outside of
# the child resource loop and supply those to the checkPrivileges on each child.
- filteredaces = yield parent.inheritedACEsforChildren(request)
+ filteredaces = (yield parent.inheritedACEsforChildren(request))
# Check private events access status
- isowner = yield parent.isOwner(request)
+ isowner = (yield parent.isOwner(request))
# Check privileges - must have at least DAV:read
try:
Modified: CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/resource.py
===================================================================
--- CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/resource.py 2008-07-07 20:02:22 UTC (rev 2667)
+++ CalendarServer/branches/users/cdaboo/implicit-2660/twistedcaldav/resource.py 2008-07-07 21:14:05 UTC (rev 2668)
@@ -31,8 +31,7 @@
from twisted.internet import reactor
from twisted.internet.defer import Deferred, maybeDeferred, succeed
-from twisted.internet.defer import waitForDeferred
-from twisted.internet.defer import deferredGenerator
+from twisted.internet.defer import inlineCallbacks, returnValue
from twisted.web2 import responsecode
from twisted.web2.dav import davxml
from twisted.web2.dav.idav import IDAVPrincipalCollectionResource
@@ -268,20 +267,16 @@
##
# FIXME: Perhaps this is better done in authorize() instead.
- @deferredGenerator
+ @inlineCallbacks
def accessControlList(self, request, *args, **kwargs):
- d = waitForDeferred(super(CalDAVResource, self).accessControlList(request, *args, **kwargs))
- yield d
- acls = d.getResult()
+ acls = (yield super(CalDAVResource, self).accessControlList(request, *args, **kwargs))
# Look for private events access classification
if self.hasDeadProperty(TwistedCalendarAccessProperty):
access = self.readDeadProperty(TwistedCalendarAccessProperty)
if access.getValue() in (Component.ACCESS_PRIVATE, Component.ACCESS_CONFIDENTIAL, Component.ACCESS_RESTRICTED,):
# Need to insert ACE to prevent non-owner principals from seeing this resource
- d = waitForDeferred(self.owner(request))
- yield d
- owner = d.getResult()
+ owner = (yield self.owner(request))
if access.getValue() == Component.ACCESS_PRIVATE:
ace = davxml.ACE(
davxml.Invert(
@@ -311,35 +306,29 @@
)
acls = davxml.ACL(ace, *acls.children)
- yield acls
+ returnValue(acls)
- @deferredGenerator
+ @inlineCallbacks
def owner(self, request):
"""
Return the DAV:owner property value (MUST be a DAV:href or None).
"""
- d = waitForDeferred(self.locateParent(request, request.urlForResource(self)))
- yield d
- parent = d.getResult()
+ parent = (yield self.locateParent(request, request.urlForResource(self)))
if parent and isinstance(parent, CalDAVResource):
- d = waitForDeferred(parent.owner(request))
- yield d
- yield d.getResult()
+ result = (yield parent.owner(request))
+ returnValue(result)
else:
- yield None
+ returnValue(None)
- @deferredGenerator
+ @inlineCallbacks
def isOwner(self, request):
"""
Determine whether the DAV:owner of this resource matches the currently authorized principal
in the request.
"""
- d = waitForDeferred(self.owner(request))
- yield d
- owner = d.getResult()
- result = (davxml.Principal(owner) == self.currentPrincipal(request))
- yield result
+ owner = (yield self.owner(request))
+ returnValue(davxml.Principal(owner) == self.currentPrincipal(request))
##
# CalDAV
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080707/40c4e649/attachment-0001.html
More information about the calendarserver-changes
mailing list