本文整理汇总了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'
示例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
示例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()))
示例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.")
示例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
示例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))
示例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)
示例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
示例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)
示例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)
示例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
示例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
示例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)
示例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]
示例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