Stream decoder now iterates more, fixes #155

This commit is contained in:
Lorenz Diener 2019-04-27 18:35:47 +02:00
pare d04d4d14fe
commit f809e0029c

Veure arxiu

@ -58,7 +58,9 @@ class StreamListener(object):
try: try:
for chunk in response.iter_content(chunk_size = 1): for chunk in response.iter_content(chunk_size = 1):
if chunk: if chunk:
if chunk == b'\n': for chunk_part in chunk:
chunk_part = bytearray([chunk_part])
if chunk_part == b'\n':
try: try:
line = line_buffer.decode('utf-8') line = line_buffer.decode('utf-8')
except UnicodeDecodeError as err: except UnicodeDecodeError as err:
@ -75,7 +77,7 @@ class StreamListener(object):
event = self._parse_line(line, event) event = self._parse_line(line, event)
line_buffer = bytearray() line_buffer = bytearray()
else: else:
line_buffer.extend(chunk) line_buffer.extend(chunk_part)
except ChunkedEncodingError as err: except ChunkedEncodingError as err:
exception = MastodonNetworkError("Server ceased communication.") exception = MastodonNetworkError("Server ceased communication.")
self.on_abort(exception) self.on_abort(exception)