Esempio n. 1
0
    def lock(self, uri, lock_data):
        """ Lock (may create) resource.
            Data is a dict, may contain:
                depth, token, refresh, lockscope, locktype, owner
        """
        cr, uid, pool, dbname, uri2 = self.get_cr(uri)
        created = False
        if not dbname:
            raise DAV_Error, 409

        try:
            node = self.uri2object(cr, uid, pool, uri2[:])
        except Exception:
            node = False

        objname = misc.ustr(uri2[-1])

        if not node:
            dir_node = self.uri2object(cr, uid, pool, uri2[:-1])
            if not dir_node:
                raise DAV_NotFound('Parent folder not found.')

            # We create a new node (file) but with empty data=None,
            # as in RFC4918 p. 9.10.4
            node = self._try_function(dir_node.create_child,
                                      (cr, objname, None),
                                      "create %s" % objname,
                                      cr=cr)
            if not node:
                cr.commit()
                raise DAV_Error(400, "Failed to create resource.")

            created = True

        try:
            node_fn = node.dav_lock
        except AttributeError:
            # perhaps the node doesn't support locks
            raise DAV_Error(400, 'No locks for this resource.')

        # Obtain the lock on the node
        lres, pid, token = self._try_function(node_fn, (cr, lock_data),
                                              "lock %s" % objname,
                                              cr=cr)

        if not lres:
            cr.commit()
            raise DAV_Error(423, "Resource already locked.")

        assert isinstance(lres, list), 'lres: %s' % repr(lres)

        try:
            data = mk_lock_response(self, uri, lres)
            cr.commit()
        except Exception:
            raise

        return created, data, token
Esempio n. 2
0
    def put(self, uri, data, content_type=None):
        """ put the object into the filesystem """
        self.parent.log_message(
            'Putting %s (%d), %s' %
            (misc.ustr(uri), data and len(data) or 0, content_type))
        cr, uid, pool, dbname, uri2 = self.get_cr(uri)
        if not dbname:
            if cr: cr.close()
            raise DAV_Forbidden
        try:
            node = self.uri2object(cr, uid, pool, uri2[:])
        except Exception:
            node = False

        objname = misc.ustr(uri2[-1])

        ret = None
        if not node:
            dir_node = self.uri2object(cr, uid, pool, uri2[:-1])
            if not dir_node:
                cr.close()
                raise DAV_NotFound('Parent folder not found')

            newchild = self._try_function(dir_node.create_child,
                                          (cr, objname, data),
                                          "create %s" % objname,
                                          cr=cr)
            if not newchild:
                cr.commit()
                cr.close()
                raise DAV_Error(400, "Failed to create resource")

            uparts = urlparse.urlparse(uri)
            fileloc = '/'.join(newchild.full_path())
            if isinstance(fileloc, unicode):
                fileloc = fileloc.encode('utf-8')
            # the uri we get is a mangled one, where the davpath has been removed
            davpath = self.parent.get_davpath()

            surl = '%s://%s' % (uparts[0], uparts[1])
            uloc = urllib.quote(fileloc)
            hurl = False
            if uri != ('/' + uloc) and uri != (surl + '/' + uloc):
                hurl = '%s%s/%s/%s' % (surl, davpath, dbname, uloc)
            etag = False
            try:
                etag = str(newchild.get_etag(cr))
            except Exception, e:
                self.parent.log_error("Cannot get etag for node: %s" % e)
            ret = (str(hurl), etag)
Esempio n. 3
0
 def __init__(self, *args):
     if len(args) and isinstance(args[0], (tuple, list)):
         path = ''.join(['/' + x for x in args[0]])
         args = (path, )
     DAV_NotFound.__init__(self, *args)
Esempio n. 4
0
 def __init__(self, *args):
     if len(args) and isinstance(args[0], (tuple, list)):
         path = ''.join([ '/' + x for x in args[0]])
         args = (path, )
     DAV_NotFound.__init__(self, *args)