def filter_whitespace(mode, text):
 if (mode == 'all'):
  return text
 elif (mode == 'single'):
  text = re.sub('([\\t ]+)', ' ', text)
  text = re.sub('(\\s*\\n\\s*)', '\n', text)
  return text
 elif (mode == 'oneline'):
  return re.sub('(\\s+)', ' ', text)
 else:
  raise Exception(('invalid whitespace mode %s' % mode))

def filter_whitespace ( mode , text ) : if ( mode == 'all' ) : return text elif ( mode == 'single' ) : text = re . sub ( '([\\t ]+)' , ' ' , text ) text = re . sub ( '(\\s*\\n\\s*)' , '\n' , text ) return text elif ( mode == 'oneline' ) : return re . sub ( '(\\s+)' , ' ' , text ) else : raise Exception ( ( 'invalid whitespace mode %s' % mode ) )
transform whitespace in text according to mode .