def onlyAlphaNum(dirty, repl=' ', whitelist=''):
  '''Filter/replace non-alphanumeric characters.
  
  Args:
    dirty: A string to filter
    repl: Character used to replace non-alphanumeric characters.  Set to empty
      string to remove instead of replace.
    whitelist: Do not remove or replace characters in this string.
  
  Returns:
    A filtered string.
  '''
  keepers = '%s%s%s'%(string.ascii_letters, string.digits, whitelist)
  replace_chars = string.maketrans(keepers, '\x00'*len(keepers))
  if repl != '':
    replace_chars = string.maketrans(replace_chars, repl*256)
    return dirty.encode('ascii','ignore').translate(replace_chars)
  else:
    return dirty.encode('ascii','ignore').translate(None, replace_chars)
dataset/ETHPy150Open DeanCutlet/filestack/util.py/onlyAlphaNum/original