def load(self, base_settings):
        """Merge local settings from file with ``base_settings``.

        Returns a new settings dict containing the base settings and the
        loaded settings. Includes:

            - base settings
            - settings from extended file(s), if any
            - settings from file

        """
        is_valid_key = lambda k: k.isupper() and not k.startswith('_')

        # Base settings, including `LocalSetting`s, loaded from the
        # Django settings module.
        valid_keys = (k for k in base_settings if is_valid_key(k))
        base_settings = DottedAccessDict((k, base_settings[k]) for k in valid_keys)

        # Settings read from the settings file; values are unprocessed.
        settings_from_file = self.strategy.read_file(self.file_name, self.section)
        settings_from_file.pop('extends', None)

        # The fully resolved settings.
        settings = Settings(base_settings)

        settings_names = []
        settings_not_decoded = set()

        for name, value in settings_from_file.items():
            for prefix in ('PREPEND.', 'APPEND.', 'SWAP.'):
                if name.startswith(prefix):
                    name = name[len(prefix):]
                    name = '{prefix}({name})'.format(**locals())
                    break

            settings_names.append(name)

            # Attempt to decode raw values. Errors in decoding at this
            # stage are ignored.
            try:
                value = self.strategy.decode_value(value)
            except ValueError:
                settings_not_decoded.add(name)

            settings.set_dotted(name, value)

            # See if this setting corresponds to a `LocalSetting`. If
            # so, note that the `LocalSetting` has a value by putting it
            # in the registry. This also makes it easy to retrieve the
            # `LocalSetting` later so its value can be set.
            current_value = base_settings.get_dotted(name, None)
            if isinstance(current_value, LocalSetting):
                self.registry[current_value] = name

        # Interpolate values of settings read from file. When a setting
        # that couldn't be decoded previously is encountered, its post-
        # interpolation value will be decoded.
        for name in settings_names:
            value = settings.get_dotted(name)
            value, _ = self._interpolate_values(value, settings)
            if name in settings_not_decoded:
                value = self.strategy.decode_value(value)
            settings.set_dotted(name, value)

        # Interpolate base settings.
        self._interpolate_values(settings, settings)

        self._interpolate_keys(settings, settings)

        self._prepend_extras(settings, settings.pop('PREPEND', None))
        self._append_extras(settings, settings.pop('APPEND', None))
        self._swap_list_items(settings, settings.pop('SWAP', None))
        self._import_from_string(settings, settings.pop('IMPORT_FROM_STRING', None))

        for local_setting, name in self.registry.items():
            local_setting.value = settings.get_dotted(name)

        return settings
def load ( self , base_settings ) : is_valid_key = lambda k : k . isupper ( ) and not k . startswith ( '_' ) valid_keys = ( k for k in base_settings if is_valid_key ( k ) ) base_settings = DottedAccessDict ( ( k , base_settings [ k ] ) for k in valid_keys ) settings_from_file = self . strategy . read_file ( self . file_name , self . section ) settings_from_file . pop ( 'extends' , None ) settings = Settings ( base_settings ) settings_names = [ ] settings_not_decoded = set ( ) for name , value in settings_from_file . items ( ) : for prefix in ( 'PREPEND.' , 'APPEND.' , 'SWAP.' ) : if name . startswith ( prefix ) : name = name [ len ( prefix ) : ] name = '{prefix}({name})' . format ( ** locals ( ) ) break settings_names . append ( name ) try : value = self . strategy . decode_value ( value ) except ValueError : settings_not_decoded . add ( name ) settings . set_dotted ( name , value ) current_value = base_settings . get_dotted ( name , None ) if isinstance ( current_value , LocalSetting ) : self . registry [ current_value ] = name for name in settings_names : value = settings . get_dotted ( name ) value , _ = self . _interpolate_values ( value , settings ) if name in settings_not_decoded : value = self . strategy . decode_value ( value ) settings . set_dotted ( name , value ) self . _interpolate_values ( settings , settings ) self . _interpolate_keys ( settings , settings ) self . _prepend_extras ( settings , settings . pop ( 'PREPEND' , None ) ) self . _append_extras ( settings , settings . pop ( 'APPEND' , None ) ) self . _swap_list_items ( settings , settings . pop ( 'SWAP' , None ) ) self . _import_from_string ( settings , settings . pop ( 'IMPORT_FROM_STRING' , None ) ) for local_setting , name in self . registry . items ( ) : local_setting . value = settings . get_dotted ( name ) return settings
Merge local settings from file with ``base_settings``.

        Returns a new settings dict containing the base settings and the
        loaded settings. Includes:

            - base settings
            - settings from extended file(s), if any
            - settings from file