Exemple #1
0
    def _get(self, key_path, key_index=0, default=UndefinedKey):
        key_elt = key_path[key_index]
        elt = super(ConfigTree, self).get(key_elt, UndefinedKey)

        if elt is UndefinedKey:
            if default is UndefinedKey:
                raise ConfigMissingException(
                    u"No configuration setting found for key {key}".format(
                        key='.'.join(key_path[:key_index + 1])))
            else:
                return default

        if key_index == len(key_path) - 1:
            if isinstance(elt, NoneValue):
                return None
            else:
                return elt
        elif isinstance(elt, ConfigTree):
            return elt._get(key_path, key_index + 1, default)
        else:
            if default is UndefinedKey:
                raise ConfigWrongTypeException(
                    u"{key} has type {type} rather than dict".format(
                        key='.'.join(key_path[:key_index + 1]),
                        type=type(elt).__name__))
            else:
                return default
Exemple #2
0
    def _get(self, key_path, key_index=0):
        key_elt = key_path[key_index]
        elt = self._dictionary.get(key_elt)

        if elt is None:
            raise ConfigMissingException(
                "No configuration setting found for key {key}".format(
                    key='.'.join(key_path[:key_index + 1])))

        if key_index == len(key_path) - 1:
            return elt
        elif isinstance(elt, ConfigTree):
            return elt._get(key_path, key_index + 1)
        else:
            raise ConfigWrongTypeException(
                "{key} has type {type} rather than dict".format(
                    key='.'.join(key_path[:key_index + 1]),
                    type=type(elt).__name__))