Beispiel #1
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
Beispiel #2
0
 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))