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


Python SafeRepresenter.add_representer方法代码示例

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


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

示例1: __write_state_file

# 需要导入模块: from yaml.representer import SafeRepresenter [as 别名]
# 或者: from yaml.representer.SafeRepresenter import add_representer [as 别名]
def __write_state_file(self, address, data_center, environment):
        host = parse_hostname(address)
        state_path = os.path.join(STATE_PATH, self.team, self.project, host)
        if not os.path.exists(state_path):
            os.makedirs(state_path)

        state_file = os.path.join(state_path, "{0}.yml".format(os.getpid()))
        if os.path.isfile(state_file):
            raise RuntimeError("Unable to run freight forwarder pid already in use.")
        else:
            # TODO: move to a yaml util
            def config_unicode_presenter(dumper, data):
                return dumper.represent_scalar('tag:yaml.org,2002:str', data)

            SafeRepresenter.add_representer(ConfigUnicode, config_unicode_presenter)

            with open(state_file, 'w') as f:
                f.write(
                    yaml.safe_dump(
                        {
                            "team": self.team,
                            "project": self.project,
                            "environment": environment,
                            "data_center": data_center,
                            "host": host,
                            "pid": os.getpid()
                        }
                    )
                ) 
开发者ID:TUNE-Archive,项目名称:freight_forwarder,代码行数:31,代码来源:freight_forwarder.py


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