/usr/lib/python2.7/dist-packages/twext/web2/dav/method/prop_common.py is in calendarserver 5.2+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | ##
# Cyrus Daboo, cdaboo@apple.com
# Copyright 2006-2012 Apple Computer, Inc. All Rights Reserved.
##
__all__ = [
"responseForHref",
"propertyListForResource",
]
from twisted.internet.defer import deferredGenerator, waitForDeferred
from twisted.python.failure import Failure
from twext.python.log import Logger
from twext.web2 import responsecode
from txdav.xml import element
from twext.web2.dav.http import statusForFailure
from twext.web2.dav.method.propfind import propertyName
log = Logger()
def responseForHref(request, responses, href, resource, propertiesForResource, propertyreq):
if propertiesForResource is not None:
properties_by_status = waitForDeferred(propertiesForResource(request, propertyreq, resource))
yield properties_by_status
properties_by_status = properties_by_status.getResult()
propstats = []
for status in properties_by_status:
properties = properties_by_status[status]
if properties:
xml_status = element.Status.fromResponseCode(status)
xml_container = element.PropertyContainer(*properties)
xml_propstat = element.PropertyStatus(xml_container, xml_status)
propstats.append(xml_propstat)
if propstats:
responses.append(element.PropertyStatusResponse(href, *propstats))
else:
responses.append(
element.StatusResponse(
href,
element.Status.fromResponseCode(responsecode.OK),
)
)
responseForHref = deferredGenerator(responseForHref)
def propertyListForResource(request, prop, resource):
"""
Return the specified properties on the specified resource.
@param request: the L{IRequest} for the current request.
@param prop: the L{PropertyContainer} element for the properties of interest.
@param resource: the L{DAVFile} for the targetted resource.
@return: a map of OK and NOT FOUND property values.
"""
return _namedPropertiesForResource(request, prop.children, resource)
def _namedPropertiesForResource(request, props, resource):
"""
Return the specified properties on the specified resource.
@param request: the L{IRequest} for the current request.
@param props: a list of property elements or qname tuples for the properties of interest.
@param resource: the L{DAVFile} for the targetted resource.
@return: a map of OK and NOT FOUND property values.
"""
properties_by_status = {
responsecode.OK : [],
responsecode.NOT_FOUND : [],
}
for property in props:
if isinstance(property, element.WebDAVElement):
qname = property.qname()
else:
qname = property
props = waitForDeferred(resource.listProperties(request))
yield props
props = props.getResult()
if qname in props:
try:
prop = waitForDeferred(resource.readProperty(qname, request))
yield prop
prop = prop.getResult()
properties_by_status[responsecode.OK].append(prop)
except:
f = Failure()
status = statusForFailure(f, "getting property: %s" % (qname,))
if status != responsecode.NOT_FOUND:
log.error("Error reading property %r for resource %s: %s" %
(qname, request.uri, f.value))
if status not in properties_by_status: properties_by_status[status] = []
properties_by_status[status].append(propertyName(qname))
else:
properties_by_status[responsecode.NOT_FOUND].append(propertyName(qname))
yield properties_by_status
_namedPropertiesForResource = deferredGenerator(_namedPropertiesForResource)
|