diff options
author | drebs <drebs@leap.se> | 2017-12-08 22:48:02 -0200 |
---|---|---|
committer | drebs <drebs@leap.se> | 2017-12-13 13:49:27 -0200 |
commit | d5a30f5909a17c7d8ba661d35f73c5c09a7c0dc6 (patch) | |
tree | b4015baa8b9fd8e6ccb69a2c57617d0d6d58847d /src/leap/soledad | |
parent | 601ed3ed0ffb81d743201c3819d18f79cee850f5 (diff) |
[refactor] make get_flags() return a deferred
Diffstat (limited to 'src/leap/soledad')
-rw-r--r-- | src/leap/soledad/server/_blobs.py | 14 | ||||
-rw-r--r-- | src/leap/soledad/server/interfaces.py | 4 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/leap/soledad/server/_blobs.py b/src/leap/soledad/server/_blobs.py index 9d1c9b1e..5fe9c1b7 100644 --- a/src/leap/soledad/server/_blobs.py +++ b/src/leap/soledad/server/_blobs.py @@ -101,11 +101,12 @@ class FilesystemBlobsBackend(object): def get_flags(self, user, blob_id, namespace=''): path = self._get_path(user, blob_id, namespace) if not os.path.isfile(path): - raise BlobNotFound + return defer.fail(BlobNotFound) if not os.path.isfile(path + '.flags'): - return [] + return defer.succeed([]) with open(path + '.flags', 'r') as flags_file: - return json.loads(flags_file.read()) + flags = json.loads(flags_file.read()) + return defer.succeed(flags) def set_flags(self, user, blob_id, flags, namespace=''): path = self._get_path(user, blob_id, namespace) @@ -298,8 +299,11 @@ class BlobsResource(resource.Resource): only_flags = request.args.get('only_flags', [False])[0] try: if only_flags: - flags = self._handler.get_flags(user, blob_id, namespace) - return json.dumps(flags) + d = self._handler.get_flags(user, blob_id, namespace) + d.addCallback(lambda flags: json.dumps(flags)) + d.addCallback(lambda flags: request.write(flags)) + d.addCallback(lambda _: request.finish()) + return NOT_DONE_YET tag = self._handler.get_tag(user, blob_id, namespace) request.responseHeaders.setRawHeaders('Tag', [tag]) except BlobNotFound: diff --git a/src/leap/soledad/server/interfaces.py b/src/leap/soledad/server/interfaces.py index ecea0bf8..bd804573 100644 --- a/src/leap/soledad/server/interfaces.py +++ b/src/leap/soledad/server/interfaces.py @@ -173,8 +173,8 @@ class IBlobsBackend(Interface): :param namespace: An optional namespace for the blob. :type namespace: str - :return: a list of flags. - :rtype: list of str + :return: A deferred that fires with the list of flags for a blob. + :rtype: twisted.internet.defer.Deferred """ def set_flags(user, blob_id, flags, namespace=''): |