本文整理汇总了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()
}
)
)