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


Python yaml.org方法代码示例

本文整理汇总了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) 
开发者ID:witten,项目名称:borgmatic,代码行数:21,代码来源:load.py

示例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) 
开发者ID:nutanix,项目名称:calm-dsl,代码行数:7,代码来源:utils.py

示例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 
开发者ID:UAVCAN,项目名称:pyuavcan,代码行数:13,代码来源:_yaml.py

示例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) 
开发者ID:meiqua,项目名称:patch_linemod,代码行数:5,代码来源:inout.py

示例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) 
开发者ID:cyanogen,项目名称:uchroma,代码行数:4,代码来源:hardware.py

示例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) 
开发者ID:cyanogen,项目名称:uchroma,代码行数:7,代码来源:config.py

示例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) 
开发者ID:googleapis,项目名称:artman,代码行数:11,代码来源:configure.py

示例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) 
开发者ID:weizhenzhao,项目名称:rasa_nlu,代码行数:13,代码来源:__init__.py

示例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) 
开发者ID:NLeSC,项目名称:scriptcwl,代码行数:11,代码来源:yamlutils.py

示例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) 
开发者ID:botfront,项目名称:rasa-for-botfront,代码行数:12,代码来源:io.py


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