python类Action()的实例源码

test_lib.py 文件源码 项目:VPP_P4 作者: RuchaMarathe 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def do_table_set_default(self, line):
        "Set default action for a match table: table_set_default <table name> <action name> <action parameters>"
        args = line.split()

        self.at_least_n_args(args, 2)

        table_name, action_name = args[0], args[1]

        table = self.get_res("table", table_name, TABLES)
        if action_name not in table.actions:
            raise UIn_Error(
                "Table %s has no action %s" % (table_name, action_name)
            )
        action = ACTIONS[action_name]
        if len(args[2:]) != action.num_params():
            raise UIn_Error(
                "Action %s needs %d parameters" % (action_name, action.num_params())
            )

        runtime_data = parse_runtime_data(action, args[2:])

        self.print_set_default(table_name, action_name, runtime_data)

        self.client.bm_mt_set_default_action(0, table_name, action_name, runtime_data)
test_lib.py 文件源码 项目:VPP_P4 作者: RuchaMarathe 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def do_act_prof_create_member(self, line):
        "Add a member to an action profile: act_prof_create_member <action profile name> <action_name> [action parameters]"
        args = line.split()

        self.at_least_n_args(args, 2)

        act_prof_name, action_name = args[0], args[1]
        act_prof = self.get_res("action profile", act_prof_name, ACTION_PROFS)

        if action_name not in act_prof.actions:
            raise UIn_Error("Action profile '{}' has no action '{}'".format(
                act_prof_name, action_name))
        action = ACTIONS[action_name]

        action_params = args[2:]
        runtime_data = self.parse_runtime_data(action, action_params)

        mbr_handle = self.client.bm_mt_act_prof_add_member(
            0, act_prof_name, action_name, runtime_data)

        print "Member has been created with handle", mbr_handle
pytestplugin.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def pytest_addoption(parser):
    group = parser.getgroup("sqlalchemy")

    def make_option(name, **kw):
        callback_ = kw.pop("callback", None)
        if callback_:
            class CallableAction(argparse.Action):
                def __call__(self, parser, namespace,
                             values, option_string=None):
                    callback_(option_string, values, parser)
            kw["action"] = CallableAction

        group.addoption(name, **kw)

    plugin_base.setup_options(make_option)
    plugin_base.read_config()
pytestplugin.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def pytest_addoption(parser):
    group = parser.getgroup("sqlalchemy")

    def make_option(name, **kw):
        callback_ = kw.pop("callback", None)
        if callback_:
            class CallableAction(argparse.Action):
                def __call__(self, parser, namespace,
                             values, option_string=None):
                    callback_(option_string, values, parser)
            kw["action"] = CallableAction

        group.addoption(name, **kw)

    plugin_base.setup_options(make_option)
    plugin_base.read_config()
arg_parsing.py 文件源码 项目:aws-encryption-sdk-cli 作者: awslabs 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __call__(
            self,
            parser,  # type: argparse.ArgumentParser
            namespace,  # type: argparse.Namespace
            values,  # type: Union[ARGPARSE_TEXT, Sequence[Any], None]
            option_string=None  # type: Optional[ARGPARSE_TEXT]
    ):
        # type: (...) -> None
        """Checks to make sure that the destination is empty before writing.

        :raises parser.error: if destination is already set
        """
        if getattr(namespace, self.dest) is not None:  # type: ignore # typeshed doesn't know about Action.dest yet?
            parser.error('{} argument may not be specified more than once'.format(option_string))
            return
        setattr(namespace, self.dest, values)  # type: ignore # typeshed doesn't know about Action.dest yet?
pytestplugin.py 文件源码 项目:QXSConsolas 作者: qxsch 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def pytest_addoption(parser):
    group = parser.getgroup("sqlalchemy")

    def make_option(name, **kw):
        callback_ = kw.pop("callback", None)
        if callback_:
            class CallableAction(argparse.Action):
                def __call__(self, parser, namespace,
                             values, option_string=None):
                    callback_(option_string, values, parser)
            kw["action"] = CallableAction

        group.addoption(name, **kw)

    plugin_base.setup_options(make_option)
    plugin_base.read_config()
