当前位置: 首页>>代码示例>>Python>>正文


Python ConfigTree.get方法代码示例

本文整理汇总了Python中pyhocon.config_tree.ConfigTree.get方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigTree.get方法的具体用法?Python ConfigTree.get怎么用?Python ConfigTree.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyhocon.config_tree.ConfigTree的用法示例。


在下文中一共展示了ConfigTree.get方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_config_list

# 需要导入模块: from pyhocon.config_tree import ConfigTree [as 别名]
# 或者: from pyhocon.config_tree.ConfigTree import get [as 别名]
    def test_config_list(self):
        config_tree = ConfigTree()

        config_tree.put("a.b.c", [4, 5])
        assert config_tree.get("a.b.c") == [4, 5]

        config_tree.put("a.b.c", [6, 7])
        assert config_tree.get("a.b.c") == [6, 7]

        config_tree.put("a.b.c", [8, 9], True)
        assert config_tree.get("a.b.c") == [6, 7, 8, 9]
开发者ID:ryban,项目名称:pyhocon,代码行数:13,代码来源:test_config_tree.py

示例2: test_plain_ordered_dict

# 需要导入模块: from pyhocon.config_tree import ConfigTree [as 别名]
# 或者: from pyhocon.config_tree.ConfigTree import get [as 别名]
 def test_plain_ordered_dict(self):
     config_tree = ConfigTree()
     config_tree.put('"a.b"', 5)
     config_tree.put('a."b.c"', [ConfigTree(), 2])
     config_tree.get('a."b.c"')[0].put('"c.d"', 1)
     d = OrderedDict()
     d['a.b'] = 5
     d['a'] = OrderedDict()
     d['a']['b.c'] = [OrderedDict(), 2]
     d['a']['b.c'][0]['c.d'] = 1
     assert config_tree.as_plain_ordered_dict() == d
开发者ID:ryban,项目名称:pyhocon,代码行数:13,代码来源:test_config_tree.py

示例3: test_getters

# 需要导入模块: from pyhocon.config_tree import ConfigTree [as 别名]
# 或者: from pyhocon.config_tree.ConfigTree import get [as 别名]
    def test_getters(self):
        config_tree = ConfigTree()
        config_tree.put("int", 5)
        assert config_tree["int"] == 5
        assert config_tree.get("int") == 5
        assert config_tree.get_int("int") == 5

        config_tree.put("float", 4.5)
        assert config_tree["float"] == 4.5
        assert config_tree.get("float") == 4.5
        assert config_tree.get_float("float") == 4.5

        config_tree.put("string", "string")
        assert config_tree["string"] == "string"
        assert config_tree.get("string") == "string"
        assert config_tree.get_string("string") == "string"

        config_tree.put("list", [1, 2, 3])
        assert config_tree["list"] == [1, 2, 3]
        assert config_tree.get("list") == [1, 2, 3]
        assert config_tree.get_list("list") == [1, 2, 3]

        config_tree.put("bool", True)
        assert config_tree["bool"] is True
        assert config_tree.get("bool") is True
        assert config_tree.get_bool("bool") is True

        config_tree.put("config", {'a': 5})
        assert config_tree["config"] == {'a': 5}
        assert config_tree.get("config") == {'a': 5}
        assert config_tree.get_config("config") == {'a': 5}
开发者ID:ryban,项目名称:pyhocon,代码行数:33,代码来源:test_config_tree.py

示例4: postParse

# 需要导入模块: from pyhocon.config_tree import ConfigTree [as 别名]
# 或者: from pyhocon.config_tree.ConfigTree import get [as 别名]
    def postParse(self, instring, loc, token_list):
        """Create ConfigTree from tokens

        :param instring:
        :param loc:
        :param token_list:
        :return:
        """
        config_tree = ConfigTree(root=self.root)
        for element in token_list:
            expanded_tokens = element.tokens if isinstance(element, ConfigInclude) else [element]

            for tokens in expanded_tokens:
                # key, value1 (optional), ...
                key = tokens[0].strip()
                operator = '='
                if len(tokens) == 3 and tokens[1].strip() in [':', '=', '+=']:
                    operator = tokens[1].strip()
                    values = tokens[2:]
                elif len(tokens) == 2:
                    values = tokens[1:]
                else:
                    raise ParseSyntaxException("Unknown tokens {tokens} received".format(tokens=tokens))
                # empty string
                if len(values) == 0:
                    config_tree.put(key, '')
                else:
                    value = values[0]
                    if isinstance(value, list) and operator == "+=":
                        value = ConfigValues([ConfigSubstitution(key, True, '', False, loc), value], False, loc)
                        config_tree.put(key, value, False)
                    elif isinstance(value, unicode) and operator == "+=":
                        value = ConfigValues([ConfigSubstitution(key, True, '', True, loc), ' ' + value], True, loc)
                        config_tree.put(key, value, False)
                    elif isinstance(value, list):
                        config_tree.put(key, value, False)
                    else:
                        existing_value = config_tree.get(key, None)
                        if isinstance(value, ConfigTree) and not isinstance(existing_value, list):
                            # Only Tree has to be merged with tree
                            config_tree.put(key, value, True)
                        elif isinstance(value, ConfigValues):
                            conf_value = value
                            value.parent = config_tree
                            value.key = key
                            if isinstance(existing_value, list) or isinstance(existing_value, ConfigTree):
                                config_tree.put(key, conf_value, True)
                            else:
                                config_tree.put(key, conf_value, False)
                        else:
                            config_tree.put(key, value, False)
        return config_tree
