def generate_source_image(source_file, processor_options, generators=None, fail_silently=True):
 processor_options = ThumbnailOptions(processor_options)
 was_closed = getattr(source_file, 'closed', False)
 if (generators is None):
  generators = [utils.dynamic_import(name) for name in settings.THUMBNAIL_SOURCE_GENERATORS]
 exceptions = []
 try:
  for generator in generators:
   source = source_file
   try:
    source.open()
   except Exception:
    try:
     source.seek(0)
    except Exception:
     source = None
   try:
    image = generator(source, **processor_options)
   except Exception as e:
    if (not fail_silently):
     if (len(generators) == 1):
      raise
     exceptions.append(e)
    image = None
   if image:
    return image
 finally:
  if was_closed:
   try:
    source_file.close()
   except Exception:
    pass
 if (exceptions and (not fail_silently)):
  raise NoSourceGenerator(*exceptions)

def generate_source_image ( source_file , processor_options , generators = None , fail_silently = True ) : processor_options = ThumbnailOptions ( processor_options ) was_closed = getattr ( source_file , 'closed' , False ) if ( generators is None ) : generators = [ utils . dynamic_import ( name ) for name in settings . THUMBNAIL_SOURCE_GENERATORS ] exceptions = [ ] try : for generator in generators : source = source_file try : source . open ( ) except Exception : try : source . seek ( 0 ) except Exception : source = None try : image = generator ( source , ** processor_options ) except Exception as e : if ( not fail_silently ) : if ( len ( generators ) == 1 ) : raise exceptions . append ( e ) image = None if image : return image finally : if was_closed : try : source_file . close ( ) except Exception : pass if ( exceptions and ( not fail_silently ) ) : raise NoSourceGenerator ( * exceptions )
processes a source file through a series of source generators .