def munge_filename(filename):
 if (not isinstance(filename, unicode)):
  filename = decode_path(filename)
 filename = os.path.split(filename)[1]
 filename = filename.lower().strip()
 filename = substitute_ascii_equivalents(filename)
 filename = re.sub(u'[^a-zA-Z0-9_. -]', '', filename).replace(u' ', u'-')
 filename = re.sub(u'-+', u'-', filename)
 (name, ext) = os.path.splitext(filename)
 ext = ext[:MAX_FILENAME_EXTENSION_LENGTH]
 ext_len = len(ext)
 name = _munge_to_length(name, max(1, (MIN_FILENAME_TOTAL_LENGTH - ext_len)), (MAX_FILENAME_TOTAL_LENGTH - ext_len))
 filename = (name + ext)
 return filename

def munge_filename ( filename ) : if ( not isinstance ( filename , unicode ) ) : filename = decode_path ( filename ) filename = os . path . split ( filename ) [ 1 ] filename = filename . lower ( ) . strip ( ) filename = substitute_ascii_equivalents ( filename ) filename = re . sub ( u'[^a-zA-Z0-9_. -]' , '' , filename ) . replace ( u' ' , u'-' ) filename = re . sub ( u'-+' , u'-' , filename ) ( name , ext ) = os . path . splitext ( filename ) ext = ext [ : MAX_FILENAME_EXTENSION_LENGTH ] ext_len = len ( ext ) name = _munge_to_length ( name , max ( 1 , ( MIN_FILENAME_TOTAL_LENGTH - ext_len ) ) , ( MAX_FILENAME_TOTAL_LENGTH - ext_len ) ) filename = ( name + ext ) return filename
tidies a filename keeps the filename extension .