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