def to_lines(chunks):
 leftovers = []
 for chunk in chunks:
  start = 0
  while (start < len(chunk)):
   end = (chunk.find('\n', start) + 1)
   if (end == 0):
    leftovers.append(chunk[start:])
    break
   if leftovers:
    leftovers.append(chunk[start:end])
    (yield ''.join(leftovers))
    leftovers = []
   else:
    (yield chunk[start:end])
   start = end
 if leftovers:
  (yield ''.join(leftovers))

def to_lines ( chunks ) : leftovers = [ ] for chunk in chunks : start = 0 while ( start < len ( chunk ) ) : end = ( chunk . find ( '\n' , start ) + 1 ) if ( end == 0 ) : leftovers . append ( chunk [ start : ] ) break if leftovers : leftovers . append ( chunk [ start : end ] ) ( yield '' . join ( leftovers ) ) leftovers = [ ] else : ( yield chunk [ start : end ] ) start = end if leftovers : ( yield '' . join ( leftovers ) )
take in data as a sequence of bytes .