[CalendarServer-changes] [3998] CalendarServer/branches/exarkun/update-twisted-3816/lib-patches/ Twisted/twisted.web2.dav.method.report_expand.patch
source_changes at macosforge.org
source_changes at macosforge.org
Mon Apr 13 08:41:59 PDT 2009
Revision: 3998
http://trac.macosforge.org/projects/calendarserver/changeset/3998
Author: exarkun at twistedmatrix.com
Date: 2009-04-13 08:41:56 -0700 (Mon, 13 Apr 2009)
Log Message:
-----------
Applied to dav-take-two branch
Removed Paths:
-------------
CalendarServer/branches/exarkun/update-twisted-3816/lib-patches/Twisted/twisted.web2.dav.method.report_expand.patch
Deleted: CalendarServer/branches/exarkun/update-twisted-3816/lib-patches/Twisted/twisted.web2.dav.method.report_expand.patch
===================================================================
--- CalendarServer/branches/exarkun/update-twisted-3816/lib-patches/Twisted/twisted.web2.dav.method.report_expand.patch 2009-04-13 14:50:54 UTC (rev 3997)
+++ CalendarServer/branches/exarkun/update-twisted-3816/lib-patches/Twisted/twisted.web2.dav.method.report_expand.patch 2009-04-13 15:41:56 UTC (rev 3998)
@@ -1,214 +0,0 @@
-Index: twisted/web2/dav/method/report_expand.py
-===================================================================
---- twisted/web2/dav/method/report_expand.py (revision 19773)
-+++ twisted/web2/dav/method/report_expand.py (working copy)
-@@ -1,6 +1,6 @@
- # -*- test-case-name: twisted.web2.dav.test.test_report_expand -*-
- ##
--# Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
-+# Copyright (c) 2005-2008 Apple Computer, Inc. All rights reserved.
- #
- # Permission is hereby granted, free of charge, to any person obtaining a copy
- # of this software and associated documentation files (the "Software"), to deal
-@@ -19,8 +19,6 @@
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- # SOFTWARE.
--#
--# DRI: Wilfredo Sanchez, wsanchez at apple.com
- ##
-
- """
-@@ -29,86 +27,143 @@
-
- __all__ = ["report_DAV__expand_property"]
-
-+from twisted.internet.defer import inlineCallbacks, returnValue
- from twisted.python import log
- from twisted.python.failure import Failure
--from twisted.internet.defer import deferredGenerator, waitForDeferred
- from twisted.web2 import responsecode
- from twisted.web2.dav import davxml
--from twisted.web2.dav.http import statusForFailure
- from twisted.web2.dav.davxml import dav_namespace
-+from twisted.web2.dav.http import statusForFailure, MultiStatusResponse
-+from twisted.web2.dav.method import prop_common
-+from twisted.web2.dav.method.propfind import propertyName
-+from twisted.web2.dav.resource import AccessDeniedError
-+from twisted.web2.dav.util import parentForURL
-+from twisted.web2.http import HTTPError, StatusResponse
-
-+ at inlineCallbacks
- def report_DAV__expand_property(self, request, expand_property):
- """
- Generate an expand-property REPORT. (RFC 3253, section 3.8)
-+
-+ TODO: for simplicity we will only support one level of expansion.
- """
-- # FIXME: Handle depth header
--
-+ # Verify root element
- if not isinstance(expand_property, davxml.ExpandProperty):
- raise ValueError("%s expected as root element, not %s."
- % (davxml.ExpandProperty.sname(), expand_property.sname()))
-
-+ # Only handle Depth: 0
-+ depth = request.headers.getHeader("depth", "0")
-+ if depth != "0":
-+ log.err("Non-zero depth is not allowed: %s" % (depth,))
-+ raise HTTPError(StatusResponse(responsecode.BAD_REQUEST, "Depth %s not allowed" % (depth,)))
-+
- #
-- # Expand DAV:allprop
-+ # Get top level properties to expand and make sure we only have one level
- #
- properties = {}
-
- for property in expand_property.children:
-- namespace = property.getAttribute("namespace")
-- name = property.getAttribute("name")
-+ namespace = property.attributes.get("namespace", dav_namespace)
-+ name = property.attributes.get("name", "")
-+
-+ # Make sure children have no children
-+ props_to_find = []
-+ for child in property.children:
-+ if child.children:
-+ log.err("expand-property REPORT only supports single level expansion")
-+ raise HTTPError(StatusResponse(
-+ responsecode.NOT_IMPLEMENTED,
-+ "expand-property REPORT only supports single level expansion"
-+ ))
-+ child_namespace = child.attributes.get("namespace", dav_namespace)
-+ child_name = child.attributes.get("name", "")
-+ props_to_find.append((child_namespace, child_name))
-
-- if not namespace: namespace = dav_namespace
-+ properties[(namespace, name)] = props_to_find
-
-- if (namespace, name) == (dav_namespace, "allprop"):
-- all_properties = waitForDeferred(self.listAllProp(request))
-- yield all_properties
-- all_properties = all_properties.getResult()
--
-- for all_property in all_properties:
-- properties[all_property.qname()] = property
-- else:
-- properties[(namespace, name)] = property
--
- #
-- # Look up the requested properties
-+ # Generate the expanded responses status for each top-level property
- #
- properties_by_status = {
- responsecode.OK : [],
- responsecode.NOT_FOUND : [],
- }
-+
-+ filteredaces = None
-+ lastParent = None
-
-- for property in properties:
-- my_properties = waitForDeferred(self.listProperties(request))
-- yield my_properties
-- my_properties = my_properties.getResult()
-+ for qname in properties.iterkeys():
-+ try:
-+ prop = (yield self.readProperty(qname, request))
-+
-+ # Form the PROPFIND-style DAV:prop element we need later
-+ props_to_return = davxml.PropertyContainer(*properties[qname])
-
-- if property in my_properties:
-- try:
-- value = waitForDeferred(self.readProperty(property, request))
-- yield value
-- value = value.getResult()
-+ # Now dereference any HRefs
-+ responses = []
-+ for href in prop.children:
-+ if isinstance(href, davxml.HRef):
-+
-+ # Locate the Href resource and its parent
-+ resource_uri = str(href)
-+ 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 request.locateResource(parentForURL(resource_uri)))
-+
-+ # Check privileges on parent - must have at least DAV:read
-+ try:
-+ yield parent.checkPrivileges(request, (davxml.Read(),))
-+ except AccessDeniedError:
-+ responses.append(davxml.StatusResponse(href, davxml.Status.fromResponseCode(responsecode.FORBIDDEN)))
-+ continue
-+
-+ # Cache the last parent's inherited aces for checkPrivileges optimization
-+ if lastParent != parent:
-+ lastParent = parent
-+
-+ # 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))
-
-- if isinstance(value, davxml.HRef):
-- raise NotImplementedError()
-- else:
-- raise NotImplementedError()
-- except:
-- f = Failure()
-+ # Check privileges - must have at least DAV:read
-+ try:
-+ yield child.checkPrivileges(request, (davxml.Read(),), inherited_aces=filteredaces)
-+ except AccessDeniedError:
-+ responses.append(davxml.StatusResponse(href, davxml.Status.fromResponseCode(responsecode.FORBIDDEN)))
-+ continue
-+
-+ # Now retrieve all the requested properties on the HRef resource
-+ yield prop_common.responseForHref(
-+ request,
-+ responses,
-+ href,
-+ child,
-+ prop_common.propertyListForResource,
-+ props_to_return,
-+ )
-+
-+ prop.children = responses
-+ properties_by_status[responsecode.OK].append(prop)
-+ except:
-+ f = Failure()
-
-- log.err("Error reading property %r for resource %s: %s"
-- % (property, self, f.value))
-+ log.err("Error reading property %r for resource %s: %s" % (qname, request.uri, f.value))
-
-- status = statusForFailure(f, "getting property: %s" % (property,))
-- if status not in properties_by_status:
-- properties_by_status[status] = []
-+ status = statusForFailure(f, "getting property: %s" % (qname,))
-+ if status not in properties_by_status: properties_by_status[status] = []
-+ properties_by_status[status].append(propertyName(qname))
-
-- raise NotImplementedError()
-+ # Build the overall response
-+ propstats = [
-+ davxml.PropertyStatus(
-+ davxml.PropertyContainer(*properties_by_status[status]),
-+ davxml.Status.fromResponseCode(status)
-+ )
-+ for status in properties_by_status if properties_by_status[status]
-+ ]
-
-- #properties_by_status[status].append(
-- # ____propertyName(property)
-- #)
-- else:
-- properties_by_status[responsecode.NOT_FOUND].append(property)
--
-- raise NotImplementedError()
--
--report_DAV__expand_property = deferredGenerator(report_DAV__expand_property)
-+ returnValue(MultiStatusResponse((davxml.PropertyStatusResponse(davxml.HRef(request.uri), *propstats),)))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090413/40a30afb/attachment.html>
More information about the calendarserver-changes
mailing list