Example #1
0
 def __init__(self):
     path = request.path_info
     if request.body:
         raise exc.HTTPUnsupportedMediaType(explanation='MKCOL request must NOT provide an XML body.')
     
     self.path = path
     
     if vfs.exists(self.path):
         raise exc.HTTPMethodNotAllowed(explanation='MKCOL can only be executed on an unmapped URL.')
     
     basepath = re.sub(r'/[^/]+/?$', '', path)
     if not vfs.exists(basepath):
         raise exc.HTTPConflict(explanation='A collection cannot be made at the Request-URI until one or more intermediate collections have been created.')
Example #2
0
 def __call__(self):
     if vfs.exists(self.destination):
         if not self.overwrite:
             raise exc.HTTPPreconditionFailed(explanation='The destination URL is already mapped to a resource and Overwrite is F.')
         else:
             if vfs.isdir(self.destination):
                 vfs.removedir(self.destination, recursive=True)
             else:
                 vfs.remove(self.destination)
     ##FIXME: no Insufficient Storage notification
     if vfs.isdir(self.source):
         ##TODO: check for recursion (/A -> /A/B) or same resource (/A -> /A)
         #if ??RECURSION??:
         #    raise exc.HTTPForbidden(explanation='No recursion allowed.')
         if self.depth == 'infinity':
             try:
                 if self.copy_or_move == 'copy':
                     vfs.copydir(self.source, self.destination)
                 elif self.copy_or_move == 'move':
                     vfs.movedir(self.source, self.destination)
             except FSError, e:
                 ##FIXME: explanation too verbose?
                 raise exc.HTTPForbidden(explanation=str(e))
         elif self.depth == '0':
             raise exc.HTTPBadRequest(explanation='A depth of 0 is not implemented for collections.')
Example #3
0
 def __init__(self, copy_or_move):
     source = request.path_info
     destination = request.headers.get('Destination')
     depth = request.headers.get('Depth', 'infinity')
     overwrite = request.headers.get('Overwrite')
     if not destination:
         raise exc.HTTPBadRequest(expnalantion='Missing Destination header')
     if request.body:
         raise exc.HTTPUnsupportedMediaType(explanation='COPY request must NOT provide an XML body.')
     
     self.source = source
     self.destination = destination
     self.copy_or_move = copy_or_move
     
     if vfs.isdir(self.path):
         self.depth = depth
     else:
         self.depth = '0'
     
     if self.depth!='0' and self.depth!='infinity':
         raise exc.HTTPBadRequest(explanation='Bad Depth specification (%s)' %(self.depth))
     
     if overwrite == 'T':
         self.overwrite = True
     else:
         self.overwrite = False
     
     basepath = re.sub(r'/[^/]+/?$', '', destination)
     if not vfs.exists(basepath):
         raise exc.HTTPConflict(explanation='Creation of a resource without an appropriately scoped parent collection.')
Example #4
0
    def __init__(self):
        "Save and check a PROPFIND request, must call the instance to generate response"

        self.path = request.path_info
        # check if it exists...
        if not vfs.exists(self.path):
            raise exc.HTTPNotFound()
        check_if_forbidden(self.path)

        body = request.body
        if not body:
            raise exc.HTTPUnsupportedMediaType(explanation="PROPFIND request must provide an XML body.")

        self.xmlreq = ET.fromstring(body)

        # check if depth is correct...
        depth = request.headers.get("Depth", "infinity")
        if depth != "1" and depth != "0":
            raise exc.HTTPForbidden(explanation="PROPFIND only allows Depth of 0 or 1 (propfind-finite-depth).")
        else:
            self.depth = depth

        # if it's a file, depth must be 0
        if vfs.isfile(self.path):
            self.depth = "0"
Example #5
0
 def __init__(self):
     path = request.path_info
     depth = request.headers.get('Depth', 'infinity')
     if request.body:
         raise exc.HTTPUnsupportedMediaType(explanation='DELETE request must NOT provide an XML body.')
     
     self.path = path
     self.depth = depth
     
     if not vfs.exists(self.path):
         raise exc.HTTPNotFound()
Example #6
0
def serve_page():
    path = request.path_info
    action = request.GET.get('action')
    
    if not vfs.exists(path):
        raise exc.HTTPNotFound()
    
    check_if_forbidden(path)
    
    # action is not defined? use defaults...
    if not action:
        if vfs.isdir(path):
            action = 'listdir'
        else:
            action = 'view'
    
    return CONFIG['filemanager_backend'].run_action(action)
Example #7
0
File: put.py Project: mtpi/daffydav
 def __init__(self):
     self.path = request.path_info
     depth = request.headers.get('Depth', 'infinity')
     
     if request.body:
         raise exc.HTTPUnsupportedMediaType(explanation='DELETE request must NOT provide an XML body.')
     
     if vfs.isdir(self.path):
         raise exc.HTTPMethodNotAllowed(explanation='URI refers to an existing collection.')
     
     basepath = re.sub(r'/[^/]+/?$', '', path)
     if not vfs.exists(basepath):
         raise exc.HTTPConflict(explanation='Creation of a resource without an appropriately scoped parent collection.')
     
     try:
         self.file = vfs.open(path, mode='w')
     except FSError, e:
         ##FIXME: explanation too verbose?
         raise exc.HTTPForbidden(explanation=str(e))