summaryrefslogtreecommitdiff
path: root/src/leap/soledad/client/_db
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/soledad/client/_db')
-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: