(self, config_dict)
Read data from the default dictionary.
Read data from the default dictionary.
Read data from the default dictionary .
def _load_from_dict(self, config_dict):
        """Read data from the default dictionary."""
        for heading, var_data in iteritems(config_dict):
            self._data[heading] = {}
            self._backup[heading] = {}
            
            for var, info in iteritems(var_data):
                if isinstance(info, (str, int, float, bool)):
                    info = _process_input(info, self._default_settings)
                elif not isinstance(info, dict):
                    continue
                else:
                    info = dict(info)
                
                #Fill from default settings
                if self._default_settings is not None:
                    for option_name, option_value in iteritems(self._default_settings):
                        if option_name not in info:
                            info[option_name] = option_value
                
                #Convert to dict if not already one
                if not isinstance(info, dict):
                    info = {'value': info}

                #Fill in type or value if not set
                if 'type' not in info:
                    try:
                        info['type'] = type(info['value'])
                    except KeyError:
                        #If this exception is being raised, then there is an empty value
                        #As there is no type, we don't know what the default value should be
                        #Option 1: Set a type or value in the base dictionary
                        #Option 2: Set default_settings to apply to all values in __init__
                        raise ValueError('{}.{} has no value and is an unknown type'.format(heading, var))
                elif 'value' not in info:
                    info['value'] = self._DEFAULT_VALUES[info['type']]
                info['default'] = info['value']

                #Convert all keys to strings so it's consistent when reading files
                if not isinstance(var, str):
                    var = str(var)

                self._data[heading][var] = info
                self._backup[heading][var] = info['value']
def _load_from_dict ( self , config_dict ) : for heading , var_data in iteritems ( config_dict ) : self . _data [ heading ] = { } self . _backup [ heading ] = { } for var , info in iteritems ( var_data ) : if isinstance ( info , ( str , int , float , bool ) ) : info = _process_input ( info , self . _default_settings ) elif not isinstance ( info , dict ) : continue else : info = dict ( info ) #Fill from default settings if self . _default_settings is not None : for option_name , option_value in iteritems ( self . _default_settings ) : if option_name not in info : info [ option_name ] = option_value #Convert to dict if not already one if not isinstance ( info , dict ) : info = { 'value' : info } #Fill in type or value if not set if 'type' not in info : try : info [ 'type' ] = type ( info [ 'value' ] ) except KeyError : #If this exception is being raised, then there is an empty value #As there is no type, we don't know what the default value should be #Option 1: Set a type or value in the base dictionary #Option 2: Set default_settings to apply to all values in __init__ raise ValueError ( '{}.{} has no value and is an unknown type' . format ( heading , var ) ) elif 'value' not in info : info [ 'value' ] = self . _DEFAULT_VALUES [ info [ 'type' ] ] info [ 'default' ] = info [ 'value' ] #Convert all keys to strings so it's consistent when reading files if not isinstance ( var , str ) : var = str ( var ) self . _data [ heading ] [ var ] = info self . _backup [ heading ] [ var ] = info [ 'value' ]