(self, action, arg_string)
| 2529 | return value |
| 2530 | |
| 2531 | def _get_value(self, action, arg_string): |
| 2532 | type_func = self._registry_get('type', action.type, action.type) |
| 2533 | if not callable(type_func): |
| 2534 | msg = _('%r is not callable') |
| 2535 | raise ArgumentError(action, msg % type_func) |
| 2536 | |
| 2537 | # convert the value to the appropriate type |
| 2538 | try: |
| 2539 | result = type_func(arg_string) |
| 2540 | |
| 2541 | # ArgumentTypeErrors indicate errors |
| 2542 | except ArgumentTypeError as err: |
| 2543 | name = getattr(action.type, '__name__', repr(action.type)) |
| 2544 | msg = str(err) |
| 2545 | raise ArgumentError(action, msg) |
| 2546 | |
| 2547 | # TypeErrors or ValueErrors also indicate errors |
| 2548 | except (TypeError, ValueError): |
| 2549 | name = getattr(action.type, '__name__', repr(action.type)) |
| 2550 | args = {'type': name, 'value': arg_string} |
| 2551 | msg = _('invalid %(type)s value: %(value)r') |
| 2552 | raise ArgumentError(action, msg % args) |
| 2553 | |
| 2554 | # return the converted value |
| 2555 | return result |
| 2556 | |
| 2557 | def _check_value(self, action, value): |
| 2558 | # converted value must be one of the choices (if specified) |
no test coverage detected