Python yaml 模块,CSafeDumper() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用yaml.CSafeDumper()

项目:docker-etude    作者:globality-corp    | 项目源码 | 文件源码
def to_yaml(self):
        """
        Pretty print dump as YAML.

        """
        return dump(
            self.to_safe_dict(),
            # show every document in its own block
            default_flow_style=False,
            # start a new document (via "---") before every resource
            explicit_start=True,
            # follow (modern) PEP8 max line length and indent
            width=99,
            indent=4,
            Dumper=SafeDumper,
        )
项目:awesome-ancient-chinese-books    作者:bhuztez    | 项目源码 | 文件源码
def dump(data, stream=None):
    class Dumper(yaml.CSafeDumper):
        pass

    def representer(dumper, data):
        return dumper.represent_dict(data.iteritems())

    Dumper.add_representer(OrderedDict, representer)

    return yaml.dump(data, stream, Dumper=Dumper, encoding='utf-8', default_flow_style=False, allow_unicode=True)