summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2016-11-16 19:09:15 -0300
committerVictor Shyba <victor1984@riseup.net>2016-11-18 15:55:52 -0300
commitf64bacefae087465d4913ac0a34fdb5b572659ff (patch)
tree55ed4ee017a7bfbc7c19b627175fb8f441590a1f
parentb0a0121a60ed60787f3f14e229705748ec082a15 (diff)
[refactor] remove assert logic from fetch_protocol
Asserts aren't a good solution for stream parsing, its cleaner to check and raise in place. Also, asserts can be ignored.
-rw-r--r--client/src/leap/soledad/client/http_target/fetch_protocol.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/client/src/leap/soledad/client/http_target/fetch_protocol.py b/client/src/leap/soledad/client/http_target/fetch_protocol.py
index 4290785d..a15991f3 100644
--- a/client/src/leap/soledad/client/http_target/fetch_protocol.py
+++ b/client/src/leap/soledad/client/http_target/fetch_protocol.py
@@ -90,11 +90,8 @@ class DocStreamReceiver(ReadBodyProtocol):
lines = self.consumeBufferLines()
while lines:
line, _ = utils.check_and_strip_comma(lines.pop(0))
- try:
- self.lineReceived(line)
- self._line += 1
- except AssertionError, e:
- raise errors.BrokenSyncStream(e)
+ self.lineReceived(line)
+ self._line += 1
def lineReceived(self, line):
"""
@@ -105,18 +102,22 @@ class DocStreamReceiver(ReadBodyProtocol):
(odd): {data},\r\n
(last): ]
"""
- assert not self._properly_finished
+ if self._properly_finished:
+ raise errors.BrokenSyncStream("Reading a finished stream")
if ']' == line:
self._properly_finished = True
elif self._line == 0:
- assert line == '['
+ if line is not '[':
+ raise errors.BrokenSyncStream("Invalid start")
elif self._line == 1:
self.metadata = line
- assert 'error' not in self.metadata
+ if 'error' in self.metadata:
+ raise errors.BrokenSyncStream("Error from server: %s" % line)
self.total = json.loads(line).get('number_of_changes', -1)
elif (self._line % 2) == 0:
self.current_doc = json.loads(line)
- assert 'error' not in self.current_doc
+ if 'error' in self.current_doc:
+ raise errors.BrokenSyncStream("Error from server: %s" % line)
else:
self._doc_reader(
self.current_doc, line.strip() or None, self.total)