aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2019-04-27 18:35:47 +0200
committerLorenz Diener <[email protected]>2019-04-27 18:35:47 +0200
commitf809e0029c91d1549124586f08bd7fd636aa0dc6 (patch)
treefb30bf0b3ed0209b8b9d64180ea99495bf68edf2
parentd04d4d14feaf9d33c9007c9644caf387bed278bc (diff)
downloadmastodon.py-f809e0029c91d1549124586f08bd7fd636aa0dc6.tar.gz
Stream decoder now iterates more, fixes #155
-rw-r--r--mastodon/streaming.py38
1 files changed, 20 insertions, 18 deletions
diff --git a/mastodon/streaming.py b/mastodon/streaming.py
index 65ec30a..1e1eefd 100644
--- a/mastodon/streaming.py
+++ b/mastodon/streaming.py
@@ -58,24 +58,26 @@ class StreamListener(object):
58 try: 58 try:
59 for chunk in response.iter_content(chunk_size = 1): 59 for chunk in response.iter_content(chunk_size = 1):
60 if chunk: 60 if chunk:
61 if chunk == b'\n': 61 for chunk_part in chunk:
62 try: 62 chunk_part = bytearray([chunk_part])
63 line = line_buffer.decode('utf-8') 63 if chunk_part == b'\n':
64 except UnicodeDecodeError as err: 64 try:
65 exception = MastodonMalformedEventError("Malformed UTF-8") 65 line = line_buffer.decode('utf-8')
66 self.on_abort(exception) 66 except UnicodeDecodeError as err:
67 six.raise_from( 67 exception = MastodonMalformedEventError("Malformed UTF-8")
68 exception, 68 self.on_abort(exception)
69 err 69 six.raise_from(
70 ) 70 exception,
71 if line == '': 71 err
72 self._dispatch(event) 72 )
73 event = {} 73 if line == '':
74 self._dispatch(event)
75 event = {}
76 else:
77 event = self._parse_line(line, event)
78 line_buffer = bytearray()
74 else: 79 else:
75 event = self._parse_line(line, event) 80 line_buffer.extend(chunk_part)
76 line_buffer = bytearray()
77 else:
78 line_buffer.extend(chunk)
79 except ChunkedEncodingError as err: 81 except ChunkedEncodingError as err:
80 exception = MastodonNetworkError("Server ceased communication.") 82 exception = MastodonNetworkError("Server ceased communication.")
81 self.on_abort(exception) 83 self.on_abort(exception)
@@ -175,4 +177,4 @@ class CallbackStreamListener(StreamListener):
175 177
176 def on_notification(self, notification): 178 def on_notification(self, notification):
177 if self.notification_handler != None: 179 if self.notification_handler != None:
178 self.notification_handler(notification) \ No newline at end of file 180 self.notification_handler(notification)
Powered by cgit v1.2.3 (git 2.41.0)