def sanitize_text(text, valid_characters=valid_chars, character_map=mapped_chars, invalid_character='X'):
 if isinstance(text, list):
  return [sanitize_text(x, valid_characters=valid_characters, character_map=character_map, invalid_character=invalid_character) for x in text]
 if (not isinstance(text, string_types)):
  text = smart_str(text)
 return _sanitize_text_helper(text, valid_characters=valid_characters, character_map=character_map)

def sanitize_text ( text , valid_characters = valid_chars , character_map = mapped_chars , invalid_character = 'X' ) : if isinstance ( text , list ) : return [ sanitize_text ( x , valid_characters = valid_characters , character_map = character_map , invalid_character = invalid_character ) for x in text ] if ( not isinstance ( text , string_types ) ) : text = smart_str ( text ) return _sanitize_text_helper ( text , valid_characters = valid_characters , character_map = character_map )
restricts the characters that are allowed in text; accepts both strings and lists of strings; non-string entities will be cast to strings .