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