def basename_from_filename(filename):
 mimetype = mimetypes.guess_type(filename)[0]
 if (mimetype is not None):
  mimetype = mimetype.lower()
  for (filetype, icon_name) in KNOWN_FILE_MIME_TYPES:
   if (filetype in mimetype):
    return icon_name
 extension = os.path.splitext(filename)[1]
 return KNOWN_FILE_EXTENSIONS.get(extension.lower(), u'file-text.svg')

def basename_from_filename ( filename ) : mimetype = mimetypes . guess_type ( filename ) [ 0 ] if ( mimetype is not None ) : mimetype = mimetype . lower ( ) for ( filetype , icon_name ) in KNOWN_FILE_MIME_TYPES : if ( filetype in mimetype ) : return icon_name extension = os . path . splitext ( filename ) [ 1 ] return KNOWN_FILE_EXTENSIONS . get ( extension . lower ( ) , u'file-text.svg' )
returns an icon name based on the filename .