(self, action, arg_string)
| 2259 | return value |
| 2260 | |
| 2261 | def _get_value(self, action, arg_string): |
| 2262 | type_func = self._registry_get('type', action.type, action.type) |
| 2263 | if not _callable(type_func): |
| 2264 | msg = _('%r is not callable') |
| 2265 | raise ArgumentError(action, msg % type_func) |
| 2266 | |
| 2267 | # convert the value to the appropriate type |
| 2268 | try: |
| 2269 | result = type_func(arg_string) |
| 2270 | |
| 2271 | # ArgumentTypeErrors indicate errors |
| 2272 | except ArgumentTypeError: |
| 2273 | name = getattr(action.type, '__name__', repr(action.type)) |
| 2274 | msg = str(_sys.exc_info()[1]) |
| 2275 | raise ArgumentError(action, msg) |
| 2276 | |
| 2277 | # TypeErrors or ValueErrors also indicate errors |
| 2278 | except (TypeError, ValueError): |
| 2279 | name = getattr(action.type, '__name__', repr(action.type)) |
| 2280 | msg = _('invalid %s value: %r') |
| 2281 | raise ArgumentError(action, msg % (name, arg_string)) |
| 2282 | |
| 2283 | # return the converted value |
| 2284 | return result |
| 2285 | |
| 2286 | def _check_value(self, action, value): |
| 2287 | # converted value must be one of the choices (if specified) |
no test coverage detected