<s> import six <EOL> from importlib import import_module <EOL> import default_settings <EOL> class BaseSettings ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , module = None , attributes = None ) : <EOL> """<STR_LIT>""" <EOL> self . attributes = { } <EOL> if module : <EOL> self . add_module ( module ) <EOL> if attributes : <EOL> self . set_from_dict ( attributes ) <EOL> @ classmethod <EOL> def from_params ( cls , ** kwargs ) : <EOL> return cls ( attributes = kwargs ) <EOL> @ classmethod <EOL> def object_from ( cls , settings ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( settings , BaseSettings ) : <EOL> return settings <EOL> else : <EOL> return cls ( settings ) <EOL> def __getattr__ ( self , name ) : <EOL> val = self . get ( name ) <EOL> if val is not None : <EOL> return val <EOL> else : <EOL> return self . __dict__ [ name ] <EOL> def __setattr__ ( self , name , value ) : <EOL> if name . isupper ( ) : <EOL> self . attributes [ name ] = value <EOL> else : <EOL> self . __dict__ [ name ] = value <EOL> def add_module ( self , module ) : <EOL> if isinstance ( module , six . string_types ) : <EOL> module = import_module ( module ) <EOL> for key in dir ( module ) : <EOL> if key . isupper ( ) : <EOL> self . set ( key , getattr ( module , key ) ) <EOL> def get ( self , key , default_value = None ) : <EOL> if not key . isupper ( ) : <EOL> return None <EOL> return self . attributes . get ( key , default_value ) <EOL> def set ( self , key , value ) : <EOL> if key . isupper ( ) : <EOL> self . attributes [ key ] = value <EOL> def set_from_dict ( self , attributes ) : <EOL> for name , value in attributes . items ( ) : <EOL> self . set ( name , value ) <EOL> class DefaultSettings ( BaseSettings ) : <EOL> def __init__ ( self ) : <EOL> super ( DefaultSettings , self ) . __init__ ( default_settings ) <EOL> class Settings ( BaseSettings ) : <EOL> def __init__ ( self , module = None , attributes = None ) : <EOL> super ( Settings , self ) . __init__ ( default_settings , attributes ) <EOL> if module : <EOL> self . add_module ( module ) </s>
