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

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

项目:speech_ml    作者:coopie    | 项目源码 | 文件源码
def change_style(style, representer):
    def new_representer(dumper, data):
        scalar = representer(dumper, data)
        scalar.style = style
        return scalar
    return new_representer


# represent_str does handle some corner cases, so use that
# instead of calling represent_scalar directly
项目:inspire-schemas    作者:inspirehep    | 项目源码 | 文件源码
def change_style(style, representer):
    def new_representer(dumper, data):
        scalar = representer(dumper, data)
        scalar.style = style
        return scalar
    return new_representer
项目:ooniprobe-debian    作者:TheTorProject    | 项目源码 | 文件源码
def represent_data(self, data):
        """
        This is very hackish. There is for sure a better way either by using
        the add_multi_representer or add_representer, the issue though lies in
        the fact that Scapy packets are metaclasses that leads to
        yaml.representer.get_classobj_bases to not be able to properly get the
        base of class of a Scapy packet.
        XXX fully debug this problem
        """
        if isinstance(data, Packet):
            data = createPacketReport(data)
        return SafeRepresenter.represent_data(self, data)