2
# Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
4
# Permission is hereby granted, free of charge, to any person obtaining a copy
5
# of this software and associated documentation files (the "Software"), to deal
6
# in the Software without restriction, including without limitation the rights
7
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
# copies of the Software, and to permit persons to whom the Software is
9
# furnished to do so, subject to the following conditions:
11
# The above copyright notice and this permission notice shall be included in all
12
# copies or substantial portions of the Software.
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
# DRI: Wilfredo Sanchez, wsanchez@apple.com
29
__all__ = ["DAVPrincipalResource"]
31
from zope.interface import implements
32
from twisted.internet.defer import maybeDeferred
33
from twisted.web2.dav import davxml
34
from twisted.web2.dav.davxml import dav_namespace
35
from twisted.web2.dav.idav import IDAVPrincipalResource
36
from twisted.web2.dav.resource import DAVLeafResource
37
from twisted.web2.dav.util import unimplemented
39
class DAVPrincipalResource (DAVLeafResource):
41
Resource representing a WebDAV principal. (RFC 3744, section 2)
43
implements(IDAVPrincipalResource)
49
liveProperties = DAVLeafResource.liveProperties + (
50
(dav_namespace, "alternate-uri-set"),
51
(dav_namespace, "principal-url" ),
52
(dav_namespace, "group-member-set" ),
53
(dav_namespace, "group-membership" ),
56
def davComplianceClasses(self):
59
def isCollection(self):
62
def findChildren(self, depth):
65
def readProperty(self, property, request):
67
if type(property) is tuple:
69
sname = "{%s}%s" % property
71
qname = property.qname()
72
sname = property.sname()
74
namespace, name = qname
76
if namespace == dav_namespace:
77
if name == "alternate-uri-set":
78
return davxml.AlternateURISet(*[davxml.HRef(u) for u in self.alternateURIs()])
80
if name == "principal-url":
81
return davxml.PrincipalURL(davxml.HRef(self.principalURL()))
83
if name == "group-member-set":
84
return davxml.GroupMemberSet(*[davxml.HRef(p) for p in self.groupMembers()])
86
if name == "group-membership":
87
return davxml.GroupMemberSet(*[davxml.HRef(g) for g in self.groupMemberships()])
89
return super(DAVPrincipalResource, self).readProperty(qname, request)
91
return maybeDeferred(defer)
97
def alternateURIs(self):
99
See L{IDAVPrincipalResource.alternateURIs}.
101
This implementation returns C{()}. Subclasses should override this
102
method to provide alternate URIs for this resource if appropriate.
106
def principalURL(self):
108
See L{IDAVPrincipalResource.principalURL}.
110
This implementation raises L{NotImplementedError}. Subclasses must
111
override this method to provide the principal URL for this resource.
115
def groupMembers(self):
117
See L{IDAVPrincipalResource.groupMembers}.
119
This implementation returns C{()}, which is appropriate for non-group
120
principals. Subclasses should override this method to provide member
121
URLs for this resource if appropriate.
125
def groupMemberships(self):
127
See L{IDAVPrincipalResource.groupMemberships}.
129
This implementation raises L{NotImplementedError}. Subclasses must
130
override this method to provide the group URLs for this resource.