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


Python yaml.ScalarNode方法代码示例

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


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

示例1: unicode_representer

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import ScalarNode [as 别名]
def unicode_representer(_, data):
    has_wide_lines = False
    for line in data.splitlines():
        if len(line) > 80:
            has_wide_lines = True
            break

    if has_wide_lines:
        return yaml.ScalarNode(
            u'tag:yaml.org,2002:str', data, style='>')

    if "\n" in data:
        return yaml.ScalarNode(
            u'tag:yaml.org,2002:str', data, style='|')

    return yaml.ScalarNode(
        u'tag:yaml.org,2002:str', data, style='') 
开发者ID:google,项目名称:rekall,代码行数:19,代码来源:yaml_utils.py

示例2: construct_mapping

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import ScalarNode [as 别名]
def construct_mapping(self, node, deep=False):
        if not isinstance(node, yaml.MappingNode):
            raise ConstructorError(None, None,
                    "expected a mapping node, but found %s" % node.id,
                    node.start_mark)
        key_set = set()
        for key_node, value_node in node.value:
            if not isinstance(key_node, yaml.ScalarNode):
                continue
            k = key_node.value
            if k in key_set:
                raise ConstructorError(
                    "while constructing a mapping", node.start_mark,
                    "found duplicate key", key_node.start_mark)
            key_set.add(k)

        return super(DuplicateKeyCheckLoader, self).construct_mapping(node, deep) 
开发者ID:cloud-custodian,项目名称:cloud-custodian,代码行数:19,代码来源:commands.py

示例3: multi_constructor

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import ScalarNode [as 别名]
def multi_constructor(loader, tag_suffix, node):
    """
    Deal with !Ref style function format
    """

    if tag_suffix not in UNCONVERTED_SUFFIXES:
        tag_suffix = '{}{}'.format(FN_PREFIX, tag_suffix)

    constructor = None
    if tag_suffix == 'Fn::GetAtt':
        constructor = construct_getatt
    elif isinstance(node, ScalarNode):
        constructor = loader.construct_scalar
    elif isinstance(node, SequenceNode):
        constructor = loader.construct_sequence
    elif isinstance(node, MappingNode):
        constructor = loader.construct_mapping
    else:
        raise 'Bad tag: !{}'.format(tag_suffix)

    return dict_node({tag_suffix: constructor(node)}, node.start_mark, node.end_mark) 
开发者ID:bridgecrewio,项目名称:checkov,代码行数:23,代码来源:cfn_yaml.py

示例4: rel_path

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import ScalarNode [as 别名]
def rel_path(self, node):
        """Handles !rel_path file command.  Supports:

        scenes: !rel_path file.yaml

        Allows the use of relative paths in the config.yaml file.  Intended
        for use with scenes.

        Args:
          node:  The YAML node to load.
        """
        # input is a single file to load.
        if isinstance(node, yaml.ScalarNode):
            filename = self.construct_scalar(node)
            return os.path.join(self._base_dir, filename)

        else:
            msg = ("Error: unrecognized node type in !rel_path statement: %s"
                   % str(node))
            raise yaml.constructor.ConstructorError(msg)

#=========================================================================== 
开发者ID:TD22057,项目名称:insteon-mqtt,代码行数:24,代码来源:config.py

示例5: multi_constructor

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import ScalarNode [as 别名]
def multi_constructor(loader, tag_suffix, node):
    """
    Deal with !Ref style function format
    """

    if tag_suffix not in UNCONVERTED_SUFFIXES:
        tag_suffix = "{}{}".format(FN_PREFIX, tag_suffix)

    constructor = None

    if tag_suffix == "Fn::GetAtt":
        constructor = construct_getatt
    elif isinstance(node, yaml.ScalarNode):
        constructor = loader.construct_scalar
    elif isinstance(node, yaml.SequenceNode):
        constructor = loader.construct_sequence
    elif isinstance(node, yaml.MappingNode):
        constructor = loader.construct_mapping
    else:
        raise Exception("Bad tag: !{}".format(tag_suffix))

    return ODict((
        (tag_suffix, constructor(node)),
    )) 
开发者ID:awslabs,项目名称:aws-cfn-template-flip,代码行数:26,代码来源:yaml_loader.py

