Merge 793f0b207f
into d98a3546a3
This commit is contained in:
commit
976149edd4
S'han modificat 1 arxius amb 23 adicions i 20 eliminacions
|
@ -41,26 +41,29 @@ class StreamListener(object):
|
||||||
|
|
||||||
response; a requests response object with the open stream for reading.
|
response; a requests response object with the open stream for reading.
|
||||||
"""
|
"""
|
||||||
event = {}
|
try:
|
||||||
line_buffer = bytearray()
|
event = {}
|
||||||
for chunk in response.iter_content(chunk_size = 1):
|
line_buffer = bytearray()
|
||||||
if chunk:
|
for chunk in response.iter_content(chunk_size = 1):
|
||||||
if chunk == b'\n':
|
if chunk:
|
||||||
try:
|
if chunk == b'\n':
|
||||||
line = line_buffer.decode('utf-8')
|
try:
|
||||||
except UnicodeDecodeError as err:
|
line = line_buffer.decode('utf-8')
|
||||||
six.raise_from(
|
except UnicodeDecodeError as err:
|
||||||
MastodonMalformedEventError("Malformed UTF-8"),
|
six.raise_from(
|
||||||
err
|
MastodonMalformedEventError("Malformed UTF-8"),
|
||||||
)
|
err
|
||||||
if line == '':
|
)
|
||||||
self._dispatch(event)
|
if line == '':
|
||||||
event = {}
|
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)
|
||||||
line_buffer = bytearray()
|
except:
|
||||||
else:
|
pass
|
||||||
line_buffer.extend(chunk)
|
|
||||||
|
|
||||||
def _parse_line(self, line, event):
|
def _parse_line(self, line, event):
|
||||||
if line.startswith(':'):
|
if line.startswith(':'):
|
||||||
|
|
Loading…
Referencia en una nova incidència