當前位置: 首頁>>代碼示例>>Python>>正文


Python yaml.SequenceNode方法代碼示例

本文整理匯總了Python中yaml.SequenceNode方法的典型用法代碼示例。如果您正苦於以下問題:Python yaml.SequenceNode方法的具體用法?Python yaml.SequenceNode怎麽用?Python yaml.SequenceNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yaml的用法示例。


在下文中一共展示了yaml.SequenceNode方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: multi_constructor

# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import SequenceNode [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

示例2: multi_constructor

# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import SequenceNode [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

示例3: repr_pairs

# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import SequenceNode [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

示例4: include

# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import SequenceNode [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

示例5: handle_yaml_constructors

# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import SequenceNode [as 別名]
def handle_yaml_constructors(loader, suffix, node):
        """
        Constructor method for PyYaml to handle cfn intrinsic functions specified as yaml tags
        """
        function_mapping = {
            "!and": ("Fn::And", lambda x: x),
            "!base64": ("Fn::Base64", lambda x: x),
            "!condition": ("Condition", lambda x: x),
            "!equals": ("Fn::Equals", lambda x: x),
            "!findinmap": ("Fn::FindInMap", lambda x: x),
            "!getatt": ("Fn::GetAtt", lambda x: str(x).split(".", 1)),
            "!getazs": ("Fn::GetAZs", lambda x: x),
            "!if": ("Fn::If", lambda x: x),
            "!importvalue": ("Fn::ImportValue", lambda x: x),
            "!join": ("Fn::Join", lambda x: [x[0], x[1]]),
            "!not": ("Fn::Not", lambda x: x),
            "!or": ("Fn::Or", lambda x: x),
            "!ref": ("Ref", lambda x: x),
            "!select": ("Fn::Select", lambda x: x),
            "!split": ("Fn::Split", lambda x: x),
            "!sub": ("Fn::Sub", lambda x: x),
        }
        try:
            function, value_transformer = function_mapping[str(suffix).lower()]
        except KeyError as key:
            raise CfnSphereException(
                "Unsupported cfn intrinsic function tag found: {0}".format(key))

        if isinstance(node, yaml.ScalarNode):
            value = loader.construct_scalar(node)
        elif isinstance(node, yaml.SequenceNode):
            value = loader.construct_sequence(node)
        elif isinstance(node, yaml.MappingNode):
            value = loader.construct_mapping(node)
        else:
            raise CfnSphereException(
                "Invalid yaml node found while handling cfn intrinsic function tags")

        return {function: value_transformer(value)} 
開發者ID:cfn-sphere,項目名稱:cfn-sphere,代碼行數:41,代碼來源:file_loader.py

示例6: construct_odict

# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import SequenceNode [as 別名]
def construct_odict(self, node):
        omap = OrderedDict()
        yield omap
        if not isinstance(node, yaml.SequenceNode):
            raise yaml.constructor.ConstructorError(
                "while constructing an ordered map",
                node.start_mark,
                "expected a sequence, but found %s" % node.id, node.start_mark
            )
        for subnode in node.value:
            if not isinstance(subnode, yaml.MappingNode):
                raise yaml.constructor.ConstructorError(
                    "while constructing an ordered map", node.start_mark,
                    "expected a mapping of length 1, but found %s" % subnode.id,
                    subnode.start_mark
                )
            if len(subnode.value) != 1:
                raise yaml.constructor.ConstructorError(
                    "while constructing an ordered map", node.start_mark,
                    "expected a single mapping item, but found %d items" % len(subnode.value),
                    subnode.start_mark
                )
            key_node, value_node = subnode.value[0]
            key = self.construct_object(key_node)
            value = self.construct_object(value_node)
            omap[key] = value 
開發者ID:sinall,項目名稱:StrategyEase-Python-SDK,代碼行數:28,代碼來源:support.py

示例7: load

# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import SequenceNode [as 別名]
def load(name: str, value: Any, *allowed: Tag) -> SequenceView:
    if isinstance(value, str):
        value = StringIO(value)
        value.name = name
    result = view(SequenceNode(Tag.SEQUENCE.value, list(compose_all(value))), ViewMode.PYTHON)
    for r in view(result, ViewMode.NODE):
        if r.tag not in allowed:
            raise ValueError("expecting %s, got %s" % (", ".join(t.name for t in allowed),
                                                       r.node.tag))
    return result 
開發者ID:datawire,項目名稱:ambassador,代碼行數:12,代碼來源:parser.py

示例8: include

# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import SequenceNode [as 別名]
def include(self, node):
        """!include file command.  Supports:

        foo: !include file.yaml
        foo: !include [file1.yaml, file2.yaml]

        Args:
          node:  The YAML node to load.
        """
        # input is a single file to load.
        if isinstance(node, yaml.ScalarNode):
            include_file = self.construct_scalar(node)
            return self._load_file(include_file)

        # input is a list of files to load.
        elif isinstance(node, yaml.SequenceNode):
            result = []
            for include_file in self.construct_sequence(node):
                result += self._load_file(include_file)
            return result

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

    #----------------------------------------------------------------------- 
開發者ID:TD22057,項目名稱:insteon-mqtt,代碼行數:29,代碼來源:config.py

示例9: _repr_pairs

# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import SequenceNode [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.

    Source: https://gist.github.com/weaver/317164
    License: Unspecified
    """
    import yaml

    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:holzschu,項目名稱:Carnets,代碼行數:29,代碼來源:meta.py

示例10: construct_odict

# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import SequenceNode [as 別名]
def construct_odict(load, node):
    """This is the same as SafeConstructor.construct_yaml_omap(),
    except the data type is changed to OrderedDict() and setitem is
    used instead of append in the loop.
 
    >>> yaml.load('''
    ... !!omap
    ... - foo: bar
    ... - mumble: quux
    ... - baz: gorp
    ... ''')
    OrderedDict([('foo', 'bar'), ('mumble', 'quux'), ('baz', 'gorp')])
 
    >>> yaml.load('''!!omap [ foo: bar, mumble: quux, baz : gorp ]''')
    OrderedDict([('foo', 'bar'), ('mumble', 'quux'), ('baz', 'gorp')])
    """
 
    omap = OrderedDict()
    yield omap
    if not isinstance(node, yaml.SequenceNode):
        raise yaml.constructor.ConstructorError(
            "while constructing an ordered map",
            node.start_mark,
            "expected a sequence, but found %s" % node.id, node.start_mark
        )
    for subnode in node.value:
        if not isinstance(subnode, yaml.MappingNode):
            raise yaml.constructor.ConstructorError(
                "while constructing an ordered map", node.start_mark,
                "expected a mapping of length 1, but found %s" % subnode.id,
                subnode.start_mark
            )
        if len(subnode.value) != 1:
            raise yaml.constructor.ConstructorError(
                "while constructing an ordered map", node.start_mark,
                "expected a single mapping item, but found %d items" % len(subnode.value),
                subnode.start_mark
            )
        key_node, value_node = subnode.value[0]
        key = load.construct_object(key_node)
        value = load.construct_object(value_node)
        omap[key] = value 
開發者ID:airspy,項目名稱:airspyone_firmware,代碼行數:44,代碼來源:yaml_odict.py

示例11: _construct_odict

# 需要導入模塊: import yaml [as 別名]
# 或者: from yaml import SequenceNode [as 別名]
def _construct_odict(load, node):
    """
    Construct OrderedDict from !!omap in yaml safe load.

    Source: https://gist.github.com/weaver/317164
    License: Unspecified

    This is the same as SafeConstructor.construct_yaml_omap(),
    except the data type is changed to OrderedDict() and setitem is
    used instead of append in the loop

    Examples
    --------
    ::

      >>> yaml.load('''  # doctest: +SKIP
      ... !!omap
      ... - foo: bar
      ... - mumble: quux
      ... - baz: gorp
      ... ''')
      OrderedDict([('foo', 'bar'), ('mumble', 'quux'), ('baz', 'gorp')])

      >>> yaml.load('''!!omap [ foo: bar, mumble: quux, baz : gorp ]''')  # doctest: +SKIP
      OrderedDict([('foo', 'bar'), ('mumble', 'quux'), ('baz', 'gorp')])
    """
    import yaml

    omap = OrderedDict()
    yield omap
    if not isinstance(node, yaml.SequenceNode):
        raise yaml.constructor.ConstructorError(
            "while constructing an ordered map", node.start_mark,
            f"expected a sequence, but found {node.id}", node.start_mark)

    for subnode in node.value:
        if not isinstance(subnode, yaml.MappingNode):
            raise yaml.constructor.ConstructorError(
                "while constructing an ordered map", node.start_mark,
                f"expected a mapping of length 1, but found {subnode.id}",
                subnode.start_mark)

        if len(subnode.value) != 1:
            raise yaml.constructor.ConstructorError(
                "while constructing an ordered map", node.start_mark,
                "expected a single mapping item, but found {} items".format(len(subnode.value)),
                subnode.start_mark)

        key_node, value_node = subnode.value[0]
        key = load.construct_object(key_node)
        value = load.construct_object(value_node)
        omap[key] = value 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:54,代碼來源:meta.py


注:本文中的yaml.SequenceNode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。