我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用yaml.CSafeDumper()。
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, )
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)