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


Python comments.CommentedSeq方法代码示例

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


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

示例1: reorder

# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedSeq [as 别名]
def reorder(data, strict=True):
        if type(data) is CommentedMap:
            order = ComposeFormat.order_map(list(data.keys()))
            keys = list(data.keys())

            while ComposeFormat.sorted_by_order(keys, order, strict) != keys:
                for a, b in zip(ComposeFormat.sorted_by_order(keys, order, strict), keys):
                    if a == b:
                        continue
                    data.move_to_end(b)
                    break
                keys = list(data.keys())
            for key, item in data.items():
                if key in ComposeFormat.NON_SORTABLE_ARRAYS:
                    continue
                ComposeFormat.reorder(item, strict)
            return data
        if type(data) is CommentedSeq:
            for i, value in enumerate(data):
                if type(value) is not CommentedMap:
                    data[i] = ComposeFormat.fix_sexadecimal_numbers(value)
            data.sort()
            return data
        return data 
开发者ID:funkwerk,项目名称:compose_format,代码行数:26,代码来源:__init__.py

示例2: is_list

# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedSeq [as 别名]
def is_list(obj):
    """
    Check if object is a list or the ruamel.yaml equivalent of a list
    """
    return isinstance(obj, (list, CommentedSeq)) 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:7,代码来源:operator.py

示例3: set_related_images

# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedSeq [as 别名]
def set_related_images(self):
        """
        Find pullspecs in predefined locations and put all of them in the
        .spec.relatedImages section (if it already exists, clear it first)
        """
        named_pullspecs = self._named_pullspecs()

        by_name = OrderedDict()
        conflicts = []

        for new in named_pullspecs:
            # Keep track only of the first instance with a given name.
            # Ideally, existing relatedImages should come first in the list,
            # otherwise error messages could be confusing.
            old = by_name.setdefault(new.name, new)
            # Check for potential conflict (same name, different image)
            if new.image != old.image:
                msg = ("{old.description}: {old.image} X {new.description}: {new.image}"
                       .format(old=old, new=new))
                conflicts.append(msg)

        if conflicts:
            raise RuntimeError("{} - Found conflicts when setting relatedImages:\n{}"
                               .format(self.path, "\n".join(conflicts)))

        related_images = (self.data.setdefault("spec", CommentedMap())
                                   .setdefault("relatedImages", CommentedSeq()))
        del related_images[:]

        for p in by_name.values():
            log.debug("%s - Set relatedImage %s (from %s): %s",
                      self.path, p.name, p.description, p.image)
            related_images.append(p.as_yaml_object()) 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:35,代码来源:operator.py

示例4: delete_all_annotations

# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedSeq [as 别名]
def delete_all_annotations(obj):
    if isinstance(obj, (dict, CommentedMap)):
        obj.get("metadata", {}).pop("annotations", None)
        for v in obj.values():
            delete_all_annotations(v)
    elif isinstance(obj, (list, CommentedSeq)):
        for item in obj:
            delete_all_annotations(item) 
开发者ID:containerbuildsystem,项目名称:atomic-reactor,代码行数:10,代码来源:test_operator.py

示例5: test_anchor_on_sequence

# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedSeq [as 别名]
def test_anchor_on_sequence(self):
        # as reported by Bjorn Stabell
        # https://bitbucket.org/ruamel/yaml/issue/7/anchor-names-not-preserved
        from ruamel.yaml.comments import CommentedSeq
        data = load("""
        nut1: &alice
         - 1
         - 2
        nut2: &blake
         - some data
         - *alice
        nut3:
         - *blake
         - *alice
        """)
        l = data['nut1']
        assert isinstance(l, CommentedSeq)
        assert l.yaml_anchor() is not None
        assert l.yaml_anchor().value == 'alice' 
开发者ID:naparuba,项目名称:opsbro,代码行数:21,代码来源:test_anchor.py

示例6: test_before_top_seq_from_scratch

# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedSeq [as 别名]
def test_before_top_seq_from_scratch(self):
        from ruamel.yaml.comments import CommentedSeq
        data = CommentedSeq()
        data.append('a')
        data.append('b')
        data.yaml_set_start_comment('Hello\nWorld\n')
        print(round_trip_dump(data))
        compare(data, """
        {comment} Hello
        {comment} World
        - a
        - b
        """.format(comment='#'))

    # nested variants 
