From 4afbe7fa6aee038bcaaf4c1c377d7e6921096d27 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Mon, 4 Dec 2017 11:24:35 -0300 Subject: [style] fixes from code review --- src/leap/soledad/client/_db/blobs/__init__.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/leap/soledad/client/_db') 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 = [] -- cgit v1.2.3