Resolve settings dict from django settings module.
        Validate that all the required keys are present and also that none of
        the removed keys do.
        Result is cached.
184934
def _user_settings(self):
        
        user_settings = getattr(settings, self._name, {})
        if not user_settings and self._required:
            raise ImproperlyConfigured("Settings file is missing dict options with name {}".format(self._name))
        keys = frozenset(user_settings.keys())

        required = self._required - keys
        if required:
            raise ImproperlyConfigured("Following options for {} are missing from settings file: {}".format(self._name, ', '.join(sorted(required))))

        removed = keys & self._removed
        if removed:
            raise ImproperlyConfigured("Following options for {} have been removed: {}".format(self._name, ', '.join(sorted(removed))))

        return user_settings
663805
def _reset_django(settings):
    
    if settings._wrapped != empty:
        clear_url_caches()
        from django.apps import apps
        apps.clear_cache()
        settings._wrapped = empty
        clear_url_caches()
671815
def check_settings(self, settings):
        
        assert isinstance(settings, dict)

        errors = []
        if not isinstance(settings, dict) or len(settings) == 0:
            errors.append('invalid_syntax')
        else:
            if not self.__sp_validation_only:
                errors += self.check_idp_settings(settings)
            sp_errors = self.check_sp_settings(settings)
            errors += sp_errors

        return errors
200882
def configure_settings(settings, environment_settings=True):
    '''
    
    '''
    changes = 1
    iterations = 0

    while changes:
        changes = 0
        app_names = ['django_autoconfig'] + list(settings['INSTALLED_APPS'])
        if environment_settings:
            app_names.append('django_autoconfig.environment_settings')
        for app_name in app_names:
            import django_autoconfig.contrib
            if autoconfig_module_exists(app_name):
                module = importlib.import_module("%s.autoconfig" % (app_name,))
            elif app_name in django_autoconfig.contrib.CONTRIB_CONFIGS:
                module = django_autoconfig.contrib.CONTRIB_CONFIGS[app_name]
            else:
                continue
            changes += merge_dictionaries(
                settings,
                getattr(module, 'SETTINGS', {}),
                template_special_case=True,
            )
            changes += merge_dictionaries(
                settings,
                getattr(module, 'DEFAULT_SETTINGS', {}),
                only_defaults=True,
            )
            for relationship in getattr(module, 'RELATIONSHIPS', []):
                changes += relationship.apply_changes(settings)

        if iterations >= MAX_ITERATIONS:
            raise ImproperlyConfigured(
                'Autoconfiguration could not reach a consistent state'
            )
        iterations += 1
    LOGGER.debug("Autoconfiguration took %d iterations.", iterations)
334879
def remove_key(key: str, persists: bool = True):
    

    environ.configs.remove(key, include_persists=persists)
    environ.configs.save()

    environ.log(
        '[REMOVED]: "{}" from configuration settings'.format(key)
    )
276567
def get_django_settings(cls, name, default=None):
        # pylint: disable=access-member-before-definition
        
        if hasattr(cls, '__django_settings__'):
            return getattr(cls.__django_settings__, name, default)
        from django.conf import settings
        cls.__django_settings__ = settings
        return cls.get_django_settings(name)
950895
def clear(self, key=None):
        
        if not self.options.enabled:
            return CACHE_DISABLED
        logger.debug('clear(key={})'.format(repr(key)))
        if key is not None and key in self._dict.keys():
            del self._dict[key]
            logger.info('cache cleared for key: ' + repr(key))
        elif not key:
            for cached_key in [k for k in self._dict.keys()]:
                del self._dict[cached_key]
            logger.info('cache cleared for ALL keys')
        return True
774014
def _get_setting(self, setting_dotted_name, default=None):
        
        name_list = setting_dotted_name.split('.')
        setting_obj = getattr(django.conf.settings, name_list[0], default)
        # if len(name_list) == 1:
        #   return setting_obj

        return functools.reduce(
            lambda o, a: o.get(a, default), [setting_obj] + name_list[1:]
        )
1084800
def _validate_config(strict=False):
    """"""
    for index in settings.get_index_names():
        _validate_mapping(index, strict=strict)
        for model in settings.get_index_models(index):
            _validate_model(model)
    if settings.get_setting("update_strategy", "full") not in ["full", "partial"]:
        raise ImproperlyConfigured(
            "Invalid SEARCH_SETTINGS: 'update_strategy' value must be 'full' or 'partial'."
        )
938905
def _filter_settings(settings, prefix):
    
    ret = {}
    for skey in settings.keys():
        if skey.startswith(prefix):
            key = skey[len(prefix):]
            ret[key] = settings[skey]
    return ret
418803
def as_dict(config):
    
    settings = defaultdict(lambda: {})
    for section in config.sections():
        for key, val in config.items(section):
            settings[section][key] = val
    return settings
1163902
def from_dict(settings):
    

    assert isinstance(settings, dict), "`settings` must be of type dict"
    for key, value in settings.items():
        setattr(self, key, value)
547797
def remove_missing_keys(src_dict, target_dict):
    
    for key in list(target_dict.keys()):
        if key not in src_dict:
            target_dict.pop(key)
279719
def set(self, **kwargs):
        '''
        
        '''
        for lower_key, value in kwargs.items():
            if lower_key.lower() != lower_key:
                raise ValueError('Requires lowercase: %s' % lower_key)
            key = lower_key.upper()
            try:
                getattr(self, key)
            except (AttributeError, ConfigurationError):
                raise AttributeError('Cannot override %s' % key)
            self.overridden_settings[key] = value
49100
def get_dict(dictionary, *keys,**kwargs):
    

    if 'default' in kwargs:
        default = kwargs['default']
    else:
        default = None

    existing = dictionary
    for i in range(0, len(keys)):

        if keys[i] in existing:

            existing = existing[keys[i]]
        else:

            return default
    return existing
123361
def get_settings():
    '''
    
    '''
    settings = {}
    for config_file in config_files():
        config_contents = load_config(config_file)
        if config_contents is not None:
            settings = deep_merge(settings, config_contents)
    return settings
133936
def all_settings(self, uppercase_keys=False):
        """"""
        d = {}

        for k in self.all_keys(uppercase_keys):
            d[k] = self.get(k)

        return d