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