示例6: represent_odict

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import ScalarNode [as 别名]
def represent_odict(dump, tag, mapping, flow_style=None):
    value = []
    node = yaml.MappingNode(tag, value, flow_style=flow_style)
    if dump.alias_key is not None:
        dump.represented_objects[dump.alias_key] = node
    best_style = True
    if hasattr(mapping, 'items'):
        mapping = mapping.items()
    for item_key, item_value in mapping:
        node_key = dump.represent_data(item_key)
        node_value = dump.represent_data(item_value)
        if not (isinstance(node_key, yaml.ScalarNode) and not node_key.style):
            best_style = False
        if not (isinstance(node_value, yaml.ScalarNode)
                and not node_value.style):
            best_style = False
        value.append((node_key, node_value))
    if flow_style is None:
        if dump.default_flow_style is not None:
            node.flow_style = dump.default_flow_style
        else:
            node.flow_style = best_style
    return node 
开发者ID:openstack,项目名称:tacker,代码行数:25,代码来源:utils.py

示例7: represent_odict

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import ScalarNode [as 别名]
def represent_odict(self, dump, tag, mapping, flow_style=None):
        value = []
        node = yaml.MappingNode(tag, value, flow_style=flow_style)
        if dump.alias_key is not None:
            dump.represented_objects[dump.alias_key] = node
        best_style = True
        if hasattr(mapping, 'items'):
            mapping = mapping.items()
        for item_key, item_value in mapping:
            node_key = dump.represent_data(item_key)
            node_value = dump.represent_data(item_value)
            if not (isinstance(node_key, yaml.ScalarNode)
                    and not node_key.style):
                best_style = False
            if not (isinstance(node_value, yaml.ScalarNode)
                    and not node_value.style):
                best_style = False
            value.append((node_key, node_value))
        if flow_style is None:
            if dump.default_flow_style is not None:
                node.flow_style = dump.default_flow_style
            else:
                node.flow_style = best_style
        return node 
开发者ID:openstack,项目名称:tacker,代码行数:26,代码来源:translate_template.py

示例8: represent_odict

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import ScalarNode [as 别名]
def represent_odict(dump, tag, mapping, flow_style=None):
    """Like BaseRepresenter.represent_mapping, but does not issue the sort().
    """
    value = []
    node = yaml.MappingNode(tag, value, flow_style=flow_style)
    if dump.alias_key is not None:
        dump.represented_objects[dump.alias_key] = node
    best_style = True
    if hasattr(mapping, 'items'):
        mapping = mapping.items()
    for item_key, item_value in mapping:
        node_key = dump.represent_data(item_key)
        node_value = dump.represent_data(item_value)
        if not (isinstance(node_key, yaml.ScalarNode) and not node_key.style):
            best_style = False
        if not (isinstance(node_value, yaml.ScalarNode) and not node_value.style):
            best_style = False
        value.append((node_key, node_value))
    if flow_style is None:
        if dump.default_flow_style is not None:
            node.flow_style = dump.default_flow_style
        else:
            node.flow_style = best_style
    return node 
开发者ID:artsy,项目名称:hokusai,代码行数:26,代码来源:representers.py

示例9: repr_pairs

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import ScalarNode [as 别名]
def repr_pairs(dump, tag, sequence, flow_style=None):
    """This is the same code as BaseRepresenter.represent_sequence(),
    but the value passed to dump.represent_data() in the loop is a
    dictionary instead of a tuple."""
 
    value = []
    node = yaml.SequenceNode(tag, value, flow_style=flow_style)
    if dump.alias_key is not None:
        dump.represented_objects[dump.alias_key] = node
    best_style = True
    for (key, val) in sequence:
        item = dump.represent_data({key: val})
        if not (isinstance(item, yaml.ScalarNode) and not item.style):
            best_style = False
        value.append(item)
    if flow_style is None:
        if dump.default_flow_style is not None:
            node.flow_style = dump.default_flow_style
        else:
            node.flow_style = best_style
    return node 
开发者ID:airspy,项目名称:airspyone_firmware,代码行数:23,代码来源:yaml_odict.py

