summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2015-09-23 15:43:06 -0300
committerVictor Shyba <victor.shyba@gmail.com>2015-09-24 19:40:51 -0300
commit5b20b469f22ab99533135beefd49129db49064e5 (patch)
tree23b9e92a0d0c6500cf8db3c6e1fa7f9a1907b311
parentdf8c794395ee695ea1dfb30603a073b32b24ee58 (diff)
[style] pep8
-rw-r--r--common/src/leap/soledad/common/couch.py15
-rw-r--r--server/src/leap/soledad/server/state.py24
2 files changed, 20 insertions, 19 deletions
diff --git a/common/src/leap/soledad/common/couch.py b/common/src/leap/soledad/common/couch.py
index 00a17715..38041c09 100644
--- a/common/src/leap/soledad/common/couch.py
+++ b/common/src/leap/soledad/common/couch.py
@@ -719,7 +719,8 @@ class CouchDatabase(CommonBackend):
return None
return self.__parse_doc_from_couch(result, doc_id, check_for_conflicts)
- def __parse_doc_from_couch(self, result, doc_id, check_for_conflicts=False):
+ def __parse_doc_from_couch(self, result, doc_id,
+ check_for_conflicts=False):
# restrict to u1db documents
if 'u1db_rev' not in result:
return None
@@ -1155,7 +1156,8 @@ class CouchDatabase(CommonBackend):
:param sync_id: The id of the current sync session.
:type sync_id: str
"""
- self.cache[other_replica_uid] = (other_generation, other_transaction_id)
+ self.cache[other_replica_uid] = (other_generation,
+ other_transaction_id)
doc_id = 'u1db_sync_%s' % other_replica_uid
try:
doc = self._database[doc_id]
@@ -1164,7 +1166,6 @@ class CouchDatabase(CommonBackend):
doc['generation'] = other_generation
doc['transaction_id'] = other_transaction_id
self._database.save(doc)
- self.cache[other_replica_uid] = (other_generation, other_transaction_id)
def _force_doc_sync_conflict(self, doc):
"""
@@ -1175,7 +1176,8 @@ class CouchDatabase(CommonBackend):
"""
my_doc = self._get_doc(doc.doc_id)
self._prune_conflicts(doc, vectorclock.VectorClockRev(doc.rev))
- doc.add_conflict(self._factory(doc.doc_id, my_doc.rev, my_doc.get_json()))
+ doc.add_conflict(self._factory(doc.doc_id, my_doc.rev,
+ my_doc.get_json()))
doc.has_conflicts = True
self._put_doc(my_doc, doc)
@@ -1293,8 +1295,9 @@ class CouchDatabase(CommonBackend):
my_doc = self._get_doc(doc.doc_id, check_for_conflicts=True)
if my_doc:
doc.set_conflicts(my_doc.get_conflicts())
- return CommonBackend._put_doc_if_newer(self, doc, save_conflict, replica_uid,
- replica_gen, replica_trans_id)
+ return CommonBackend._put_doc_if_newer(self, doc, save_conflict,
+ replica_uid, replica_gen,
+ replica_trans_id)
def _put_and_update_indexes(self, cur_doc, doc):
self._put_doc(cur_doc, doc)
diff --git a/server/src/leap/soledad/server/state.py b/server/src/leap/soledad/server/state.py
index d1225170..f269b77e 100644
--- a/server/src/leap/soledad/server/state.py
+++ b/server/src/leap/soledad/server/state.py
@@ -24,7 +24,8 @@ class ServerSyncState(object):
"""
The state of one sync session, as stored on backend server.
- On server side, the ongoing syncs metadata is maintained in a caching layer.
+ On server side, the ongoing syncs metadata is maintained in
+ a caching layer.
"""
def __init__(self, source_replica_uid, sync_id):
@@ -38,7 +39,8 @@ class ServerSyncState(object):
"""
self._source_replica_uid = source_replica_uid
self._sync_id = sync_id
- self._storage = caching.get_cache_for(source_replica_uid + sync_id)
+ caching_key = source_replica_uid + sync_id
+ self._storage = caching.get_cache_for(caching_key)
def _put_dict_info(self, key, value):
"""
@@ -61,7 +63,7 @@ class ServerSyncState(object):
:param seen_id: The doc_id of a document seen during sync.
:type seen_id: str
- :param gen: The corresponding db generation for that document.
+ :param gen: The corresponding db generation.
:type gen: int
"""
self._put_dict_info(
@@ -113,12 +115,9 @@ class ServerSyncState(object):
server.
:rtype: tuple
"""
- info = self._storage.get('changes_to_return') if 'changes_to_return' in self._storage else None
- gen = None
- trans_id = None
- number_of_changes = None
- if info:
- info = info[0]
+ gen = trans_id = number_of_changes = None
+ if 'changes_to_return' in self._storage:
+ info = self._storage.get('changes_to_return')[0]
gen = info['gen']
trans_id = info['trans_id']
number_of_changes = len(info['changes_to_return'])
@@ -132,12 +131,11 @@ class ServerSyncState(object):
received during the current sync process.
:type received: int
"""
- info = self._storage.get('changes_to_return') if 'changes_to_return' in self._storage else None
gen = trans_id = next_change_to_return = None
- if info:
- info = info[0]
+ if 'changes_to_return' in self._storage:
+ info = self._storage.get('changes_to_return')[0]
gen = info['gen']
trans_id = info['trans_id']
if received < len(info['changes_to_return']):
- next_change_to_return = tuple(info['changes_to_return'][received])
+ next_change_to_return = (info['changes_to_return'][received])
return gen, trans_id, next_change_to_return