pytestplugin.py 文件源码 项目:flasky 作者: RoseOu 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def pytest_addoption(parser):
    group = parser.getgroup("sqlalchemy")

    def make_option(name, **kw):
        callback_ = kw.pop("callback", None)
        if callback_:
            class CallableAction(argparse.Action):
                def __call__(self, parser, namespace,
                             values, option_string=None):
                    callback_(option_string, values, parser)
            kw["action"] = CallableAction

        group.addoption(name, **kw)

    plugin_base.setup_options(make_option)
    plugin_base.read_config()
parser.py 文件源码 项目:pipper 作者: sernst 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def required_length(minimum: int, maximum: int, optional: bool = False):
    """Returns a custom required length class"""

    class RequiredLength(argparse.Action):
        def __call__(self, parser, args, values, option_string=None):
            is_allowed = (
                (minimum <= len(values) <= maximum) or
                (optional and not len(values))
            )

            if  is_allowed:
                setattr(args, self.dest, values)
                return

            raise argparse.ArgumentTypeError(
                'Argument "{}" must have {}-{} arguments'.format(
                    self.dest,
                    minimum,
                    maximum
                )
            )

    return RequiredLength
cli_list_entrypoint.py 文件源码 项目:slicer_cli_web 作者: girder 项目源码 文件源码 阅读 44 收藏 0 点赞 0 评论 0
def _make_print_cli_list_spec_action(cli_list_spec_file):

    with open(cli_list_spec_file) as f:
        str_cli_list_spec = f.read()

    class _PrintCLIListSpecAction(argparse.Action):

        def __init__(self,
                     option_strings,
                     dest=argparse.SUPPRESS,
                     default=argparse.SUPPRESS,
                     help=None):
            super(_PrintCLIListSpecAction, self).__init__(
                option_strings=option_strings,
                dest=dest,
                default=default,
                nargs=0,
                help=help)

        def __call__(self, parser, namespace, values, option_string=None):
            print str_cli_list_spec
            parser.exit()

    return _PrintCLIListSpecAction
pytestplugin.py 文件源码 项目:oa_qian 作者: sunqb 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def pytest_addoption(parser):
    group = parser.getgroup("sqlalchemy")

    def make_option(name, **kw):
        callback_ = kw.pop("callback", None)
        if callback_:
            class CallableAction(argparse.Action):
                def __call__(self, parser, namespace,
                             values, option_string=None):
                    callback_(option_string, values, parser)
            kw["action"] = CallableAction

        group.addoption(name, **kw)

    plugin_base.setup_options(make_option)
    plugin_base.read_config()
runtime_CLI.py 文件源码 项目:P4-network-slices-A 作者: Emil-501 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def do_table_set_default(self, line):
        "Set default action for a match table: table_set_default <table name> <action name> <action parameters>"
        args = line.split()

        self.at_least_n_args(args, 2)

        table_name, action_name = args[0], args[1]

        table = self.get_res("table", table_name, TABLES)
        if action_name not in table.actions:
            raise UIn_Error(
                "Table %s has no action %s" % (table_name, action_name)
            )
        action = ACTIONS[action_name]
        if len(args[2:]) != action.num_params():
            raise UIn_Error(
                "Action %s needs %d parameters" % (action_name, action.num_params())
            )

        runtime_data = parse_runtime_data(action, args[2:])

        self.print_set_default(table_name, action_name, runtime_data)

        self.client.bm_mt_set_default_action(0, table_name, action_name, runtime_data)
runtime_CLI.py 文件源码 项目:P4-network-slices-A 作者: Emil-501 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def do_act_prof_create_member(self, line):
        "Add a member to an action profile: act_prof_create_member <action profile name> <action_name> [action parameters]"
        args = line.split()

        self.at_least_n_args(args, 2)

        act_prof_name, action_name = args[0], args[1]
        act_prof = self.get_res("action profile", act_prof_name, ACTION_PROFS)

        if action_name not in act_prof.actions:
            raise UIn_Error("Action profile '{}' has no action '{}'".format(
                act_prof_name, action_name))
        action = ACTIONS[action_name]

        action_params = args[2:]
        runtime_data = self.parse_runtime_data(action, action_params)

        mbr_handle = self.client.bm_mt_act_prof_add_member(
            0, act_prof_name, action_name, runtime_data)

        print "Member has been created with handle", mbr_handle
