From 06ade52b27800ca94c1abf73964975a5bf717f04 Mon Sep 17 00:00:00 2001 From: drebs Date: Wed, 6 Dec 2017 20:37:55 -0200 Subject: [refactor] make blobs backend delete_blob() agnostic of twisted.web requests --- src/leap/soledad/server/_blobs.py | 13 ++++++++----- src/leap/soledad/server/interfaces.py | 5 ----- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'src/leap/soledad') diff --git a/src/leap/soledad/server/_blobs.py b/src/leap/soledad/server/_blobs.py index 86bbcdcb..c0b3b237 100644 --- a/src/leap/soledad/server/_blobs.py +++ b/src/leap/soledad/server/_blobs.py @@ -137,11 +137,10 @@ class FilesystemBlobsBackend(object): yield fbp.startProducing(blobfile) yield self.semaphore.release() - def delete_blob(self, user, blob_id, request, namespace=''): + def delete_blob(self, user, blob_id, namespace=''): blob_path = self._get_path(user, blob_id, namespace) if not os.path.isfile(blob_path): - request.setResponseCode(404) - return "Blob doesn't exists: %s" % blob_id + raise BlobNotFound self.__touch(blob_path + '.deleted') os.unlink(blob_path) try: @@ -304,8 +303,12 @@ class BlobsResource(resource.Resource): def render_DELETE(self, request): logger.info("http put: %s" % request.path) user, blob_id, namespace = self._validate(request) - self._handler.delete_blob(user, blob_id, request, namespace=namespace) - return '' + try: + self._handler.delete_blob(user, blob_id, namespace=namespace) + return '' + except BlobNotFound: + request.setResponseCode(404) + return "Blob doesn't exists: %s" % blob_id def render_PUT(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 11d75f11..3bf6eaa9 100644 --- a/src/leap/soledad/server/interfaces.py +++ b/src/leap/soledad/server/interfaces.py @@ -23,11 +23,6 @@ class IBlobsBackend(Interface): """ An interface for a backend that can store blobs. - - Classes that implement this interface are supposed to be used by - ``BlobsResource``, which is a ``twisted.web.resource.Resource`` that serves - the Blobs API. Because of that, their methods receive instances of - ``twisted.web.server.Request`` and should use them to serve the Blobs API. """ def read_blob(user, blob_id, namespace=''): -- cgit v1.2.3