<s> from thumbor . utils import logger <EOL> from functools import reduce <EOL> def import_class ( name , get_module = False ) : <EOL> module_name = get_module and name or '<STR_LIT:.>' . join ( name . split ( '<STR_LIT:.>' ) [ : - <NUM_LIT:1> ] ) <EOL> klass = name . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> module = get_module and __import__ ( name ) or __import__ ( module_name ) <EOL> if '<STR_LIT:.>' in module_name : <EOL> module = reduce ( getattr , module_name . split ( '<STR_LIT:.>' ) [ <NUM_LIT:1> : ] , module ) <EOL> return get_module and module or getattr ( module , klass ) <EOL> class Importer : <EOL> def __init__ ( self , config ) : <EOL> self . config = config <EOL> self . engine = None <EOL> self . gif_engine = None <EOL> self . loader = None <EOL> self . url_signer = None <EOL> self . upload_photo_storage = None <EOL> self . storage = None <EOL> self . metrics = None <EOL> self . result_storage = None <EOL> self . detectors = [ ] <EOL> self . filters = [ ] <EOL> self . optimizers = [ ] <EOL> self . error_handler_class = None <EOL> def import_class ( self , name , get_module = False ) : <EOL> return import_class ( name , get_module ) <EOL> def import_modules ( self ) : <EOL> self . config . validates_presence_of ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> ) <EOL> self . import_item ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . import_item ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . import_item ( '<STR_LIT>' ) <EOL> self . import_item ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . import_item ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . import_item ( '<STR_LIT>' , '<STR_LIT>' , is_multiple = True ) <EOL> self . import_item ( '<STR_LIT>' , '<STR_LIT>' , is_multiple = True , ignore_errors = True ) <EOL> self . import_item ( '<STR_LIT>' , '<STR_LIT>' , is_multiple = True ) <EOL> self . import_item ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if self . config . RESULT_STORAGE : <EOL> self . import_item ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if self . config . UPLOAD_PHOTO_STORAGE : <EOL> self . import_item ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if self . config . USE_CUSTOM_ERROR_HANDLING : <EOL> self . import_item ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . error_handler_class = self . error_handler_module <EOL> def import_item ( self , config_key = None , class_name = None , is_multiple = False , item_value = None , ignore_errors = False ) : <EOL> if item_value is None : <EOL> conf_value = getattr ( self . config , config_key ) <EOL> else : <EOL> conf_value = item_value <EOL> if is_multiple : <EOL> modules = [ ] <EOL> if conf_value : <EOL> for module_name in conf_value : <EOL> try : <EOL> if class_name is not None : <EOL> module = self . import_class ( '<STR_LIT>' % ( module_name , class_name ) ) <EOL> else : <EOL> module = self . import_class ( module_name , get_module = True ) <EOL> modules . append ( module ) <EOL> except ImportError : <EOL> if ignore_errors : <EOL> logger . warn ( '<STR_LIT>' % module_name ) <EOL> else : <EOL> raise <EOL> setattr ( self , config_key . lower ( ) , tuple ( modules ) ) <EOL> else : <EOL> if class_name is not None : <EOL> module = self . import_class ( '<STR_LIT>' % ( conf_value , class_name ) ) <EOL> else : <EOL> module = self . import_class ( conf_value , get_module = True ) <EOL> setattr ( self , config_key . lower ( ) , module ) </s>
