本文整理汇总了Python中ruamel.yaml.org方法的典型用法代码示例。如果您正苦于以下问题:Python yaml.org方法的具体用法?Python yaml.org怎么用?Python yaml.org使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ruamel.yaml
的用法示例。
在下文中一共展示了yaml.org方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: flatten_mapping
# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import org [as 别名]
def flatten_mapping(self, node):
'''
Support the special case of shallow merging included configuration into an existing mapping
using the YAML '<<' merge key. Example syntax:
```
retention:
keep_daily: 1
<<: !include common.yaml
```
'''
representer = ruamel.yaml.representer.SafeRepresenter()
for index, (key_node, value_node) in enumerate(node.value):
if key_node.tag == u'tag:yaml.org,2002:merge' and value_node.tag == '!include':
included_value = representer.represent_data(self.construct_object(value_node))
node.value[index] = (key_node, included_value)
super(Include_constructor, self).flatten_mapping(node)
示例2: str_presenter
# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import org [as 别名]
def str_presenter(dumper, data):
"""For handling multiline strings"""
if len(data.splitlines()) > 1: # check for multiline string
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
return dumper.represent_scalar("tag:yaml.org,2002:str", data)
示例3: _represent_decimal
# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import org [as 别名]
def _represent_decimal(self: ruamel.yaml.BaseRepresenter,
data: decimal.Decimal) -> ruamel.yaml.ScalarNode:
if data.is_finite():
s = str(_POINT_ZERO_DECIMAL + data) # The zero addition is to force float-like string representation
elif data.is_nan():
s = '.nan'
elif data.is_infinite():
s = '.inf' if data > 0 else '-.inf'
else:
assert False
return self.represent_scalar('tag:yaml.org,2002:float', s) # type: ignore
示例4: float_representer
# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import org [as 别名]
def float_representer(dumper, value):
text = '{0:.8f}'.format(value)
return dumper.represent_scalar(u'tag:yaml.org,2002:float', text)
示例5: represent_hex_quad
# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import org [as 别名]
def represent_hex_quad(dumper, data):
return dumper.represent_scalar(u'tag:yaml.org,2002:int', '0x%04x' % data)
示例6: represent_flow_seq
# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import org [as 别名]
def represent_flow_seq(dumper, data):
"""
Dump sequences in flow style
"""
return dumper.represent_sequence(u'tag:yaml.org,2002:seq', data, flow_style=True)
示例7: _represent_ordereddict
# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import org [as 别名]
def _represent_ordereddict(dumper, data):
value = []
for item_key, item_value in data.items():
node_key = dumper.represent_data(item_key)
node_value = dumper.represent_data(item_value)
value.append((node_key, node_value))
return yaml.nodes.MappingNode(u'tag:yaml.org,2002:map', value)
示例8: fix_yaml_loader
# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import org [as 别名]
def fix_yaml_loader() -> None:
"""Ensure that any string read by yaml is represented as unicode."""
def construct_yaml_str(self, node):
# Override the default string handling function
# to always return unicode objects
return self.construct_scalar(node)
yaml.Loader.add_constructor(u'tag:yaml.org,2002:str', construct_yaml_str)
yaml.SafeLoader.add_constructor(u'tag:yaml.org,2002:str',
construct_yaml_str)
示例9: str_presenter
# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import org [as 别名]
def str_presenter(dmpr, data):
"""Return correct str_presenter to write multiple lines to a yaml field.
Source: http://stackoverflow.com/a/33300001
"""
if is_multiline(data):
return dmpr.represent_scalar('tag:yaml.org,2002:str', data, style='|')
return dmpr.represent_scalar('tag:yaml.org,2002:str', data)
示例10: fix_yaml_loader
# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import org [as 别名]
def fix_yaml_loader() -> None:
"""Ensure that any string read by yaml is represented as unicode."""
def construct_yaml_str(self, node):
# Override the default string handling function
# to always return unicode objects
return self.construct_scalar(node)
yaml.Loader.add_constructor("tag:yaml.org,2002:str", construct_yaml_str)
yaml.SafeLoader.add_constructor("tag:yaml.org,2002:str", construct_yaml_str)