python类representer()的实例源码

yaml_util.py 文件源码 项目:speech_ml 作者: coopie 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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
normalize_yaml.py 文件源码 项目:inspire-schemas 作者: inspirehep 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def change_style(style, representer):
    def new_representer(dumper, data):
        scalar = representer(dumper, data)
        scalar.style = style
        return scalar
    return new_representer
reporter.py 文件源码 项目:ooniprobe-debian 作者: TheTorProject 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
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)


问题


面经


文章

微信
公众号

扫码关注公众号