本文整理汇总了Python中pyhocon.config_tree.ConfigTree类的典型用法代码示例。如果您正苦于以下问题:Python ConfigTree类的具体用法?Python ConfigTree怎么用?Python ConfigTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConfigTree类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_config_logging
def test_config_logging(self):
import logging.config
config_tree = ConfigTree()
config_tree.put('version', 1)
config_tree.put('root.level', logging.INFO)
assert dict(config_tree)['version'] == 1
logging.config.dictConfig(config_tree)
开发者ID:okdtsk,项目名称:pyhocon,代码行数:7,代码来源:test_config_tree.py
示例2: _fixup_self_references
def _fixup_self_references(cls, config, accept_unresolved=False):
if isinstance(config, ConfigTree) and config.root:
for key in config: # Traverse history of element
history = config.history[key]
previous_item = history[0]
for current_item in history[1:]:
for substitution in cls._find_substitutions(current_item):
prop_path = ConfigTree.parse_key(substitution.variable)
if len(prop_path) > 1 and config.get(substitution.variable, None) is not None:
continue # If value is present in latest version, don't do anything
if prop_path[0] == key:
if isinstance(previous_item, ConfigValues) and not accept_unresolved: # We hit a dead end, we cannot evaluate
raise ConfigSubstitutionException(
"Property {variable} cannot be substituted. Check for cycles.".format(
variable=substitution.variable
)
)
else:
value = previous_item if len(prop_path) == 1 else previous_item.get(".".join(prop_path[1:]))
_, _, current_item = cls._do_substitute(substitution, value)
previous_item = current_item
if len(history) == 1: # special case, when self optional referencing without existing
for substitution in cls._find_substitutions(previous_item):
prop_path = ConfigTree.parse_key(substitution.variable)
if len(prop_path) > 1 and config.get(substitution.variable, None) is not None:
continue # If value is present in latest version, don't do anything
if prop_path[0] == key and substitution.optional:
cls._do_substitute(substitution, None)
开发者ID:chimpler,项目名称:pyhocon,代码行数:29,代码来源:config_parser.py
示例3: test_contains_with_quoted_keys
def test_contains_with_quoted_keys(self):
config_tree = ConfigTree()
config_tree.put('a.b."c.d"', 5)
assert 'a' in config_tree
assert 'a.b' in config_tree
assert 'a.c' not in config_tree
assert 'a.b."c.d"' in config_tree
assert 'a.b.c.d' not in config_tree
开发者ID:chimpler,项目名称:pyhocon,代码行数:8,代码来源:test_config_tree.py
示例4: test_contains
def test_contains(self):
config_tree = ConfigTree()
config_tree.put('a.b', 5)
config_tree.put('a.c', None)
assert 'a' in config_tree
assert 'a.b' in config_tree
assert 'a.c' in config_tree
assert 'a.b.c' not in config_tree
开发者ID:chimpler,项目名称:pyhocon,代码行数:8,代码来源:test_config_tree.py
示例5: create_tree
def create_tree(value):
if isinstance(value, dict):
res = ConfigTree(root=root)
for key, child_value in value.items():
res.put(key, create_tree(child_value))
return res
if isinstance(value, list):
return [create_tree(v) for v in value]
else:
return value
开发者ID:chimpler,项目名称:pyhocon,代码行数:10,代码来源:config_parser.py
示例6: test_config_tree_special_characters
def test_config_tree_special_characters(self):
special_characters = '$}[]:=+#`^[email protected]*&.'
for char in special_characters:
config_tree = ConfigTree()
escaped_key = "\"test{char}key\"".format(char=char)
key = "a.b.{escaped_key}".format(escaped_key=escaped_key)
config_tree.put(key, "value")
hocon_tree = HOCONConverter.to_hocon(config_tree)
assert escaped_key in hocon_tree
parsed_tree = ConfigFactory.parse_string(hocon_tree)
assert parsed_tree.get(key) == "value"
开发者ID:chimpler,项目名称:pyhocon,代码行数:11,代码来源:test_config_tree.py
示例7: test_config_list
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,代码行数:11,代码来源:test_config_tree.py
示例8: test_config_tree_quoted_string
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,代码行数:13,代码来源:test_config_tree.py
示例9: test_durations
def test_durations(self):
one_sec = ("1s", "1 s", "1seconds", "1 seconds", " 1s ", " 1 s ",
"1second",
"1000", "1000ms", "1000 ms", "1000 milliseconds", " 1000 milliseconds ",
"1000millisecond",
"1000000us", "1000000 us", "1000000 microseconds", "1000000microsecond",
"1000000000ns", "1000000000 ns", "1000000000 nanoseconds", "1000000000nanosecond",
"0.01666666666666666666666m", "0.01666666666666666666666 minutes", "0.01666666666666666666666 minute",
"0.00027777777777777777777h", "0.00027777777777777777777 hours", "0.00027777777777777777777hour",
"1.1574074074074073e-05d", "1.1574074074074073e-05 days", "1.1574074074074073e-05day")
config_tree = ConfigTree()
nanos_in_one_sec = 1000**3
millis_in_one_sec = 1000
for repr in one_sec:
config_tree.put("one_sec", repr)
assert config_tree.get_nanoseconds() == nanos_in_one_sec
assert config_tree.get_milliseconds() == millis_in_one_sec
开发者ID:cmenguy,项目名称:pyhocon,代码行数:17,代码来源:test_config_tree.py
示例10: test_numerically_index_objects_to_arrays
def test_numerically_index_objects_to_arrays(self):
config_tree = ConfigTree()
config_tree.put("list.2", "b")
config_tree.put("list.0", "a")
assert config_tree.get_list("list") == ["a", "b"]
config_tree.put("invalid-list.a", "c")
config_tree.put("invalid-list.b", "d")
with pytest.raises(ConfigException):
config_tree.get_list("invalid-list")
开发者ID:chimpler,项目名称:pyhocon,代码行数:10,代码来源:test_config_tree.py
示例11: postParse
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:
# Merge dict
if isinstance(value, ConfigValues):
conf_value = value
value.parent = config_tree
value.key = key
else:
conf_value = value
config_tree.put(key, conf_value)
return config_tree
开发者ID:peoplepattern,项目名称:pyhocon,代码行数:34,代码来源:__init__.py
示例12: test_getter_type_conversion_bool_to_string
def test_getter_type_conversion_bool_to_string(self):
config_tree = ConfigTree()
config_tree.put("bool-true", True)
assert config_tree.get_string("bool-true") == "true"
config_tree.put("bool-false", False)
assert config_tree.get_string("bool-false") == "false"
开发者ID:cnspica,项目名称:pyhocon,代码行数:7,代码来源:test_config_tree.py
示例13: test_getter_type_conversion_number_to_string
def test_getter_type_conversion_number_to_string(self):
config_tree = ConfigTree()
config_tree.put("int", 5)
assert config_tree.get_string("int") == "5"
config_tree.put("float", 2.345)
assert config_tree.get_string("float") == "2.345"
开发者ID:cnspica,项目名称:pyhocon,代码行数:7,代码来源:test_config_tree.py
示例14: test_plain_ordered_dict
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,代码行数:11,代码来源:test_config_tree.py
示例15: postParse
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:
# from include then merge items
expanded_tokens = element.items() if isinstance(element, ConfigTree) else [element]
for tokens in expanded_tokens:
# key, value1, value2, ...
key = tokens[0].strip()
values = tokens[1:]
# empty string
if len(values) == 0:
config_tree.put(key, '')
else:
if isinstance(values[0], list):
# Merge arrays
config_tree.put(key, values[0], False)
for value in values[1:]:
config_tree.put(key, value, True)
else:
# Merge dict
for value in values:
if isinstance(value, ConfigList):
conf_value = list(value)
elif isinstance(value, ConfigValues):
conf_value = value
value.parent = config_tree
value.key = key
else:
conf_value = value
config_tree.put(key, conf_value)
return config_tree
开发者ID:laserson,项目名称:pyhocon,代码行数:41,代码来源:__init__.py
示例16: test_getters_with_default
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,代码行数:39,代码来源:test_config_tree.py
示例17: test_getters
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,代码行数:31,代码来源:test_config_tree.py
示例18: test_config_tree_null
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,代码行数:4,代码来源:test_config_tree.py
示例19: test_config_tree_iterator
def test_config_tree_iterator(self):
config_tree = ConfigTree()
config_tree.put("a.b.c", 5)
for k in config_tree:
assert k == "a"
assert config_tree[k]["b.c"] == 5
开发者ID:ryban,项目名称:pyhocon,代码行数:6,代码来源:test_config_tree.py
示例20: test_configtree_pop
def test_configtree_pop(self):
config_tree = ConfigTree()
config_tree.put("string", "string")
assert config_tree.pop("string", "default") == "string"
assert config_tree.pop("string-new", "default") == "default"
assert config_tree == ConfigTree()
with pytest.raises(ConfigMissingException):
assert config_tree.pop("string-new")
config_tree.put("list", [1, 2, 3])
assert config_tree.pop("list", [4]) == [1, 2, 3]
assert config_tree.pop("list-new", [4]) == [4]
assert config_tree == ConfigTree()
config_tree.put("config", {'a': 5})
assert config_tree.pop("config", {'b': 1}) == {'a': 5}
assert config_tree.pop("config-new", {'b': 1}) == {'b': 1}
assert config_tree == ConfigTree()
config_tree = ConfigTree()
config_tree.put('key', 'value')
assert config_tree.pop('key', 'value') == 'value'
assert 'key' not in config_tree
config_tree = ConfigTree()
config_tree.put('a.b.c.one', 1)
config_tree.put('a.b.c.two', 2)
config_tree.put('"f.k".g.three', 3)
exp = OrderedDict()
exp['a'] = OrderedDict()
exp['a']['b'] = OrderedDict()
exp['a']['b']['c'] = OrderedDict()
exp['a']['b']['c']['one'] = 1
exp['a']['b']['c']['two'] = 2
exp['f.k'] = OrderedDict()
exp['f.k']['g'] = OrderedDict()
exp['f.k']['g']['three'] = 3
assert config_tree.pop('a.b.c').as_plain_ordered_dict() == exp['a']['b']['c']
assert config_tree.pop('a.b.c', None) is None
with pytest.raises(ConfigMissingException):
assert config_tree.pop('a.b.c')
with pytest.raises(ConfigMissingException):
assert config_tree['a']['b'].pop('c')
assert config_tree.pop('a').as_plain_ordered_dict() == OrderedDict(b=OrderedDict())
assert config_tree.pop('"f.k"').as_plain_ordered_dict() == OrderedDict(g=OrderedDict(three=3))
assert config_tree.as_plain_ordered_dict() == OrderedDict()
开发者ID:chimpler,项目名称:pyhocon,代码行数:52,代码来源:test_config_tree.py
注:本文中的pyhocon.config_tree.ConfigTree类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论