runtime_CLI.py 文件源码 项目:P4-network-slices-A 作者: Emil-501 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def do_table_set_default(self, line):
        "Set default action for a match table: table_set_default <table name> <action name> <action parameters>"
        args = line.split()

        self.at_least_n_args(args, 2)

        table_name, action_name = args[0], args[1]

        table = self.get_res("table", table_name, TABLES)
        if action_name not in table.actions:
            raise UIn_Error(
                "Table %s has no action %s" % (table_name, action_name)
            )
        action = ACTIONS[action_name]
        if len(args[2:]) != action.num_params():
            raise UIn_Error(
                "Action %s needs %d parameters" % (action_name, action.num_params())
            )

        runtime_data = parse_runtime_data(action, args[2:])

        self.print_set_default(table_name, action_name, runtime_data)

        self.client.bm_mt_set_default_action(0, table_name, action_name, runtime_data)
runtime_CLI.py 文件源码 项目:P4-network-slices-A 作者: Emil-501 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def do_act_prof_create_member(self, line):
        "Add a member to an action profile: act_prof_create_member <action profile name> <action_name> [action parameters]"
        args = line.split()

        self.at_least_n_args(args, 2)

        act_prof_name, action_name = args[0], args[1]
        act_prof = self.get_res("action profile", act_prof_name, ACTION_PROFS)

        if action_name not in act_prof.actions:
            raise UIn_Error("Action profile '{}' has no action '{}'".format(
                act_prof_name, action_name))
        action = ACTIONS[action_name]

        action_params = args[2:]
        runtime_data = self.parse_runtime_data(action, action_params)

        mbr_handle = self.client.bm_mt_act_prof_add_member(
            0, act_prof_name, action_name, runtime_data)

        print "Member has been created with handle", mbr_handle
runtime_CLI.py 文件源码 项目:P4-network-slices-A 作者: Emil-501 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def do_table_set_default(self, line):
        "Set default action for a match table: table_set_default <table name> <action name> <action parameters>"
        args = line.split()

        self.at_least_n_args(args, 2)

        table_name, action_name = args[0], args[1]

        table = self.get_res("table", table_name, TABLES)
        if action_name not in table.actions:
            raise UIn_Error(
                "Table %s has no action %s" % (table_name, action_name)
            )
        action = ACTIONS[action_name]
        if len(args[2:]) != action.num_params():
            raise UIn_Error(
                "Action %s needs %d parameters" % (action_name, action.num_params())
            )

        runtime_data = parse_runtime_data(action, args[2:])

        self.print_set_default(table_name, action_name, runtime_data)

        self.client.bm_mt_set_default_action(0, table_name, action_name, runtime_data)
runtime_CLI.py 文件源码 项目:P4-network-slices-A 作者: Emil-501 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def do_act_prof_create_member(self, line):
        "Add a member to an action profile: act_prof_create_member <action profile name> <action_name> [action parameters]"
        args = line.split()

        self.at_least_n_args(args, 2)

        act_prof_name, action_name = args[0], args[1]
        act_prof = self.get_res("action profile", act_prof_name, ACTION_PROFS)

        if action_name not in act_prof.actions:
            raise UIn_Error("Action profile '{}' has no action '{}'".format(
                act_prof_name, action_name))
        action = ACTIONS[action_name]

        action_params = args[2:]
        runtime_data = self.parse_runtime_data(action, action_params)

        mbr_handle = self.client.bm_mt_act_prof_add_member(
            0, act_prof_name, action_name, runtime_data)

        print "Member has been created with handle", mbr_handle
runtime_CLI.py 文件源码 项目:P4-network-slices-A 作者: Emil-501 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def do_table_set_default(self, line):
        "Set default action for a match table: table_set_default <table name> <action name> <action parameters>"
        args = line.split()

        self.at_least_n_args(args, 2)

        table_name, action_name = args[0], args[1]

        table = self.get_res("table", table_name, TABLES)
        if action_name not in table.actions:
            raise UIn_Error(
                "Table %s has no action %s" % (table_name, action_name)
            )
        action = ACTIONS[action_name]
        if len(args[2:]) != action.num_params():
            raise UIn_Error(
                "Action %s needs %d parameters" % (action_name, action.num_params())
            )

        runtime_data = parse_runtime_data(action, args[2:])

        self.print_set_default(table_name, action_name, runtime_data)

        self.client.bm_mt_set_default_action(0, table_name, action_name, runtime_data)
