Fix line buffering when there's UTF-8 in a container's output

This commit is contained in:
Aanand Prasad 2014-01-09 16:19:22 +00:00
parent 7a4b69edc0
commit 059d240824
1 changed files with 6 additions and 1 deletions

View File

@ -55,10 +55,15 @@ def read_websocket(websocket):
break
def split_buffer(reader, separator):
"""
Given a generator which yields strings and a separator string,
joins all input, splits on the separator and yields each chunk.
Requires that each input string is decodable as UTF-8.
"""
buffered = ''
for data in reader:
lines = (buffered + data).split(separator)
lines = (buffered + data.decode('utf-8')).split(separator)
for line in lines[:-1]:
yield line + separator
if len(lines) > 1: