def split_buffer(stream, splitter=None, decoder=(lambda a: a)):
 splitter = (splitter or line_splitter)
 buffered = six.text_type(u'')
 for data in stream_as_text(stream):
  buffered += data
  while True:
   buffer_split = splitter(buffered)
   if (buffer_split is None):
    break
   (item, buffered) = buffer_split
   (yield item)
 if buffered:
  try:
   (yield decoder(buffered))
  except Exception as e:
   log.error((u'Compose tried decoding the following data chunk, but failed:\n%s' % repr(buffered)))
   raise StreamParseError(e)

def split_buffer ( stream , splitter = None , decoder = ( lambda a : a ) ) : splitter = ( splitter or line_splitter ) buffered = six . text_type ( u'' ) for data in stream_as_text ( stream ) : buffered += data while True : buffer_split = splitter ( buffered ) if ( buffer_split is None ) : break ( item , buffered ) = buffer_split ( yield item ) if buffered : try : ( yield decoder ( buffered ) ) except Exception as e : log . error ( ( u'Compose tried decoding the following data chunk, but failed:\n%s' % repr ( buffered ) ) ) raise StreamParseError ( e )
given a generator which yields strings and a splitter function .