summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2017-12-06 19:34:32 -0200
committerdrebs <drebs@leap.se>2017-12-13 13:43:47 -0200
commit03b4b4c410252af0a85dd94cb0b3a91eaca9b9a4 (patch)
tree826e000cbf9e6d8bd4808322727368a803c3901d /src
parentfc0725b0827b6f5e02f1d155712b106b3c8854c1 (diff)
[refactor] make blobs backend read_blob() agnostic of twisted.web
Diffstat (limited to 'src')
-rw-r--r--src/leap/soledad/server/_blobs.py10
-rw-r--r--src/leap/soledad/server/interfaces.py16
2 files changed, 9 insertions, 17 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=''):