Esempio n. 1
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.')
Esempio n. 2
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.')
Esempio n. 3
0
def isdir_alone(path):
    """
    Returns true when path is a directory without subdirectories
    """
    if check_if_forbidden(path, raise_error=False):
        return True
    child_dirs = [elem for elem in vfs.listdir(path) if vfs.isdir(path_join(path, elem))]
    if len(child_dirs) > 0:
        return False
    else:
        return True
Esempio n. 4
0
 def __call__(self):
     try:
         if vfs.isdir(self.path):
             if self.depth == 'infinity':
                 recursive=True
             else:
                 recursive=False
             vfs.removedir(self.path, recursive=recursive)
         else:
             vfs.remove(self.path)
     except FSError, e:
         ##FIXME: explanation too verbose?
         raise exc.HTTPForbidden(explanation=str(e))
Esempio n. 5
0
def check_if_forbidden(path, raise_error=True):
    """Raise an HTTPForbidden if there's any exception accessing file/dir"""
    # check if there are any exception
    try:
        if vfs.isdir(path):
            vfs.listdir(path)
        else:
            vfs.open(path).close()
    except FSError, e:
        if raise_error:
            ##FIXME: explanation too verbose?
            raise exc.HTTPForbidden(explanation=str(e))
        else:
            return True
Esempio n. 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)
Esempio n. 7
0
File: put.py Progetto: 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))
Esempio n. 8
0
    def gen_prop_tree(self, props, only_names=False):
        XMLroot = ET.Element("{DAV:}multistatus")
        XMLresp = ET.SubElement(XMLroot, "{DAV:}response")

        # depth==0: only this resource
        resources = [self.path]
        # depth==1: add resources of the collection
        if self.depth == "1":
            ##FIXME: fix unicode (most errors here!)
            resources.extend([path_join(self.path, res) for res in vfs.listdir(self.path)])

        for res in resources:
            XMLres_href = ET.SubElement(XMLresp, "{DAV:}href")
            XMLres_href.text = res
            XMLres_propstat = ET.SubElement(XMLresp, "{DAV:}propstat")
            XMLres_propstat_prop = ET.SubElement(XMLres_propstat, "{DAV:}prop")

            res_info = vfs.getinfo(res)
            if "{DAV:}creationdate" in props:
                prop = ET.SubElement(XMLres_propstat_prop, "{DAV:}creationdate")
                if not only_names:
                    prop.text = res_info["created_time"].strftime("%Y-%m-%dT%H:%M:%SZ")
            if "{DAV:}getcontentlength" in props:
                prop = ET.SubElement(XMLres_propstat_prop, "{DAV:}getcontentlength")
                if not only_names:
                    prop.text = str(res_info["size"])
            if "{DAV:}getlastmodified" in props:
                prop = ET.SubElement(XMLres_propstat_prop, "{DAV:}getlastmodified")
                if not only_names:
                    prop.text = res_info["modified_time"].strftime("%Y-%m-%dT%H:%M:%SZ")
            if "{DAV:}resourcetype" in props:
                restype = ET.SubElement(XMLres_propstat_prop, "{DAV:}resourcetype")
                if not only_names and vfs.isdir(res):
                    ET.SubElement(restype, "{DAV:}collection")
            ##FIXME: add DAV:supportedlock and DAV:lockdiscovery

            XMLres_propstat_status = ET.SubElement(XMLres_propstat, "{DAV:}status")
            XMLres_propstat_status.text = "HTTP/1.1 200 OK"
            # XMLres_propstat_status = ET.SubElement(XMLres_propstat, '{DAV:}status')
            # XMLres_propstat_status.text = 'HTTP/1.1 403 Forbidden'
            # XMLres_propstat_responsedescription = ET.SubElement(XMLres_propstat, '{DAV:}responsedescription')
            # XMLres_propstat_responsedescription.text = 'There has been an access violation error.'
        return XMLroot