~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to twisted/web2/dav/acl.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-01-17 14:52:35 UTC
  • mfrom: (1.1.5 upstream) (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20070117145235-btmig6qfmqfen0om
Tags: 2.5.0-0ubuntu1
New upstream version, compatible with python2.5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##
 
2
# Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
 
3
#
 
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:
 
10
 
11
# The above copyright notice and this permission notice shall be included in all
 
12
# copies or substantial portions of the Software.
 
13
 
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
 
20
# SOFTWARE.
 
21
#
 
22
# DRI: Wilfredo Sanchez, wsanchez@apple.com
 
23
##
 
24
 
 
25
"""
 
26
WebDAV ACL resources.
 
27
"""
 
28
 
 
29
__all__ = ["DAVPrincipalResource"]
 
30
 
 
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
 
38
 
 
39
class DAVPrincipalResource (DAVLeafResource):
 
40
    """
 
41
    Resource representing a WebDAV principal.  (RFC 3744, section 2)
 
42
    """
 
43
    implements(IDAVPrincipalResource)
 
44
 
 
45
    ##
 
46
    # WebDAV
 
47
    ##
 
48
 
 
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" ),
 
54
    )
 
55
 
 
56
    def davComplianceClasses(self):
 
57
        return ("1",)
 
58
 
 
59
    def isCollection(self):
 
60
        return False
 
61
 
 
62
    def findChildren(self, depth):
 
63
        return ()
 
64
 
 
65
    def readProperty(self, property, request):
 
66
        def defer():
 
67
            if type(property) is tuple:
 
68
                qname = property
 
69
                sname = "{%s}%s" % property
 
70
            else:
 
71
                qname = property.qname()
 
72
                sname = property.sname()
 
73
 
 
74
            namespace, name = qname
 
75
 
 
76
            if namespace == dav_namespace:
 
77
                if name == "alternate-uri-set":
 
78
                    return davxml.AlternateURISet(*[davxml.HRef(u) for u in self.alternateURIs()])
 
79
 
 
80
                if name == "principal-url":
 
81
                    return davxml.PrincipalURL(davxml.HRef(self.principalURL()))
 
82
 
 
83
                if name == "group-member-set":
 
84
                    return davxml.GroupMemberSet(*[davxml.HRef(p) for p in self.groupMembers()])
 
85
 
 
86
                if name == "group-membership":
 
87
                    return davxml.GroupMemberSet(*[davxml.HRef(g) for g in self.groupMemberships()])
 
88
 
 
89
            return super(DAVPrincipalResource, self).readProperty(qname, request)
 
90
 
 
91
        return maybeDeferred(defer)
 
92
 
 
93
    ##
 
94
    # ACL
 
95
    ##
 
96
 
 
97
    def alternateURIs(self):
 
98
        """
 
99
        See L{IDAVPrincipalResource.alternateURIs}.
 
100
 
 
101
        This implementation returns C{()}.  Subclasses should override this
 
102
        method to provide alternate URIs for this resource if appropriate.
 
103
        """
 
104
        return ()
 
105
 
 
106
    def principalURL(self):
 
107
        """
 
108
        See L{IDAVPrincipalResource.principalURL}.
 
109
 
 
110
        This implementation raises L{NotImplementedError}.  Subclasses must
 
111
        override this method to provide the principal URL for this resource.
 
112
        """
 
113
        unimplemented(self)
 
114
 
 
115
    def groupMembers(self):
 
116
        """
 
117
        See L{IDAVPrincipalResource.groupMembers}.
 
118
 
 
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.
 
122
        """
 
123
        return ()
 
124
 
 
125
    def groupMemberships(self):
 
126
        """
 
127
        See L{IDAVPrincipalResource.groupMemberships}.
 
128
 
 
129
        This implementation raises L{NotImplementedError}.  Subclasses must
 
130
        override this method to provide the group URLs for this resource.
 
131
        """
 
132
        unimplemented(self)
 
133