#NEWLINE# def import_from_string( val , setting_name ) : #NEWLINE# #INDENT# '\n    Attempt to import a class from a string representation.\n    ' #NEWLINE# try : #NEWLINE# #INDENT# parts = val . split ( '.' ) #NEWLINE# ( module_path , class_name ) = ( '.' . join ( parts [ : ( - 1 ) ] ) , parts [ ( - 1 ) ] ) #NEWLINE# module = importlib . import_module ( module_path ) #NEWLINE# return getattr ( module , class_name ) #NEWLINE# #UNINDENT# except ( ImportError , AttributeError ) as e : #NEWLINE# #INDENT# msg = ( "Could not import '%s' for API setting '%s'. %s: %s." % ( val , setting_name , e . __class__ . __name__ , e ) ) #NEWLINE# raise ImportError ( msg )