This file is indexed.

/usr/share/pyshared/DAV/iface.py is in python-webdav 0.9.4.1-1build1.

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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#Copyright (c) 1999 Christian Scholz (ruebe@aachen.heimat.de)
#
#This library is free software; you can redistribute it and/or
#modify it under the terms of the GNU Library General Public
#License as published by the Free Software Foundation; either
#version 2 of the License, or (at your option) any later version.
#
#This library is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#Library General Public License for more details.
#
#You should have received a copy of the GNU Library General Public
#License along with this library; if not, write to the Free
#Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
#MA 02111-1307, USA

"""

basic interface class

use this for subclassing when writing your own interface
class.

"""

from xml.dom import minidom
from locks import LockManager
from errors import *

import time
from string import lower

class dav_interface:
    """ interface class for implementing DAV servers """

    ### defined properties (modify this but let the DAV stuff there!)
    ### the format is namespace: [list of properties]

    PROPS={"DAV:" : ('creationdate',
                     'displayname',
                     'getcontentlanguage',
                     'getcontentlength',
                     'getcontenttype',
                     'getetag',
                     'getlastmodified',
                     'lockdiscovery',
                     'resourcetype',
                     'source',
                     'supportedlock'),
           "NS2" : ("p1","p2")
           }

    # here we define which methods handle which namespace
    # the first item is the namespace URI and the second one
    # the method prefix
    # e.g. for DAV:getcontenttype we call dav_getcontenttype()
    M_NS={"DAV:" : "_get_dav",
          "NS2"  : "ns2" }

    def get_propnames(self,uri):
        """ return the property names allowed for the given URI

        In this method we simply return the above defined properties
        assuming that they are valid for any resource.
        You can override this in order to return a different set
        of property names for each resource.

        """
        return self.PROPS

    def get_prop2(self,uri,ns,pname):
        """ return the value of a property


        """
        if lower(ns)=="dav:": return self.get_dav(uri,pname)

        raise DAV_NotFound

    def get_prop(self,uri,ns,propname):
        """ return the value of a given property

        uri        -- uri of the object to get the property of
        ns        -- namespace of the property
        pname        -- name of the property
        """
        if self.M_NS.has_key(ns):
            prefix=self.M_NS[ns]
        else:
            raise DAV_NotFound
        mname=prefix+"_"+propname.replace('-', '_')
        try:
            m=getattr(self,mname)
            r=m(uri)
            return r
        except AttributeError:
            raise DAV_NotFound

    ###
    ### DATA methods (for GET and PUT)
    ###

    def get_data(self, uri, range=None):
        """ return the content of an object

        return data or raise an exception

        """
        raise DAV_NotFound

    def put(self, uri, data, content_type=None):
        """ write an object to the repository

        return the location uri or raise an exception
        """

        raise DAV_Forbidden

    ###
    ### LOCKing information
    ###
    def _get_dav_supportedlock(self, uri):

        txt = ('<main xmlns:D="http://dummy/d" xmlns:ns1="http://webdav.de/ns1"><D:lockentry>\n'
                '<D:lockscope><D:exclusive></D:exclusive></D:lockscope>\n'
                '<D:locktype><D:write></D:write></D:locktype>\n'
                '</D:lockentry></main>\n')
        xml = minidom.parseString(txt)
        return xml.firstChild.firstChild

    def _get_dav_lockdiscovery(self, uri):
        lcm = LockManager()
        if lcm._l_isLocked(uri):
            lock = lcm._l_getLockForUri(uri)
            txt = lock.asXML(discover=True, namespace='D')

            txtwithns = '<main xmlns:D="http://dummy/D" xmlns:n="http://webdav.de/N">%s</main>'
            xml = minidom.parseString(txtwithns % txt)
            return xml.firstChild.firstChild

        return ''

    ###
    ### Methods for DAV properties
    ###

    def _get_dav_creationdate(self,uri):
        """ return the creationdate of a resource """
        d=self.get_creationdate(uri)
        # format it
        return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(d))

    def _get_dav_getlastmodified(self,uri):
        """ return the last modified date of a resource """
        d=self.get_lastmodified(uri)
        # format it
        return time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(d))


    ###
    ### OVERRIDE THESE!
    ###

    def get_creationdate(self,uri):
        """ return the creationdate of the resource """
        return time.time()

    def get_lastmodified(self,uri):
        """ return the last modification date of the resource """
        return time.time()


    ###
    ### COPY MOVE DELETE
    ###

    ### methods for deleting a resource

    def rmcol(self,uri):
        """ delete a collection 

        This should not delete any children! This is automatically done
        before by the DELETE class in DAV/delete.py

        return a success code or raise an exception

        """
        raise DAV_NotFound

    def rm(self,uri):
        """ delete a single resource 

        return a success code or raise an exception

        """
        raise DAV_NotFound

    """

    COPY/MOVE HANDLER

    These handler are called when a COPY or MOVE method is invoked by
    a client. In the default implementation it works as follows:

    - the davserver receives a COPY/MOVE method
    - the davcopy or davmove module will be loaded and the corresponding
      class will be initialized
    - this class parses the query and decides which method of the interface class
      to call:

      copyone for a single resource to copy
      copytree for a tree to copy (collection)
      (the same goes for move of course).

    - the interface class has now two options:
        1. to handle the action directly (e.g. cp or mv on filesystems)
        2. to let it handle via the copy/move methods in davcmd.

    ad 1) The first approach can be used when we know that no error can 
          happen inside a tree or when the action can exactly tell which
          element made which error. We have to collect these and return
          it in a dict of the form {uri: error_code, ...}

    ad 2) The copytree/movetree/... methods of davcmd.py will do the recursion
          themselves and call for each resource the copy/move method of the
          interface class. Thus method will then only act on a single resource.
          (Thus a copycol on a normal unix filesystem actually only needs to do
          an mkdir as the content will be copied by the davcmd.py function.
          The davcmd.py method will also automatically collect all errors and
          return the dictionary described above.
          When you use 2) you also have to implement the copy() and copycol()
          methods in your interface class. See the example for details.

    To decide which approach is the best you have to decide if your application
    is able to generate errors inside a tree. E.g. a function which completely
    fails on a tree if one of the tree's childs fail is not what we need. Then
    2) would be your way of doing it.
    Actually usually 2) is the better solution and should only be replaced by
    1) if you really need it.

    The remaining question is if we should do the same for the DELETE method.

    """

    ### MOVE handlers

    def moveone(self,src,dst,overwrite):
        """ move one resource with Depth=0 """
        return moveone(self,src,dst,overwrite)

    def movetree(self,src,dst,overwrite):
        """ move a collection with Depth=infinity """
        return movetree(self,src,dst,overwrite)

    ### COPY handlers

    def copyone(self,src,dst,overwrite):
        """ copy one resource with Depth=0 """
        return copyone(self,src,dst,overwrite)

    def copytree(self,src,dst,overwrite):
        """ copy a collection with Depth=infinity """
        return copytree(self,src,dst,overwrite)


    ### low level copy methods (you only need these for method 2)
    def copy(self,src,dst):
        """ copy a resource with depth==0 

        You don't need to bother about overwrite or not.
        This has been done already.

        return a success code or raise an exception if something fails
        """
        return 201


    def copycol(self,src,dst):
        """ copy a resource with depth==infinity 

        You don't need to bother about overwrite or not.
        This has been done already.

        return a success code or raise an exception if something fails
        """
        return 201

    ### some utility functions you need to implement

    def exists(self,uri):
        """ return 1 or None depending on if a resource exists """
        return None # no

    def is_collection(self,uri):
        """ return 1 or None depending on if a resource is a collection """
        return None # no