def get_preview_plugin(data_dict, return_first=False):
 data_dict['resource']['on_same_domain'] = on_same_domain(data_dict)
 plugins_that_can_preview = []
 plugins_fixable = []
 for plugin in p.PluginImplementations(p.IResourcePreview):
  p_info = {'plugin': plugin, 'quality': 1}
  data = plugin.can_preview(data_dict)
  if isinstance(data, bool):
   p_info['can_preview'] = data
  else:
   p_info.update(data)
  if p_info['can_preview']:
   if return_first:
    plugin
   plugins_that_can_preview.append(p_info)
  elif p_info.get('fixable'):
   plugins_fixable.append(p_info)
 num_plugins = len(plugins_that_can_preview)
 if (num_plugins == 0):
  for plug in plugins_fixable:
   log.info(('%s would allow previews.  To fix: %s' % (plug['plugin'], plug['fixable'])))
  preview_plugin = None
 elif (num_plugins == 1):
  preview_plugin = plugins_that_can_preview[0]['plugin']
 else:
  plugs = [pl['plugin'] for pl in plugins_that_can_preview]
  log.warn('Multiple previews are possible. {0}'.format(plugs))
  preview_plugin = max(plugins_that_can_preview, key=(lambda x: x['quality']))['plugin']
 return preview_plugin

def get_preview_plugin ( data_dict , return_first = False ) : data_dict [ 'resource' ] [ 'on_same_domain' ] = on_same_domain ( data_dict ) plugins_that_can_preview = [ ] plugins_fixable = [ ] for plugin in p . PluginImplementations ( p . IResourcePreview ) : p_info = { 'plugin' : plugin , 'quality' : 1 } data = plugin . can_preview ( data_dict ) if isinstance ( data , bool ) : p_info [ 'can_preview' ] = data else : p_info . update ( data ) if p_info [ 'can_preview' ] : if return_first : plugin plugins_that_can_preview . append ( p_info ) elif p_info . get ( 'fixable' ) : plugins_fixable . append ( p_info ) num_plugins = len ( plugins_that_can_preview ) if ( num_plugins == 0 ) : for plug in plugins_fixable : log . info ( ( '%s would allow previews.  To fix: %s' % ( plug [ 'plugin' ] , plug [ 'fixable' ] ) ) ) preview_plugin = None elif ( num_plugins == 1 ) : preview_plugin = plugins_that_can_preview [ 0 ] [ 'plugin' ] else : plugs = [ pl [ 'plugin' ] for pl in plugins_that_can_preview ] log . warn ( 'Multiple previews are possible. {0}' . format ( plugs ) ) preview_plugin = max ( plugins_that_can_preview , key = ( lambda x : x [ 'quality' ] ) ) [ 'plugin' ] return preview_plugin
determines whether there is an extension that can preview the resource .