def split_lines(tokenlist):
 line = []
 for item in tokenlist:
  if (len(item) == 2):
   (token, string) = item
   parts = string.split(u'\n')
   for part in parts[:(-1)]:
    if part:
     line.append((token, part))
    (yield line)
    line = []
   line.append((token, parts[(-1)]))
  else:
   (token, string, mouse_handler) = item
   parts = string.split(u'\n')
   for part in parts[:(-1)]:
    if part:
     line.append((token, part, mouse_handler))
    (yield line)
    line = []
   line.append((token, parts[(-1)], mouse_handler))
 (yield line)

def split_lines ( tokenlist ) : line = [ ] for item in tokenlist : if ( len ( item ) == 2 ) : ( token , string ) = item parts = string . split ( u'\n' ) for part in parts [ : ( - 1 ) ] : if part : line . append ( ( token , part ) ) ( yield line ) line = [ ] line . append ( ( token , parts [ ( - 1 ) ] ) ) else : ( token , string , mouse_handler ) = item parts = string . split ( u'\n' ) for part in parts [ : ( - 1 ) ] : if part : line . append ( ( token , part , mouse_handler ) ) ( yield line ) line = [ ] line . append ( ( token , parts [ ( - 1 ) ] , mouse_handler ) ) ( yield line )
take a single list of tuples and yield one such list for each line .