diff options
author | Victor Shyba <victor1984@riseup.net> | 2016-11-16 19:09:15 -0300 |
---|---|---|
committer | drebs <drebs@leap.se> | 2016-12-12 09:12:01 -0200 |
commit | ec4a1d773609a922734f36bfe2360c7e622ff155 (patch) | |
tree | ecae78e403a417b5e9c8aee7e230974379222484 | |
parent | cc81bb2a8ed0e989159f17061a567230a5059c21 (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.py | 19 |
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) |