runtime_CLI.py 文件源码 项目:P4-network-slices-A 作者: Emil-501 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def do_act_prof_create_member(self, line):
        "Add a member to an action profile: act_prof_create_member <action profile name> <action_name> [action parameters]"
        args = line.split()

        self.at_least_n_args(args, 2)

        act_prof_name, action_name = args[0], args[1]
        act_prof = self.get_res("action profile", act_prof_name, ACTION_PROFS)

        if action_name not in act_prof.actions:
            raise UIn_Error("Action profile '{}' has no action '{}'".format(
                act_prof_name, action_name))
        action = ACTIONS[action_name]

        action_params = args[2:]
        runtime_data = self.parse_runtime_data(action, action_params)

        mbr_handle = self.client.bm_mt_act_prof_add_member(
            0, act_prof_name, action_name, runtime_data)

        print "Member has been created with handle", mbr_handle
runtime_CLI.py 文件源码 项目:P4-network-slices-A 作者: Emil-501 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def do_table_set_default(self, line):
        "Set default action for a match table: table_set_default <table name> <action name> <action parameters>"
        args = line.split()

        self.at_least_n_args(args, 2)

        table_name, action_name = args[0], args[1]

        table = self.get_res("table", table_name, TABLES)
        if action_name not in table.actions:
            raise UIn_Error(
                "Table %s has no action %s" % (table_name, action_name)
            )
        action = ACTIONS[action_name]
        if len(args[2:]) != action.num_params():
            raise UIn_Error(
                "Action %s needs %d parameters" % (action_name, action.num_params())
            )

        runtime_data = parse_runtime_data(action, args[2:])

        self.print_set_default(table_name, action_name, runtime_data)

        self.client.bm_mt_set_default_action(0, table_name, action_name, runtime_data)
runtime_CLI.py 文件源码 项目:P4-network-slices-A 作者: Emil-501 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def do_act_prof_create_member(self, line):
        "Add a member to an action profile: act_prof_create_member <action profile name> <action_name> [action parameters]"
        args = line.split()

        self.at_least_n_args(args, 2)

        act_prof_name, action_name = args[0], args[1]
        act_prof = self.get_res("action profile", act_prof_name, ACTION_PROFS)

        if action_name not in act_prof.actions:
            raise UIn_Error("Action profile '{}' has no action '{}'".format(
                act_prof_name, action_name))
        action = ACTIONS[action_name]

        action_params = args[2:]
        runtime_data = self.parse_runtime_data(action, action_params)

        mbr_handle = self.client.bm_mt_act_prof_add_member(
            0, act_prof_name, action_name, runtime_data)

        print "Member has been created with handle", mbr_handle
shell_utils.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def get_argparse_extension_checker(choices, dir_allowed=False):
    """Get an :class:`argparge.Action` class that can check for correct extensions.

    Returns:
        argparse.Action: a class (not an instance) of an argparse action.
    """

    class Act(argparse.Action):
        def __call__(self, parser, namespace, fname, option_string=None):
            is_valid = any(map(lambda choice: fname[-len(choice):] == choice, choices))

            if not is_valid and dir_allowed and os.path.isdir(fname):
                is_valid = True

            if is_valid:
                setattr(namespace, self.dest, fname)
            else:
                option_string = '({})'.format(option_string) if option_string else ''
                parser.error("File doesn't end with one of {}{}".format(choices, option_string))

    return Act
test_argparse.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test(self):

        def get_my_type(string):
            return 'my_type{%s}' % string

        parser = argparse.ArgumentParser()
        parser.register('type', 'my_type', get_my_type)
        parser.add_argument('-x', type='my_type')
        parser.add_argument('y', type='my_type')

        self.assertEqual(parser.parse_args('1'.split()),
                         NS(x=None, y='my_type{1}'))
        self.assertEqual(parser.parse_args('-x 1 42'.split()),
                         NS(x='my_type{1}', y='my_type{42}'))


# ============
# Action tests
# ============
pytestplugin.py 文件源码 项目:chihu 作者: yelongyu 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def pytest_addoption(parser):
    group = parser.getgroup("sqlalchemy")

    def make_option(name, **kw):
        callback_ = kw.pop("callback", None)
        if callback_:
            class CallableAction(argparse.Action):
                def __call__(self, parser, namespace,
                             values, option_string=None):
                    callback_(option_string, values, parser)
            kw["action"] = CallableAction

        group.addoption(name, **kw)

    plugin_base.setup_options(make_option)
    plugin_base.read_config()
