def _split_multiline_prompt(get_prompt_tokens):
 def has_before_tokens(cli):
  for (token, char) in get_prompt_tokens(cli):
   if (u'\n' in char):
    return True
  return False
 def before(cli):
  result = []
  found_nl = False
  for (token, char) in reversed(explode_tokens(get_prompt_tokens(cli))):
   if found_nl:
    result.insert(0, (token, char))
   elif (char == u'\n'):
    found_nl = True
  return result
 def first_input_line(cli):
  result = []
  for (token, char) in reversed(explode_tokens(get_prompt_tokens(cli))):
   if (char == u'\n'):
    break
   else:
    result.insert(0, (token, char))
  return result
 return (has_before_tokens, before, first_input_line)

def _split_multiline_prompt ( get_prompt_tokens ) : def has_before_tokens ( cli ) : for ( token , char ) in get_prompt_tokens ( cli ) : if ( u'\n' in char ) : return True return False def before ( cli ) : result = [ ] found_nl = False for ( token , char ) in reversed ( explode_tokens ( get_prompt_tokens ( cli ) ) ) : if found_nl : result . insert ( 0 , ( token , char ) ) elif ( char == u'\n' ) : found_nl = True return result def first_input_line ( cli ) : result = [ ] for ( token , char ) in reversed ( explode_tokens ( get_prompt_tokens ( cli ) ) ) : if ( char == u'\n' ) : break else : result . insert ( 0 , ( token , char ) ) return result return ( has_before_tokens , before , first_input_line )
take a get_prompt_tokens function and return three new functions instead .