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


Python oyaml.safe_load方法代码示例

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


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

示例1: test__cli__command_parse_serialize_from_stdin

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import safe_load [as 别名]
def test__cli__command_parse_serialize_from_stdin(serialize):
    """Check that the parser serialized output option is working.

    Not going to test for the content of the output as that is subject to change.
    """
    result = invoke_assert_code(
        args=[parse, ('-', '--format', serialize)],
        cli_input='select * from tbl',
    )
    if serialize == 'json':
        result = json.loads(result.output)
    elif serialize == 'yaml':
        result = yaml.safe_load(result.output)
    else:
        raise Exception
    result = result[0]  # only one file
    assert result['filepath'] == 'stdin' 
开发者ID:alanmcruickshank,项目名称:sqlfluff,代码行数:19,代码来源:cli_commands_test.py

示例2: test__cli__command_lint_serialize_multiple_files

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import safe_load [as 别名]
def test__cli__command_lint_serialize_multiple_files(serialize):
    """Check the general format of JSON output for multiple files."""
    fpath = 'test/fixtures/linter/indentation_errors.sql'

    # note the file is in here twice. two files = two payloads.
    result = invoke_assert_code(
        args=[lint, (fpath, fpath, '--format', serialize)],
        ret_code=65,
    )

    if serialize == 'json':
        result = json.loads(result.output)
    elif serialize == 'yaml':
        result = yaml.safe_load(result.output)
    else:
        raise Exception
    assert len(result) == 2 
开发者ID:alanmcruickshank,项目名称:sqlfluff,代码行数:19,代码来源:cli_commands_test.py

示例3: raw_conf

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import safe_load [as 别名]
def raw_conf(mapchete_file):
    """
    Loads a mapchete_file into a dictionary.

    Parameters
    ----------
    mapchete_file : str
        Path to a Mapchete file.

    Returns
    -------
    dictionary
    """
    if isinstance(mapchete_file, dict):
        return _map_to_new_config(mapchete_file)
    else:
        return _map_to_new_config(yaml.safe_load(open(mapchete_file, "r").read())) 
开发者ID:ungarj,项目名称:mapchete,代码行数:19,代码来源:config.py

示例4: _config_to_dict

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import safe_load [as 别名]
def _config_to_dict(input_config):
    if isinstance(input_config, dict):
        if "config_dir" not in input_config:
            raise MapcheteConfigError("config_dir parameter missing")
        return OrderedDict(input_config, mapchete_file=None)
    # from Mapchete file
    elif os.path.splitext(input_config)[1] == ".mapchete":
        with open(input_config, "r") as config_file:
            return OrderedDict(
                yaml.safe_load(config_file.read()),
                config_dir=os.path.dirname(os.path.realpath(input_config)),
                mapchete_file=input_config
            )
    # throw error if unknown object
    else:
        raise MapcheteConfigError(
            "Configuration has to be a dictionary or a .mapchete file.") 
开发者ID:ungarj,项目名称:mapchete,代码行数:19,代码来源:config.py

示例5: test_validate_config_valid

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import safe_load [as 别名]
def test_validate_config_valid(mock_exit, mock_print, test_input, expected):
    with open("tests/data/test-config.yaml") as f:
        config = yaml.safe_load(f)
        returned_config = kafkashell.config.validate_config(config)

        assert not mock_print.called
        assert not mock_exit.called
        assert config == returned_config 
开发者ID:devshawn,项目名称:kafka-shell,代码行数:10,代码来源:test_config.py

示例6: read_yaml

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import safe_load [as 别名]
def read_yaml(self, filename, render_variables=False):
        return yaml.safe_load(self.read_file(filename, render_variables)) 
开发者ID:MaibornWolff,项目名称:dcos-deploy,代码行数:4,代码来源:reader.py

示例7: read_yaml

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import safe_load [as 别名]
def read_yaml(filename):
    with open(filename) as yaml_file:
        data = yaml_file.read()
    return yaml.safe_load(data) 
开发者ID:MaibornWolff,项目名称:dcos-deploy,代码行数:6,代码来源:file.py