pytestplugin.py 文件源码 项目:chihu 作者: yelongyu 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def pytest_addoption(parser):
    group = parser.getgroup("sqlalchemy")

    def make_option(name, **kw):
        callback_ = kw.pop("callback", None)
        if callback_:
            class CallableAction(argparse.Action):
                def __call__(self, parser, namespace,
                             values, option_string=None):
                    callback_(option_string, values, parser)
            kw["action"] = CallableAction

        group.addoption(name, **kw)

    plugin_base.setup_options(make_option)
    plugin_base.read_config()
pytestplugin.py 文件源码 项目:ShelbySearch 作者: Agentscreech 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def pytest_addoption(parser):
    group = parser.getgroup("sqlalchemy")

    def make_option(name, **kw):
        callback_ = kw.pop("callback", None)
        if callback_:
            class CallableAction(argparse.Action):
                def __call__(self, parser, namespace,
                             values, option_string=None):
                    callback_(option_string, values, parser)
            kw["action"] = CallableAction

        group.addoption(name, **kw)

    plugin_base.setup_options(make_option)
    plugin_base.read_config()
pytestplugin.py 文件源码 项目:ShelbySearch 作者: Agentscreech 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def pytest_addoption(parser):
    group = parser.getgroup("sqlalchemy")

    def make_option(name, **kw):
        callback_ = kw.pop("callback", None)
        if callback_:
            class CallableAction(argparse.Action):
                def __call__(self, parser, namespace,
                             values, option_string=None):
                    callback_(option_string, values, parser)
            kw["action"] = CallableAction

        group.addoption(name, **kw)

    plugin_base.setup_options(make_option)
    plugin_base.read_config()
util.py 文件源码 项目:certbot 作者: nikoloskii 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def add_deprecated_argument(add_argument, argument_name, nargs):
    """Adds a deprecated argument with the name argument_name.

    Deprecated arguments are not shown in the help. If they are used on
    the command line, a warning is shown stating that the argument is
    deprecated and no other action is taken.

    :param callable add_argument: Function that adds arguments to an
        argument parser/group.
    :param str argument_name: Name of deprecated argument.
    :param nargs: Value for nargs when adding the argument to argparse.

    """
    class ShowWarning(argparse.Action):
        """Action to log a warning when an argument is used."""
        def __call__(self, unused1, unused2, unused3, option_string=None):
            sys.stderr.write(
                "Use of {0} is deprecated.\n".format(option_string))

    configargparse.ACTION_TYPES_THAT_DONT_NEED_A_VALUE.add(ShowWarning)
    add_argument(argument_name, action=ShowWarning,
                 help=argparse.SUPPRESS, nargs=nargs)
pytestplugin.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def pytest_addoption(parser):
    group = parser.getgroup("sqlalchemy")

    def make_option(name, **kw):
        callback_ = kw.pop("callback", None)
        if callback_:
            class CallableAction(argparse.Action):
                def __call__(self, parser, namespace,
                             values, option_string=None):
                    callback_(option_string, values, parser)
            kw["action"] = CallableAction

        group.addoption(name, **kw)

    plugin_base.setup_options(make_option)
    plugin_base.read_config()
pytestplugin.py 文件源码 项目:Price-Comparator 作者: Thejas-1 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def pytest_addoption(parser):
    group = parser.getgroup("sqlalchemy")

    def make_option(name, **kw):
        callback_ = kw.pop("callback", None)
        if callback_:
            class CallableAction(argparse.Action):
                def __call__(self, parser, namespace,
                             values, option_string=None):
                    callback_(option_string, values, parser)
            kw["action"] = CallableAction

        group.addoption(name, **kw)

    plugin_base.setup_options(make_option)
    plugin_base.read_config()
test_argparse.py 文件源码 项目:oil 作者: oilshell 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test(self):

        def get_my_type(string):
            return 'my_type{%s}' % string

        parser = argparse.ArgumentParser()
        parser.register('type', 'my_type', get_my_type)
        parser.add_argument('-x', type='my_type')
        parser.add_argument('y', type='my_type')

        self.assertEqual(parser.parse_args('1'.split()),
                         NS(x=None, y='my_type{1}'))
        self.assertEqual(parser.parse_args('-x 1 42'.split()),
                         NS(x='my_type{1}', y='my_type{42}'))


# ============
# Action tests
# ============


问题


面经


文章

微信
公众号

扫码关注公众号