Fig bug in split_buffer where input was being discarded
Also, write some tests for it.
This commit is contained in:
parent
84667636a2
commit
e8472be6d5
3 changed files with 64 additions and 19 deletions
|
|
@ -83,3 +83,28 @@ def mkdir(path, permissions=0o700):
|
|||
|
||||
def docker_url():
|
||||
return os.environ.get('DOCKER_HOST')
|
||||
|
||||
|
||||
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.
|
||||
|
||||
Unlike string.split(), each chunk includes the trailing
|
||||
separator, except for the last one if none was found on the end
|
||||
of the input.
|
||||
"""
|
||||
buffered = str('')
|
||||
separator = str(separator)
|
||||
|
||||
for data in reader:
|
||||
buffered += data
|
||||
while True:
|
||||
index = buffered.find(separator)
|
||||
if index == -1:
|
||||
break
|
||||
yield buffered[:index+1]
|
||||
buffered = buffered[index+1:]
|
||||
|
||||
if len(buffered) > 0:
|
||||
yield buffered
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue