本文整理匯總了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)