當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。