• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pyhocon.ConfigFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyhocon.ConfigFactory的典型用法代码示例。如果您正苦于以下问题:Python ConfigFactory类的具体用法?Python ConfigFactory怎么用?Python ConfigFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_self_ref_substitution_dict_recurse

 def test_self_ref_substitution_dict_recurse(self):
     with pytest.raises(ConfigSubstitutionException):
         ConfigFactory.parse_string(
             """
             x = ${x}
             """
         )
开发者ID:cnspica,项目名称:pyhocon,代码行数:7,代码来源:test_config_parser.py


示例2: test_substitutions_overwrite

    def test_substitutions_overwrite(self):
        config1 = ConfigFactory.parse_string(
            """
            a = 123
            a = ${?test}
            a = 5
            """
        )

        assert config1["a"] == 5

        config2 = ConfigFactory.parse_string(
            """
            {
              database {
                host = "localhost"
                port = 8000
                url = ${database.host}":"${database.port}
              }

              database {
                host = ${?DB_HOST}
              }

              database {
                host = "other.host.net"
                port = 433
              }
            }
            """
        )

        assert config2["database"]["host"] == "other.host.net"
        assert config2["database"]["port"] == 433
        assert config2["database"]["url"] == "other.host.net:433"
开发者ID:peoplepattern,项目名称:pyhocon,代码行数:35,代码来源:test_config_parser.py


示例3: convert

    def convert(input_file=None, output_file=None, format='json'):
        """Convert to json, properties or yaml

        :param format: json, properties or yaml
        :type format: basestring
        :return: json, properties or yaml string representation
        """

        if input_file is None:
            content = sys.stdin.read()
            config = ConfigFactory.parse_string(content)
        else:
            config = ConfigFactory.parse_file(input_file)

        if format.lower() == 'json':
            res = HOCONConverter.to_json(config)
        elif format.lower() == 'properties':
            res = HOCONConverter.to_properties(config)
        elif format.lower() == 'yaml':
            res = HOCONConverter.to_yaml(config)
        else:
            raise Exception("Format must be 'json', 'properties' or 'yaml'")

        if output_file is None:
            print(res)
        else:
            with open(output_file, "w") as fd:
                fd.write(res)
开发者ID:peoplepattern,项目名称:pyhocon,代码行数:28,代码来源:tool.py


示例4: test_substitution_cycle

 def test_substitution_cycle(self):
     with pytest.raises(ConfigSubstitutionException):
         ConfigFactory.parse_string(
             """
             a = ${b}
             b = ${c}
             c = ${a}
             """)
开发者ID:davechina,项目名称:pyhocon,代码行数:8,代码来源:test_config_parser.py