开发者ID:naparuba,项目名称:opsbro,代码行数:17,代码来源:test_comment_manipulation.py

示例7: test_before_nested_seq_from_scratch

# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedSeq [as 别名]
def test_before_nested_seq_from_scratch(self):
        from ruamel.yaml.comments import CommentedMap, CommentedSeq
        data = CommentedMap()
        datab = CommentedSeq()
        data['a'] = 1
        data['b'] = datab
        datab.append('c')
        datab.append('d')
        data['b'].yaml_set_start_comment('Hello\nWorld\n', indent=2)
        compare(data, """
        a: 1
        b:
          {comment} Hello
          {comment} World
          - c
          - d
        """.format(comment='#')) 
开发者ID:naparuba,项目名称:opsbro,代码行数:19,代码来源:test_comment_manipulation.py

示例8: to_yaml

# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedSeq [as 别名]
def to_yaml(self, data):
        self._should_be_list(data)
        return CommentedSeq([self._validator.to_yaml(item) for item in data]) 
开发者ID:crdoconnor,项目名称:strictyaml,代码行数:5,代码来源:compound.py

示例9: data

# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedSeq [as 别名]
def data(self):
        """
        Returns raw data representation of the document or document segment.

        Mappings are rendered as ordered dicts, sequences as lists and scalar values
        as whatever the validator returns (int, string, etc.).

        If no validators are used, scalar values are always returned as strings.
        """
        if isinstance(self._value, CommentedMap):
            mapping = OrderedDict()
            for key, value in self._value.items():
                """
                #if isinstance(key, YAML):
                    #mapping[key.data] = value.data if isinstance(value, YAML) else value
                """
                mapping[key.data] = value.data
            return mapping
        elif isinstance(self._value, CommentedSeq):
            return [item.data for item in self._value]
        else:
            return self._value 
开发者ID:crdoconnor,项目名称:strictyaml,代码行数:24,代码来源:representation.py

示例10: as_marked_up

# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedSeq [as 别名]
def as_marked_up(self):
        """
        Returns ruamel.yaml CommentedSeq/CommentedMap objects
        with comments. This can be fed directly into a ruamel.yaml
        dumper.
        """
        return self._chunk.contents 
开发者ID:crdoconnor,项目名称:strictyaml,代码行数:9,代码来源:representation.py

示例11: text

# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedSeq [as 别名]
def text(self):
        """
        Return string value of scalar, whatever value it was parsed as.
        """
        if isinstance(self._value, CommentedMap):
            raise TypeError("{0} is a mapping, has no text value.".format(repr(self)))
        if isinstance(self._value, CommentedSeq):
            raise TypeError("{0} is a sequence, has no text value.".format(repr(self)))
        return self._text 
开发者ID:crdoconnor,项目名称:strictyaml,代码行数:11,代码来源:representation.py

示例12: __gt__

# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedSeq [as 别名]
def __gt__(self, val):
        if isinstance(self._value, CommentedMap) or isinstance(
            self._value, CommentedSeq
        ):
            raise TypeError("{0} not an orderable type.".format(repr(self._value)))
        return self._value > val 
开发者ID:crdoconnor,项目名称:strictyaml,代码行数:8,代码来源:representation.py

示例13: __lt__

# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedSeq [as 别名]
def __lt__(self, val):
        if isinstance(self._value, CommentedMap) or isinstance(
            self._value, CommentedSeq
        ):
            raise TypeError("{0} not an orderable type.".format(repr(self._value)))
        return self._value < val 
开发者ID:crdoconnor,项目名称:strictyaml,代码行数:8,代码来源:representation.py

示例14: is_sequence

# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedSeq [as 别名]
def is_sequence(self):
        return isinstance(self._value, CommentedSeq) 
开发者ID:crdoconnor,项目名称:strictyaml,代码行数:4,代码来源:representation.py

示例15: scalar

# 需要导入模块: from ruamel.yaml import comments [as 别名]
# 或者: from ruamel.yaml.comments import CommentedSeq [as 别名]
def scalar(self):
        if isinstance(self._value, (CommentedMap, CommentedSeq)):
            raise TypeError("{0} has no scalar value.".format(repr(self)))
        return self._value 
开发者ID:crdoconnor,项目名称:strictyaml,代码行数:6,代码来源:representation.py


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