Stream decoder now iterates more, fixes #155
This commit is contained in:
pare
d04d4d14fe
commit
f809e0029c
S'han modificat 1 arxius amb 20 adicions i 18 eliminacions
|
@ -58,24 +58,26 @@ 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:
|
||||||
try:
|
chunk_part = bytearray([chunk_part])
|
||||||
line = line_buffer.decode('utf-8')
|
if chunk_part == b'\n':
|
||||||
except UnicodeDecodeError as err:
|
try:
|
||||||
exception = MastodonMalformedEventError("Malformed UTF-8")
|
line = line_buffer.decode('utf-8')
|
||||||
self.on_abort(exception)
|
except UnicodeDecodeError as err:
|
||||||
six.raise_from(
|
exception = MastodonMalformedEventError("Malformed UTF-8")
|
||||||
exception,
|
self.on_abort(exception)
|
||||||
err
|
six.raise_from(
|
||||||
)
|
exception,
|
||||||
if line == '':
|
err
|
||||||
self._dispatch(event)
|
)
|
||||||
event = {}
|
if line == '':
|
||||||
|
self._dispatch(event)
|
||||||
|
event = {}
|
||||||
|
else:
|
||||||
|
event = self._parse_line(line, event)
|
||||||
|
line_buffer = bytearray()
|
||||||
else:
|
else:
|
||||||
event = self._parse_line(line, event)
|
line_buffer.extend(chunk_part)
|
||||||
line_buffer = bytearray()
|
|
||||||
else:
|
|
||||||
line_buffer.extend(chunk)
|
|
||||||
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)
|
||||||
|
|
Loading…
Referencia en una nova incidència