示例5: test_string_substitutions

    def test_string_substitutions(self):
        config1 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = str
                        e = "str      "
                    }
                }
                d = ${a.b.c}
                f = ${a.b.e}
            }
            """
        )

        assert config1.get("a.b.c") == "str"
        assert config1.get("d") == "str"
        assert config1.get("f") == "str      "

        config2 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = str
                        e = "str      "
                    }
                }
                d = test  ${a.b.c}
                f = test  ${a.b.e}
            }
            """
        )

        assert config2.get("a.b.c") == "str"
        assert config2.get("d") == "test  str"
        assert config2.get("f") == "test  str      "

        config3 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = str
                        e = "str      "
                    }
                }
                d = test  ${a.b.c}  me
                f = test  ${a.b.e}  me
            }
            """
        )

        assert config3.get("a.b.c") == "str"
        assert config3.get("d") == "test  str  me"
        assert config3.get("f") == "test  str        me"
开发者ID:peoplepattern,项目名称:pyhocon,代码行数:57,代码来源:test_config_parser.py


示例6: test_string_substitutions

    def test_string_substitutions(self):
        config1 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = str
                        e = "str      "
                    }
                }
                d = ${a.b.c}
                f = ${a.b.e}
            }
            """
        )

        assert config1.get('a.b.c') == 'str'
        assert config1.get('d') == 'str'
        assert config1.get('f') == 'str      '

        config2 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = str
                        e = "str      "
                    }
                }
                d = test  ${a.b.c}
                f = test  ${a.b.e}
            }
            """
        )

        assert config2.get('a.b.c') == 'str'
        assert config2.get('d') == 'test  str'
        assert config2.get('f') == 'test  str      '

        config3 = ConfigFactory.parse_string(
            u"""
            {
                a: {
                    b: {
                        c = str
                        e = "str      "
                    }
                }
                d = test  ${a.b.c}  me
                f = test  ${a.b.e}  me
            }
            """
        )

        assert config3.get('a.b.c') == 'str'
        assert config3.get('d') == 'test  str  me'
        assert config3.get('f') == 'test  str        me'
开发者ID:davechina,项目名称:pyhocon,代码行数:57,代码来源:test_config_parser.py


示例7: test_invalid_dict

    def test_invalid_dict(self):
        with pytest.raises(ParseSyntaxException):
            ConfigFactory.parse_string(
                """
                a = {
                    f: 5
                    g
                }
                """)

        with pytest.raises(ParseSyntaxException):
            ConfigFactory.parse_string('a = {g}')
开发者ID:davechina,项目名称:pyhocon,代码行数:12,代码来源:test_config_parser.py


示例8: test_fallback_self_ref_substitutions_concat_string

 def test_fallback_self_ref_substitutions_concat_string(self):
     config1 = ConfigFactory.parse_string(
         """
         string = abc
         """
     )
     config2 = ConfigFactory.parse_string(
         """
         string = ${string}def
         """,
         resolve=False
     )
     config2 = config2.with_fallback(config1)
     assert config2.get("string") == 'abcdef'
开发者ID:cnspica,项目名称:pyhocon,代码行数:14,代码来源:test_config_parser.py


示例9: test_fallback_self_ref_substitutions_append_plus_equals

 def test_fallback_self_ref_substitutions_append_plus_equals(self):
     config1 = ConfigFactory.parse_string(
         """
         list = [ 1, 2, 3 ]
         """
     )
     config2 = ConfigFactory.parse_string(
         """
         list += [ 4, 5, 6 ]
         """,
         resolve=False
     )
     config2 = config2.with_fallback(config1)
     assert config2.get("list") == [1, 2, 3, 4, 5, 6]
开发者ID:cnspica,项目名称:pyhocon,代码行数:14,代码来源:test_config_parser.py


示例10: test_fallback_self_ref_substitutions_merge

 def test_fallback_self_ref_substitutions_merge(self):
     config1 = ConfigFactory.parse_string(
         """
         dict = { x: 1 }
         """
     )
     config2 = ConfigFactory.parse_string(
         """
         dict = ${dict} { y: 2 }
         """,
         resolve=False
     )
     config2 = config2.with_fallback(config1)
     assert config2.get("dict") == {'x': 1, 'y': 2}
开发者ID:cnspica,项目名称:pyhocon,代码行数:14,代码来源:test_config_parser.py


示例11: test_non_existent_substitution

    def test_non_existent_substitution(self):
        with pytest.raises(ConfigSubstitutionException):
            ConfigFactory.parse_string(
                """
                    common_modules = ${non_existent}
                """
            )

        with pytest.raises(ConfigSubstitutionException):
            ConfigFactory.parse_string(
                """
                    common_modules = abc ${non_existent}
                """
            )

        with pytest.raises(ConfigSubstitutionException):
            ConfigFactory.parse_string(
                """
                    common_modules = ${non_existent} abc
                """
            )

        with pytest.raises(ConfigSubstitutionException):
            ConfigFactory.parse_string(
                """
                    common_modules = abc ${non_existent} def
                """
            )
开发者ID:davechina,项目名称:pyhocon,代码行数:28,代码来源:test_config_parser.py


示例12: test_bad_concat

 def test_bad_concat(self):
     ConfigFactory.parse_string('a = 45\n')
     with pytest.raises(ConfigWrongTypeException):
         ConfigFactory.parse_string('a = [4] "4"')
     with pytest.raises(ConfigWrongTypeException):
         ConfigFactory.parse_string('a = "4" [5]')
     with pytest.raises(ConfigWrongTypeException):
         ConfigFactory.parse_string('a = {b: 5} "4"')
开发者ID:davechina,项目名称:pyhocon,代码行数:8,代码来源:test_config_parser.py


示例13: test_int_substitutions

    def test_int_substitutions(self):
        config1 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = 5
                    }
                }
                d = ${a.b.c}
            }
            """
        )

        assert config1.get('a.b.c') == 5
        assert config1.get('d') == 5

        config2 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = 5
                    }
                }
                d = test ${a.b.c}
            }
            """
        )

        assert config2.get('a.b.c') == 5
        assert config2.get('d') == 'test 5'

        config3 = ConfigFactory.parse_string(
            """
            {
                a: {
                    b: {
                        c = 5
                    }
                }
                d = test ${a.b.c} me
            }
            """
        )

        assert config3.get('a.b.c') == 5
        assert config3.get('d') == 'test 5 me'
开发者ID:davechina,项目名称:pyhocon,代码行数:48,代码来源:test_config_parser.py


示例14: test_parse_null

 def test_parse_null(self):
     config = ConfigFactory.parse_string(
         """
         a = null
         """
     )
     assert config.get('a') is None
开发者ID:davechina,项目名称:pyhocon,代码行数:7,代码来源:test_config_parser.py


示例15: test_parse_with_comments

    def test_parse_with_comments(self):
        config = ConfigFactory.parse_string(
            """
            // comment 1
            # comment 2
            {
                c = test   // comment 0
                g = 6 test   # comment 0
                # comment 3
                a: { # comment 4
                    b: test,                # comment 5
                } # comment 6
                t = [1, # comment 7
                     2, # comment 8
                     3, # comment 9
                ]
            } # comment 10
            // comment 11
            // comment 12
            """
        )

        assert config.get('c') == 'test'
        assert config.get('g') == '6 test'
        assert config.get('a.b') == 'test'
        assert config.get_string('a.b') == 'test'
        assert config.get('t') == [1, 2, 3]
开发者ID:davechina,项目名称:pyhocon,代码行数:27,代码来源:test_config_parser.py


示例16: test_parse_simple_value

    def test_parse_simple_value(self):
        config = ConfigFactory.parse_string(
            """t = {
                c = 5
                "d" = true
                e.y = {
                    f: 7
                    g: "hey dude!"
                    h: hey man!
                    i = \"\"\"
                        "first line"
                        "second" line
                        \"\"\"
                }
                j = [1, 2, 3]
                u = 192.168.1.3/32
            }
            """
        )

        assert config.get_string('t.c') == '5'
        assert config.get_int('t.c') == 5
        assert config.get('t.e.y.f') == 7
        assert config.get('t.e.y.g') == 'hey dude!'
        assert config.get('t.e.y.h') == 'hey man!'
        assert [l.strip() for l in config.get('t.e.y.i').split('\n')] == ['', '"first line"', '"second" line', '']
        assert config.get_bool('t.d') is True
        assert config.get_int('t.e.y.f') == 7
        assert config.get('t.j') == [1, 2, 3]
        assert config.get('t.u') == '192.168.1.3/32'
开发者ID:davechina,项目名称:pyhocon,代码行数:30,代码来源:test_config_parser.py


示例17: test_dict_merge

    def test_dict_merge(self):
        config = ConfigFactory.parse_string(
            """
            a {
                    d {
                            g.h.j.u: 5
                            g {
                                    h.d: 4
                            }
                            g.h.k: f d
                    }

                    h.i.m = 7
                    h.i {
                            d: 5
                    }

                    h.i {
                            e:65
                    }
            }
            """
        )

        expected_result = {
            "a": {"d": {"g": {"h": {"j": {"u": 5}, "d": 4, "k": "f d"}}}, "h": {"i": {"m": 7, "d": 5, "e": 65}}}
        }
        assert expected_result == config
开发者ID:peoplepattern,项目名称:pyhocon,代码行数:28,代码来源:test_config_parser.py


示例18: test_assign_dict_strings_no_equal_sign_with_eol

    def test_assign_dict_strings_no_equal_sign_with_eol(self):
        config = ConfigFactory.parse_string(
            """
            a
            {
            a: 1,
            b: 2,
            }

            b # test
            # test2
            {
            c: 3,
            d: 4,}

            c

            {
            e: 5,
            f: 6
            }
            """
        )
        assert config['a'] == {'a': 1, 'b': 2}
        assert config['b'] == {'c': 3, 'd': 4}
        assert config['c'] == {'e': 5, 'f': 6}
开发者ID:davechina,项目名称:pyhocon,代码行数:26,代码来源:test_config_parser.py


示例19: test_assign_list_numbers_with_eol

    def test_assign_list_numbers_with_eol(self):
        config = ConfigFactory.parse_string(
            """
            a =
            [
            1,
            2,
            ]

            b = # test
            # test2
            [
            3,
            4,]

            c =

            [
            5,
            6
            ]
            """
        )
        assert config['a'] == [1, 2]
        assert config['b'] == [3, 4]
        assert config['c'] == [5, 6]
开发者ID:davechina,项目名称:pyhocon,代码行数:26,代码来源:test_config_parser.py


示例20: get_custom_settings

def get_custom_settings(args):
    custom_settings_file = vars(args).get('custom_settings_file')
    if custom_settings_file and os.path.exists(custom_settings_file):
        print('Loading custom settings {}'.format(custom_settings_file))
        return ConfigFactory.parse_file(custom_settings_file)
    else:
        return None
开发者ID:pengyangtuo,项目名称:conductr-cli,代码行数:7,代码来源:conduct_main.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python config_tree.ConfigTree类代码示例发布时间:2022-05-25
下一篇:
Python testcase.TestCaseQApp类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap