diff options
author | Victor Shyba <victor1984@riseup.net> | 2017-12-04 11:24:35 -0300 |
---|---|---|
committer | Victor Shyba <victor1984@riseup.net> | 2017-12-04 11:24:35 -0300 |
commit | 4afbe7fa6aee038bcaaf4c1c377d7e6921096d27 (patch) | |
tree | 86c197288d755c7d74daad8b0cf00c07b4936b9b | |
parent | 91f6ecf09ebb03f584ceabb85effb45b5ef08f3e (diff) |
[style] fixes from code review
-rw-r--r-- | src/leap/soledad/client/_db/blobs/__init__.py | 15 | ||||
-rw-r--r-- | src/leap/soledad/server/_streaming_resource.py | 2 | ||||
-rw-r--r-- | src/leap/soledad/server/url_mapper.py | 4 |
3 files changed, 12 insertions, 9 deletions
diff --git a/src/leap/soledad/client/_db/blobs/__init__.py b/src/leap/soledad/client/_db/blobs/__init__.py index 3daf8d1a..b7b8ad1f 100644 --- a/src/leap/soledad/client/_db/blobs/__init__.py +++ b/src/leap/soledad/client/_db/blobs/__init__.py @@ -56,6 +56,7 @@ from .errors import ( logger = Logger() FIXED_REV = 'ImmutableRevision' # Blob content is immutable +SEPARATOR = ' ' def check_http_status(code, blob_id=None, flags=None): @@ -112,20 +113,22 @@ class StreamDecrypterBuffer(object): self.blobs_list = blobs_list self.secret = secret self.done_callback = done_callback + # self.buf is used to collect size and tag, before becoming a + # DecrypterBuffer, which then gets used to process the content. self.buf = b'' self.reset() def reset(self): - self.current_blob_size = False + self.current_blob_size = None self.current_blob_id = None self.received = 0 def write(self, data): if not self.current_blob_size: self.buf += data - if ' ' in self.buf: + if SEPARATOR in self.buf: marker, self.buf = self.buf.split(' ') - assert(len(marker) == 20) # 16 byte tag + 4 byte size + assert(len(marker) == 20) # 4 byte size + 16 byte tag size, tag = marker[:4], marker[4:] self.current_blob_size = self.size_pack.unpack(size)[0] self.received = len(self.buf) @@ -181,8 +184,8 @@ class BlobManager(BlobsSynchronizer): :type token: str :param cert_file: The path to the CA certificate file. :type cert_file: str - :param cert_file: Remote storage stream URL, if supported. - :type cert_file: str + :param remote_stream: Remote storage stream URL, if supported. + :type remote_stream: str """ super(BlobsSynchronizer, self).__init__() if local_path: @@ -480,7 +483,7 @@ class BlobManager(BlobsSynchronizer): def _downstream(self, blobs_id_list, namespace=''): uri = urljoin(self.remote_stream, self.user) params = {'namespace': namespace} if namespace else None - data = BytesIO(json.dumps(list(blobs_id_list))) + data = BytesIO(json.dumps(blobs_id_list)) response = yield self._client.post(uri, params=params, data=data) deferreds = [] diff --git a/src/leap/soledad/server/_streaming_resource.py b/src/leap/soledad/server/_streaming_resource.py index f96220b0..8ce304d1 100644 --- a/src/leap/soledad/server/_streaming_resource.py +++ b/src/leap/soledad/server/_streaming_resource.py @@ -16,7 +16,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. """ A twisted resource that serves download as a single stream of multiple blobs. --> POST .../uuid/namespace/ DATA: [blob_id, blob_id2, ..., blob_idn] +-> POST .../uuid/ DATA: [blob_id, blob_id2, ..., blob_idn] <- [(size(blob_id), content(blob_id)) for blob_id in DATA] (as a binary stream) """ import json diff --git a/src/leap/soledad/server/url_mapper.py b/src/leap/soledad/server/url_mapper.py index a658b712..21e81b7c 100644 --- a/src/leap/soledad/server/url_mapper.py +++ b/src/leap/soledad/server/url_mapper.py @@ -60,7 +60,7 @@ class URLMapper(object): /blobs/{uuid}/{blob_id} | GET, PUT, DELETE, POST /blobs/{uuid} | GET /incoming/ | PUT - /stream/{uuid}/{namespace} | POST + /stream/{uuid}/ | POST """ # global resource self._connect('/', ['GET']) @@ -79,6 +79,6 @@ class URLMapper(object): ['GET', 'PUT', 'DELETE', 'POST']) self._connect('/blobs/{uuid}/', ['GET']) # streaming resource - self._connect('/stream/{uuid}/{namespace}', ['POST']) + self._connect('/stream/{uuid}/', ['POST']) # incoming resource self._connect('/incoming/{target_user_uuid}/{incoming_id}', ['PUT']) |