當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。