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


Python yaml.safe_dump方法代码示例

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


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

示例1: create_tmp_file_from_contents

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import safe_dump [as 别名]
def create_tmp_file_from_contents(rname, data, ftype='yaml'):
        ''' create a file in tmp with name and contents'''

        tmp = Utils.create_tmpfile(prefix=rname)

        if ftype == 'yaml':
            # AUDIT:no-member makes sense here due to ruamel.YAML/PyYAML usage
            # pylint: disable=no-member
            if hasattr(yaml, 'RoundTripDumper'):
                Utils._write(tmp, yaml.dump(data, Dumper=yaml.RoundTripDumper))
            else:
                Utils._write(tmp, yaml.safe_dump(data, default_flow_style=False))

        elif ftype == 'json':
            Utils._write(tmp, json.dumps(data))
        else:
            Utils._write(tmp, data)

        # Register cleanup when module is done
        atexit.register(Utils.cleanup, [tmp])
        return tmp 
开发者ID:RedHatOfficial,项目名称:ansible-redhat_openshift_utils,代码行数:23,代码来源:oc_obj.py

示例2: create

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import safe_dump [as 别名]
def create(self, files=None, content=None):
        '''
           Create a config

           NOTE: This creates the first file OR the first conent.
           TODO: Handle all files and content passed in
        '''
        if files:
            return self._create(files[0])

        # pylint: disable=no-member
        # The purpose of this change is twofold:
        # - we need a check to only use the ruamel specific dumper if ruamel is loaded
        # - the dumper or the flow style change is needed so openshift is able to parse
        # the resulting yaml, at least until gopkg.in/yaml.v2 is updated
        if hasattr(yaml, 'RoundTripDumper'):
            content['data'] = yaml.dump(content['data'], Dumper=yaml.RoundTripDumper)
        else:
            content['data'] = yaml.safe_dump(content['data'], default_flow_style=False)

        content_file = Utils.create_tmp_files_from_contents(content)[0]

        return self._create(content_file['path'])

    # pylint: disable=too-many-function-args 
开发者ID:RedHatOfficial,项目名称:ansible-redhat_openshift_utils,代码行数:27,代码来源:oc_obj.py

示例3: write

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import safe_dump [as 别名]
def write(self):
        ''' write to file '''
        if not self.filename:
            raise YeditException('Please specify a filename.')

        if self.backup and self.file_exists():
            shutil.copy(self.filename, '{}{}'.format(self.filename, self.backup_ext))

        # Try to set format attributes if supported
        try:
            self.yaml_dict.fa.set_block_style()
        except AttributeError:
            pass

        # Try to use RoundTripDumper if supported.
        if self.content_type == 'yaml':
            try:
                Yedit._write(self.filename, yaml.dump(self.yaml_dict, Dumper=yaml.RoundTripDumper))
            except AttributeError:
                Yedit._write(self.filename, yaml.safe_dump(self.yaml_dict, default_flow_style=False))
        elif self.content_type == 'json':
            Yedit._write(self.filename, json.dumps(self.yaml_dict, indent=4, sort_keys=True))
        else:
            raise YeditException('Unsupported content_type: {}.'.format(self.content_type) +
                                 'Please specify a content_type of yaml or json.')

        return (True, self.yaml_dict) 
开发者ID:RedHatOfficial,项目名称:ansible-redhat_openshift_utils,代码行数:29,代码来源:oc_obj.py

示例4: handleFile

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import safe_dump [as 别名]
def handleFile(self, f, *args, **kwargs):
            super().handleFile(f)
            if self.audio_file and self.audio_file.info and self.audio_file.tag:
                print(yaml.safe_dump(audioFileToJson(self.audio_file),
                                     indent=2, default_flow_style=False,
                                     explicit_start=True)) 
开发者ID:nicfit,项目名称:eyeD3,代码行数:8,代码来源:yamltag.py

示例5: dump_yaml

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import safe_dump [as 别名]
def dump_yaml(data, *path):
    def convert(obj):
        if isinstance(obj, dict):
            obj = {k: v for k, v in obj.items() if not k.startswith('_')}
            return {convert(k): convert(v) for k, v in obj.items()}
        if isinstance(obj, list):
            return [convert(x) for x in obj]
        if isinstance(obj, type):
            return obj.__name__
        return obj
    filename = os.path.join(*path)
    ensure_directory(os.path.dirname(filename))
    with open(filename, 'w') as file_:
        yaml.safe_dump(convert(data), file_, default_flow_style=False) 
开发者ID:danijar,项目名称:mindpark,代码行数:16,代码来源:other.py

示例6: _write_yaml

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import safe_dump [as 别名]
def _write_yaml(self, config_dict, dest):
        with io.open(dest, 'w', encoding='UTF-8') as f:
            yaml.safe_dump(config_dict, f, default_flow_style=False)

# Metadata gen 
开发者ID:googleapis,项目名称:artman,代码行数:7,代码来源:package_metadata_tasks.py

示例7: test_model_hot_reloading

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import safe_dump [as 别名]
def test_model_hot_reloading(app, rasa_default_train_data):
    query = "http://dummy-uri/parse?q=hello&project=my_keyword_model"
    response = yield app.get(query)
    assert response.code == 404, "Project should not exist yet"
    train_u = "http://dummy-uri/train?project=my_keyword_model"
    model_config = {"pipeline": "keyword", "data": rasa_default_train_data}
    model_str = yaml.safe_dump(model_config, default_flow_style=False,
                               allow_unicode=True)
    response = app.post(train_u,
                        headers={b"Content-Type": b"application/x-yml"},
                        data=model_str)
    time.sleep(3)
    app.flush()
    response = yield response
    assert response.code == 200, "Training should end successfully"

    response = app.post(train_u,
                        headers={b"Content-Type": b"application/json"},
                        data=json.dumps(model_config))
    time.sleep(3)
    app.flush()
    response = yield response
    assert response.code == 200, "Training should end successfully"

    response = yield app.get(query)
    assert response.code == 200, "Project should now exist after it got trained" 
开发者ID:weizhenzhao,项目名称:rasa_nlu,代码行数:28,代码来源:test_server.py

示例8: write_file_config

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import safe_dump [as 别名]
def write_file_config(file_config):
    with tempfile.NamedTemporaryFile("w+",
                                     suffix="_tmp_config_file.yml",
                                     delete=False) as f:
        f.write(yaml.safe_dump(file_config))
        f.flush()
        return f 
开发者ID:weizhenzhao,项目名称:rasa_nlu,代码行数:9,代码来源:utilities.py

示例9: write_file_config

# 需要导入模块: from ruamel import yaml [as 别名]
# 或者: from ruamel.yaml import safe_dump [as 别名]
def write_file_config(file_config):
    with tempfile.NamedTemporaryFile(
        "w+", suffix="_tmp_config_file.yml", delete=False
    ) as f:
        f.write(yaml.safe_dump(file_config))
        f.flush()
        return f 
开发者ID:botfront,项目名称:rasa-for-botfront,代码行数:9,代码来源:utilities.py


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