summaryrefslogtreecommitdiff
path: root/src/leap/soledad/client
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-07-08 07:04:49 -0300
committerdrebs <drebs@leap.se>2017-07-21 10:58:47 -0300
commit64107009a869a6ddb6cea129e65735d9740e697b (patch)
treedabe4ff46f652a864c95db59e4776b59f1114cb3 /src/leap/soledad/client
parenteb000dac7a66ea249adb8c9b7d154101b897311c (diff)
[feature] add get/set flags
IncomingBox spec has a flags feature for the processing flow of messages. This commit adds it using a .flags file. -- Resolves: #8869
Diffstat (limited to 'src/leap/soledad/client')
-rw-r--r--src/leap/soledad/client/_db/blobs.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/leap/soledad/client/_db/blobs.py b/src/leap/soledad/client/_db/blobs.py
index 604d4bef..f693ec20 100644
--- a/src/leap/soledad/client/_db/blobs.py
+++ b/src/leap/soledad/client/_db/blobs.py
@@ -22,6 +22,7 @@ from urlparse import urljoin
import binascii
import os
+import json
import base64
from io import BytesIO
@@ -57,6 +58,10 @@ class BlobAlreadyExistsError(SoledadError):
pass
+class InvalidFlagsError(SoledadError):
+ pass
+
+
class ConnectionPool(adbapi.ConnectionPool):
def insertAndGetLastRowid(self, *args, **kwargs):
@@ -106,6 +111,8 @@ class ConnectionPool(adbapi.ConnectionPool):
def check_http_status(code):
if code == 409:
raise BlobAlreadyExistsError()
+ elif code == 406:
+ raise InvalidFlagsError()
elif code != 200:
raise SoledadError("Server Error")
@@ -214,6 +221,24 @@ class BlobManager(object):
yield self._encrypt_and_upload(doc.blob_id, fd)
@defer.inlineCallbacks
+ def set_flags(self, blob_id, flags, **params):
+ flags = BytesIO(json.dumps(flags))
+ uri = urljoin(self.remote, self.user + "/" + blob_id)
+ response = yield self._client.post(uri, data=flags, params=params)
+ check_http_status(response.code)
+
+ @defer.inlineCallbacks
+ def get_flags(self, blob_id, **params):
+ uri = urljoin(self.remote, self.user + "/" + blob_id)
+ params.update({'only_flags': True})
+ data = yield self._client.get(uri, params=params)
+ try:
+ data = yield data.json()
+ except:
+ data = []
+ defer.returnValue(data)
+
+ @defer.inlineCallbacks
def get(self, blob_id):
local_blob = yield self.local.get(blob_id)
if local_blob: