def secure_filename(filename):
 if isinstance(filename, unicode):
  from unicodedata import normalize
  filename = normalize('NFKD', filename).encode('ascii', 'ignore')
 for sep in (os.path.sep, os.path.altsep):
  if sep:
   filename = filename.replace(sep, ' ')
 filename = str(_filename_ascii_strip_re.sub('', '_'.join(filename.split()))).strip('._')
 if ((os.name == 'nt') and filename and (filename.split('.')[0].upper() in _windows_device_files)):
  filename = ('_' + filename)
 return filename

def secure_filename ( filename ) : if isinstance ( filename , unicode ) : from unicodedata import normalize filename = normalize ( 'NFKD' , filename ) . encode ( 'ascii' , 'ignore' ) for sep in ( os . path . sep , os . path . altsep ) : if sep : filename = filename . replace ( sep , ' ' ) filename = str ( _filename_ascii_strip_re . sub ( '' , '_' . join ( filename . split ( ) ) ) ) . strip ( '._' ) if ( ( os . name == 'nt' ) and filename and ( filename . split ( '.' ) [ 0 ] . upper ( ) in _windows_device_files ) ) : filename = ( '_' + filename ) return filename
pass it a filename and it will return a secure version of it .