示例8: _validate_recommended_data

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import safe_load [as 别名]
def _validate_recommended_data(data: OrderedDict) -> bool:
    """
    Ensure the returned data has the following structure:
    links:
      - name: Global Protect Skillets
        link: https://github.com/PaloAltoNetworks/GPSkillets
        branch: 90dev
        description: Configuration templates for GlobalProtect mobile users
    :param data: loaded object from oyaml.safe_load
    :return: boolean
    """

    if 'links' not in data:
        print('No links key in data')
        return False

    if type(data['links']) is not list:
        print('links is not a valid list!')
        return False

    for link in data['links']:
        if type(link) is not OrderedDict and type(link) is not dict:
            print('link entry is not a dict')
            return False

        if 'name' not in link or 'link' not in link or 'description' not in link:
            print('link entry does not have all required keys')
            return False

    return True 
开发者ID:PaloAltoNetworks,项目名称:panhandler,代码行数:32,代码来源:app_utils.py

示例9: get_config

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import safe_load [as 别名]
def get_config():
    config_file = get_user_config_path()

    with open(config_file) as f:
        return yaml.safe_load(f) 
开发者ID:devshawn,项目名称:kafka-shell,代码行数:7,代码来源:config.py

示例10: get_default_config

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import safe_load [as 别名]
def get_default_config():
    data_dir = os.path.dirname(os.path.realpath(__file__))
    data_path = os.path.join(data_dir, "data/shell-config.yaml")

    with open(data_path) as f:
        return yaml.safe_load(f) 
开发者ID:devshawn,项目名称:kafka-shell,代码行数:8,代码来源:config.py

示例11: test_validate_config_is_valid_with_environment_variables

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import safe_load [as 别名]
def test_validate_config_is_valid_with_environment_variables(mock_exit, mock_print, test_input, expected):
    with open("tests/data/test-environment-variables-config.yaml") as f:
        config = yaml.safe_load(f)
        returned_config = kafkashell.config.validate_config(config)

        assert not mock_print.called
        assert not mock_exit.called
        assert config == returned_config 
开发者ID:devshawn,项目名称:kafka-shell,代码行数:10,代码来源:test_config.py

示例12: setup_settings_with_real_completer_for_test

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import safe_load [as 别名]
def setup_settings_with_real_completer_for_test(mock_settings):
    with open("kafkashell/data/completer.json") as f:
        with open("kafkashell/data/shell-config.yaml") as fc:
            settings = mock_settings.return_value
            settings.selected_cluster = "local"
            settings.enable_help = True
            settings.enable_fuzzy_search = True
            settings.user_config = yaml.safe_load(fc)
            settings.commands = json.load(f)["commands"]
            return settings 
开发者ID:devshawn,项目名称:kafka-shell,代码行数:12,代码来源:utilities.py

示例13: get_test_config

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import safe_load [as 别名]
def get_test_config(config_name="test"):
    data_dir = os.path.dirname(os.path.realpath(__file__))
    data_path = os.path.realpath(os.path.join(data_dir, "../tests/data/{0}-config.yaml".format(config_name)))
    with open(data_path) as f:
        return yaml.safe_load(f) 
开发者ID:devshawn,项目名称:kafka-shell,代码行数:7,代码来源:utilities.py

示例14: load_yaml

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import safe_load [as 别名]
def load_yaml(fpath):
    """Load a yaml structure and process it into a tuple."""
    # Load raw file
    with open(fpath) as f:
        raw = f.read()
    # Parse the yaml
    obj = oyaml.safe_load(raw)
    # Return the parsed and structured object
    return process_struct(obj)[0] 
开发者ID:alanmcruickshank,项目名称:sqlfluff,代码行数:11,代码来源:conftest.py

示例15: test__cli__command_lint_serialize_from_stdin

# 需要导入模块: import oyaml [as 别名]
# 或者: from oyaml import safe_load [as 别名]
def test__cli__command_lint_serialize_from_stdin(serialize, sql, expected, exit_code):
    """Check an explicit serialized return value for a single error."""
    result = invoke_assert_code(
        args=[lint, ('-', '--rules', 'L010', '--format', serialize)],
        cli_input=sql,
        ret_code=exit_code
    )

    if serialize == 'json':
        assert json.loads(result.output) == expected
    elif serialize == 'yaml':
        assert yaml.safe_load(result.output) == expected
    else:
        raise Exception 
开发者ID:alanmcruickshank,项目名称:sqlfluff,代码行数:16,代码来源:cli_commands_test.py


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