def sanitize_file_name_unicode(name, substitute='_'):
 if isbytestring(name):
  return sanitize_file_name(name, substitute=substitute, as_unicode=True)
 chars = [(substitute if (c in _filename_sanitize_unicode) else c) for c in name]
 one = u''.join(chars)
 one = re.sub('\\s', ' ', one).strip()
 (bname, ext) = os.path.splitext(one)
 one = re.sub('^\\.+$', '_', bname)
 one = one.replace('..', substitute)
 one += ext
 if (one and (one[(-1)] in ('.', ' '))):
  one = (one[:(-1)] + '_')
 if one.startswith('.'):
  one = ('_' + one[1:])
 return one

def sanitize_file_name_unicode ( name , substitute = '_' ) : if isbytestring ( name ) : return sanitize_file_name ( name , substitute = substitute , as_unicode = True ) chars = [ ( substitute if ( c in _filename_sanitize_unicode ) else c ) for c in name ] one = u'' . join ( chars ) one = re . sub ( '\\s' , ' ' , one ) . strip ( ) ( bname , ext ) = os . path . splitext ( one ) one = re . sub ( '^\\.+$' , '_' , bname ) one = one . replace ( '..' , substitute ) one += ext if ( one and ( one [ ( - 1 ) ] in ( '.' , ' ' ) ) ) : one = ( one [ : ( - 1 ) ] + '_' ) if one . startswith ( '.' ) : one = ( '_' + one [ 1 : ] ) return one
sanitize the filename name .