def _match_argument(self, action, arg_strings_pattern): # - https://github.com/streamlink/streamlink/issues/971 # - https://bugs.python.org/issue9334 # match the pattern for this action to the arg strings nargs_pattern = self._get_nargs_pattern(action) match = argparse._re.match(nargs_pattern, arg_strings_pattern) # if no match, see if we can emulate optparse and return the # required number of arguments regardless of their values if match is None: nargs = action.nargs if action.nargs is not None else 1 if isinstance(nargs, numbers.Number) and len(arg_strings_pattern) >= nargs: return nargs # raise an exception if we weren't able to find a match if match is None: nargs_errors = { None: argparse._('expected one argument'), argparse.OPTIONAL: argparse._('expected at most one argument'), argparse.ONE_OR_MORE: argparse._('expected at least one argument'), } default = argparse.ngettext('expected %s argument', 'expected %s arguments', action.nargs) % action.nargs msg = nargs_errors.get(action.nargs, default) raise argparse.ArgumentError(action, msg) # return the number of arguments matched return len(match.group(1))
def update_event(self, inp=-1): self.set_output_val( 0, argparse.ngettext(self.input(0), self.input(1), self.input(2)))