本文整理汇总了Python中yaml.parser方法的典型用法代码示例。如果您正苦于以下问题:Python yaml.parser方法的具体用法?Python yaml.parser怎么用?Python yaml.parser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yaml
的用法示例。
在下文中一共展示了yaml.parser方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_parser
# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import parser [as 别名]
def create_parser() -> argparse.ArgumentParser:
"""Creates the top-level argument parser.
Returns:
argparse.ArgumentParser: Top-level argument parser.
"""
parser = argparse.ArgumentParser(prog="spectacles")
parser.add_argument("--version", action="version", version=__version__)
subparser_action = parser.add_subparsers(
title="Available sub-commands", dest="command"
)
base_subparser = _build_base_subparser()
_build_connect_subparser(subparser_action, base_subparser)
_build_sql_subparser(subparser_action, base_subparser)
_build_assert_subparser(subparser_action, base_subparser)
_build_content_subparser(subparser_action, base_subparser)
return parser
示例2: __call__
# 需要导入模块: import yaml [as 别名]
# 或者: from yaml import parser [as 别名]
def __call__(self, parser, namespace, values, option_string):
"""Populates argument defaults with values from the config file.
Args:
parser: Parent argparse parser that is calling the action.
namespace: Object where parsed values will be set.
values: Parsed values to be set to the namespace.
option_string: Argument string, e.g. "--optional".
"""
config = self.parse_config(path=values)
for dest, value in config.items():
for action in parser._actions:
if dest == action.dest:
"""Required actions that are fulfilled by config are no longer
required from the command line."""
action.required = False
# Override default if not previously set by an environment variable.
if not isinstance(action, EnvVarAction) or not os.environ.get(
action.env_var
):
setattr(namespace, dest, value)
break
else:
raise SpectaclesException(
name="invalid-config-file-param",
title="Invalid configuration file parameter.",
detail=f"Parameter '{dest}' in {values} is not valid.",
)
parser.set_defaults(**config)