diff options
-rw-r--r-- | src/leap/soledad/server/_blobs.py | 10 | ||||
-rw-r--r-- | src/leap/soledad/server/interfaces.py | 16 | ||||
-rw-r--r-- | tests/blobs/test_fs_backend.py | 3 |
3 files changed, 11 insertions, 18 deletions
diff --git a/src/leap/soledad/server/_blobs.py b/src/leap/soledad/server/_blobs.py index 2ba3fe91..bf370979 100644 --- a/src/leap/soledad/server/_blobs.py +++ b/src/leap/soledad/server/_blobs.py @@ -78,12 +78,12 @@ class FilesystemBlobsBackend(object): def __touch(self, path): open(path, 'a') - def read_blob(self, user, blob_id, request, namespace=''): + def read_blob(self, user, blob_id, namespace=''): logger.info('reading blob: %s - %s@%s' % (user, blob_id, namespace)) path = self._get_path(user, blob_id, namespace) logger.debug('blob path: %s' % path) - _file = static.File(path, defaultType='application/octet-stream') - return _file.render_GET(request) + res = static.File(path, defaultType='application/octet-stream') + return res def get_flags(self, user, blob_id, namespace=''): path = self._get_path(user, blob_id, namespace) @@ -295,8 +295,8 @@ class BlobsResource(resource.Resource): # 404 - Not Found request.setResponseCode(404) return "Blob doesn't exists: %s" % blob_id - return self._handler.read_blob(user, blob_id, request, - namespace=namespace) + res = self._handler.read_blob(user, blob_id, namespace=namespace) + return res.render_GET(request) def render_DELETE(self, request): logger.info("http put: %s" % request.path) diff --git a/src/leap/soledad/server/interfaces.py b/src/leap/soledad/server/interfaces.py index 430cdec3..3274dfdf 100644 --- a/src/leap/soledad/server/interfaces.py +++ b/src/leap/soledad/server/interfaces.py @@ -30,27 +30,19 @@ class IBlobsBackend(Interface): ``twisted.web.server.Request`` and should use them to serve the Blobs API. """ - def read_blob(user, blob_id, request, namespace=''): + def read_blob(user, blob_id, namespace=''): """ - Read a blob from the backend storage and write it as a response to a - request. + Read a blob from the backend storage return it as a twisted resource. :param user: The id of the user who owns the blob. :type user: str :param blob_id: The id of the blob. :type blob_id: str - :param request: A representation of all of the information about the - request that is being made. - :type request: twisted.web.server.Request :param namespace: An optional namespace for the blob. :type namespace: str - :return: Either ``server.NOT_DONE_YET`` to indicate an asynchronous - operation or a ``bytes`` instance to write as the response to the - request. If ``NOT_DONE_YET`` is returned, at some point later (for - example, in a Deferred callback) call ``request.write(b"data")`` to - write data to the request, and ``request.finish()`` to send the - data to the browser. + :return: The blob as a twisted resource. + :rtype: twisted.web.resource.Resource """ def write_blob(user, blob_id, request, namespace=''): diff --git a/tests/blobs/test_fs_backend.py b/tests/blobs/test_fs_backend.py index 5df658ff..58d8690d 100644 --- a/tests/blobs/test_fs_backend.py +++ b/tests/blobs/test_fs_backend.py @@ -66,7 +66,8 @@ class FilesystemBackendTestCase(unittest.TestCase): file_mock.return_value = render_mock backend = _blobs.FilesystemBlobsBackend(blobs_path=self.tempdir) request = DummyRequest(['']) - backend.read_blob('user', 'blob_id', request) + resource = backend.read_blob('user', 'blob_id') + resource.render_GET(request) backend._get_path.assert_called_once_with('user', 'blob_id', '') ctype = 'application/octet-stream' |