开发者ID:chimpler,项目名称:pyhocon,代码行数:54,代码来源:config_parser.py

示例5: test_config_tree_quoted_string

# 需要导入模块: from pyhocon.config_tree import ConfigTree [as 别名]
# 或者: from pyhocon.config_tree.ConfigTree import get [as 别名]
    def test_config_tree_quoted_string(self):
        config_tree = ConfigTree()
        config_tree.put("a.b.c", "value")
        assert config_tree.get("a.b.c") == "value"

        with pytest.raises(ConfigMissingException):
            assert config_tree.get("a.b.d")

        with pytest.raises(ConfigMissingException):
            config_tree.get("a.d.e")

        with pytest.raises(ConfigWrongTypeException):
            config_tree.get("a.b.c.e")
开发者ID:txominpelu,项目名称:pyhocon,代码行数:15,代码来源:test_config_tree.py

示例6: postParse

# 需要导入模块: from pyhocon.config_tree import ConfigTree [as 别名]
# 或者: from pyhocon.config_tree.ConfigTree import get [as 别名]
    def postParse(self, instring, loc, token_list):
        """Create ConfigTree from tokens

        :param instring:
        :param loc:
        :param token_list:
        :return:
        """
        config_tree = ConfigTree()
        for element in token_list:
            expanded_tokens = element.tokens if isinstance(element, ConfigInclude) else [element]

            for tokens in expanded_tokens:
                # key, value1 (optional), ...
                key = tokens[0].strip()
                values = tokens[1:]

                # empty string
                if len(values) == 0:
                    config_tree.put(key, '')
                else:
                    value = values[0]
                    if isinstance(value, list):
                        config_tree.put(key, value, False)
                    else:
                        if isinstance(value, ConfigTree):
                            config_tree.put(key, value, True)
                        elif isinstance(value, ConfigValues):
                            conf_value = value
                            value.parent = config_tree
                            value.key = key
                            existing_value = config_tree.get(key, None)
                            if isinstance(existing_value, list) or isinstance(existing_value, ConfigTree):
                                config_tree.put(key, conf_value, True)
                            else:
                                config_tree.put(key, conf_value, False)
                        else:
                            conf_value = value
                            config_tree.put(key, conf_value, False)
        return config_tree
开发者ID:gilles-duboscq,项目名称:pyhocon,代码行数:42,代码来源:config_parser.py

示例7: test_config_tree_number

# 需要导入模块: from pyhocon.config_tree import ConfigTree [as 别名]
# 或者: from pyhocon.config_tree.ConfigTree import get [as 别名]
 def test_config_tree_number(self):
     config_tree = ConfigTree()
     config_tree.put("a.b.c", 5)
     assert config_tree.get("a.b.c") == 5
开发者ID:txominpelu,项目名称:pyhocon,代码行数:6,代码来源:test_config_tree.py

示例8: test_getters_with_default

# 需要导入模块: from pyhocon.config_tree import ConfigTree [as 别名]
# 或者: from pyhocon.config_tree.ConfigTree import get [as 别名]
    def test_getters_with_default(self):
        config_tree = ConfigTree()
        config_tree.put("int", 5)
        assert config_tree.get("int-new", 1) == 1
        assert config_tree.get_int("int", 1) == 5
        assert config_tree.get_int("int-new", 1) == 1
        assert config_tree.get_int("int-new.test", 1) == 1

        config_tree.put("float", 4.5)
        assert config_tree.get("float", 1.0) == 4.5
        assert config_tree.get("float-new", 1.0) == 1.0
        assert config_tree.get_float("float", 1.0) == 4.5
        assert config_tree.get_float("float-new", 1.0) == 1.0
        assert config_tree.get_float("float-new.test", 1.0) == 1.0

        config_tree.put("string", "string")
        assert config_tree.get("string", "default") == "string"
        assert config_tree.get("string-new", "default") == "default"
        assert config_tree.get_string("string", "default") == "string"
        assert config_tree.get_string("string-new", "default") == "default"
        assert config_tree.get_string("string-new.test", "default") == "default"

        config_tree.put("list", [1, 2, 3])
        assert config_tree.get("list", [4]) == [1, 2, 3]
        assert config_tree.get("list-new", [4]) == [4]
        assert config_tree.get_list("list", [4]) == [1, 2, 3]
        assert config_tree.get_list("list-new", [4]) == [4]

        config_tree.put("bool", True)
        assert config_tree.get("bool", False) is True
        assert config_tree.get("bool-new", False) is False
        assert config_tree.get_bool("bool", False) is True
        assert config_tree.get_bool("bool-new", False) is False

        config_tree.put("config", {'a': 5})
        assert config_tree.get("config", {'b': 1}) == {'a': 5}
        assert config_tree.get("config-new", {'b': 1}) == {'b': 1}
        assert config_tree.get_config("config", {'b': 1}) == {'a': 5}
        assert config_tree.get_config("config-new", {'b': 1}) == {'b': 1}
开发者ID:ryban,项目名称:pyhocon,代码行数:41,代码来源:test_config_tree.py

示例9: test_config_tree_null

# 需要导入模块: from pyhocon.config_tree import ConfigTree [as 别名]
# 或者: from pyhocon.config_tree.ConfigTree import get [as 别名]
 def test_config_tree_null(self):
     config_tree = ConfigTree()
     config_tree.put("a.b.c", None)
     assert config_tree.get("a.b.c") is None
开发者ID:ryban,项目名称:pyhocon,代码行数:6,代码来源:test_config_tree.py


注:本文中的pyhocon.config_tree.ConfigTree.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。