(self, action, arg_strings)
| 2473 | # Value conversion methods |
| 2474 | # ======================== |
| 2475 | def _get_values(self, action, arg_strings): |
| 2476 | # for everything but PARSER, REMAINDER args, strip out first '--' |
| 2477 | if not action.option_strings and action.nargs not in [PARSER, REMAINDER]: |
| 2478 | try: |
| 2479 | arg_strings.remove('--') |
| 2480 | except ValueError: |
| 2481 | pass |
| 2482 | |
| 2483 | # optional argument produces a default when not present |
| 2484 | if not arg_strings and action.nargs == OPTIONAL: |
| 2485 | if action.option_strings: |
| 2486 | value = action.const |
| 2487 | else: |
| 2488 | value = action.default |
| 2489 | if isinstance(value, str): |
| 2490 | value = self._get_value(action, value) |
| 2491 | self._check_value(action, value) |
| 2492 | |
| 2493 | # when nargs='*' on a positional, if there were no command-line |
| 2494 | # args, use the default if it is anything other than None |
| 2495 | elif (not arg_strings and action.nargs == ZERO_OR_MORE and |
| 2496 | not action.option_strings): |
| 2497 | if action.default is not None: |
| 2498 | value = action.default |
| 2499 | else: |
| 2500 | value = arg_strings |
| 2501 | self._check_value(action, value) |
| 2502 | |
| 2503 | # single argument or optional argument produces a single value |
| 2504 | elif len(arg_strings) == 1 and action.nargs in [None, OPTIONAL]: |
| 2505 | arg_string, = arg_strings |
| 2506 | value = self._get_value(action, arg_string) |
| 2507 | self._check_value(action, value) |
| 2508 | |
| 2509 | # REMAINDER arguments convert all values, checking none |
| 2510 | elif action.nargs == REMAINDER: |
| 2511 | value = [self._get_value(action, v) for v in arg_strings] |
| 2512 | |
| 2513 | # PARSER arguments convert all values, but check only the first |
| 2514 | elif action.nargs == PARSER: |
| 2515 | value = [self._get_value(action, v) for v in arg_strings] |
| 2516 | self._check_value(action, value[0]) |
| 2517 | |
| 2518 | # SUPPRESS argument does not put anything in the namespace |
| 2519 | elif action.nargs == SUPPRESS: |
| 2520 | value = SUPPRESS |
| 2521 | |
| 2522 | # all other types of nargs produce a list |
| 2523 | else: |
| 2524 | value = [self._get_value(action, v) for v in arg_strings] |
| 2525 | for v in value: |
| 2526 | self._check_value(action, v) |
| 2527 | |
| 2528 | # return the converted value |
| 2529 | return value |
| 2530 | |
| 2531 | def _get_value(self, action, arg_string): |
| 2532 | type_func = self._registry_get('type', action.type, action.type) |
no test coverage detected