<s> import sys <EOL> from . _compat import string_types , PY2 <EOL> def import_string ( import_name , silent = False ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( import_name , string_types ) <EOL> import_name = str ( import_name ) <EOL> try : <EOL> if '<STR_LIT::>' in import_name : <EOL> module , obj = import_name . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> elif '<STR_LIT:.>' in import_name : <EOL> module , obj = import_name . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> else : <EOL> return __import__ ( import_name ) <EOL> if PY2 and isinstance ( obj , unicode ) : <EOL> obj = obj . encode ( '<STR_LIT:utf-8>' ) <EOL> try : <EOL> return getattr ( __import__ ( module , None , None , [ obj ] ) , obj ) <EOL> except ( ImportError , AttributeError ) : <EOL> modname = module + '<STR_LIT:.>' + obj <EOL> __import__ ( modname ) <EOL> return sys . modules [ modname ] <EOL> except ImportError as e : <EOL> if not silent : <EOL> raise <EOL> class ConfigAttribute ( object ) : <EOL> def __init__ ( self , name , converter = None ) : <EOL> self . name = name <EOL> self . converter = converter <EOL> def __get__ ( self , instance , owner ) : <EOL> if instance is None : <EOL> return self <EOL> rv = instance . config [ self . name ] <EOL> if self . converter is not None : <EOL> return self . converter ( rv ) <EOL> return rv <EOL> def __set__ ( self , instance , value ) : <EOL> instance . config [ self . name ] = value </s>