示例10: include

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import ScalarNode [as 别名]
def include(self, node):
        if isinstance(node, yaml.ScalarNode):
            return self.extractFile(self.construct_scalar(node))

        elif isinstance(node, yaml.SequenceNode):
            result = []

            for i in self.construct_sequence(node):
                i = general_function.get_absolute_path(i, self._root)
                for j in general_files_func.get_ofs(i):
                    result += self.extractFile(j)
            return result

        elif isinstance(node, yaml.MappingNode):
            result = {}
            for k,v in self.construct_mapping(node).iteritems():
                result[k] = self.extractFile(v)
            return result

        else:
            print ('Error:: unrecognised node type in !include statement')
            raise yaml.constructor.ConstructorError 
开发者ID:nixys,项目名称:nxs-backup,代码行数:24,代码来源:specific_function.py

示例11: represent_odict

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import ScalarNode [as 别名]
def represent_odict(dump, tag, mapping, flow_style=None):
    """
    Like BaseRepresenter.represent_mapping, but does not issue the sort().
    """
    value = []
    node = yaml.MappingNode(tag, value, flow_style=flow_style)
    if dump.alias_key is not None:
        dump.represented_objects[dump.alias_key] = node
    best_style = True
    if hasattr(mapping, 'items'):
        mapping = mapping.items()
    for item_key, item_value in mapping:
        node_key = dump.represent_data(item_key)
        node_value = dump.represent_data(item_value)
        if not (isinstance(node_key, yaml.ScalarNode) and not node_key.style):
            best_style = False
        if not (isinstance(node_value, yaml.ScalarNode) and not node_value.style):
            best_style = False
        value.append((node_key, node_value))
    if flow_style is None:
        if dump.default_flow_style is not None:
            node.flow_style = dump.default_flow_style
        else:
            node.flow_style = best_style
    return node 
开发者ID:oanda,项目名称:v20-python,代码行数:27,代码来源:base_entity.py

示例12: test_handle_yaml_constructors_converts_base64

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import ScalarNode [as 别名]
def test_handle_yaml_constructors_converts_base64(self):
        loader_mock = Mock()
        loader_mock.construct_scalar.return_value = "myString"
        node_mock = Mock(spec=yaml.ScalarNode)

        response = FileLoader.handle_yaml_constructors(loader_mock, "!base64", node_mock)
        self.assertEqual({'Fn::Base64': 'myString'}, response) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:9,代码来源:file_loader_tests.py

示例13: test_handle_yaml_constructors_converts_and

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import ScalarNode [as 别名]
def test_handle_yaml_constructors_converts_and(self):
        loader_mock = Mock()
        loader_mock.construct_scalar.return_value = ["myCondition", "myOtherCondition"]
        node_mock = Mock(spec=yaml.ScalarNode)

        response = FileLoader.handle_yaml_constructors(loader_mock, "!and", node_mock)
        self.assertEqual({'Fn::And': ["myCondition", "myOtherCondition"]}, response) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:9,代码来源:file_loader_tests.py

示例14: test_handle_yaml_constructors_converts_equals

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import ScalarNode [as 别名]
def test_handle_yaml_constructors_converts_equals(self):
        loader_mock = Mock()
        loader_mock.construct_scalar.return_value = ["myValue", "myOtherValue"]
        node_mock = Mock(spec=yaml.ScalarNode)

        response = FileLoader.handle_yaml_constructors(loader_mock, "!equals", node_mock)
        self.assertEqual({'Fn::Equals': ["myValue", "myOtherValue"]}, response) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:9,代码来源:file_loader_tests.py

示例15: test_handle_yaml_constructors_converts_if

# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import ScalarNode [as 别名]
def test_handle_yaml_constructors_converts_if(self):
        loader_mock = Mock()
        loader_mock.construct_scalar.return_value = ["myCondition", "myOtherCondition"]
        node_mock = Mock(spec=yaml.ScalarNode)

        response = FileLoader.handle_yaml_constructors(loader_mock, "!if", node_mock)
        self.assertEqual({'Fn::If': ["myCondition", "myOtherCondition"]}, response) 
开发者ID:cfn-sphere,项目名称:cfn-sphere,代码行数:9,代码来源:file_loader_tests.py


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