Merge lp:~barry/argparse/11ubuntu into lp:ubuntu/lucid/argparse
- 11ubuntu
- Merge into lucid
Proposed by
Barry Warsaw
Status: | Merged | ||||
---|---|---|---|---|---|
Merge reported by: | Gediminas Paulauskas | ||||
Merged at revision: | not available | ||||
Proposed branch: | lp:~barry/argparse/11ubuntu | ||||
Merge into: | lp:ubuntu/lucid/argparse | ||||
Diff against target: |
1906 lines (+594/-185) 23 files modified
NEWS.txt (+16/-0) PKG-INFO (+1/-1) README.txt (+2/-2) argparse.py (+121/-38) debian/changelog (+12/-0) doc/ArgumentParser.html (+10/-28) doc/add_argument.html (+17/-7) doc/api-docs.html (+6/-6) doc/argparse-vs-optparse.html (+5/-5) doc/genindex.html (+20/-6) doc/index.html (+5/-5) doc/other-methods.html (+36/-5) doc/other-utilities.html (+5/-5) doc/overview.html (+5/-5) doc/parse_args.html (+5/-5) doc/search.html (+5/-5) doc/searchindex.js (+1/-1) doc/source/ArgumentParser.rst (+5/-24) doc/source/add_argument.rst (+11/-2) doc/source/conf.py (+2/-2) doc/source/other-methods.rst (+24/-0) setup.py (+5/-3) test/test_argparse.py (+275/-30) |
||||
To merge this branch: | bzr merge lp:~barry/argparse/11ubuntu | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ritesh Raj Sarraf | Pending | ||
Barry Warsaw | Pending | ||
Review via email:
|
Commit message
Description of the change
Updates argparse to upstream version 1.1
To post a comment you must log in.
lp:~barry/argparse/11ubuntu
updated
- 8. By Barry Warsaw
-
New upstream release (LP: #537484)
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Ritesh Raj Sarraf (rrs) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'NEWS.txt' |
2 | --- NEWS.txt 2009-10-12 18:04:37 +0000 |
3 | +++ NEWS.txt 2010-03-11 19:12:27 +0000 |
4 | @@ -1,3 +1,19 @@ |
5 | +What's New in argparse 1.1 |
6 | +========================== |
7 | + |
8 | +- Issue #22: Support more customization of version arguments. |
9 | +- Issue #34: Allow better custom type error messages using ArgumentTypeError. |
10 | +- Issue #36: Get "from argparse import *" working. |
11 | +- Issue #37: Stop treating two character alphanumeric flags as numbers. |
12 | +- Issue #38: Better error messages when 'dest' occurs twice for positional arguments. |
13 | +- Issue #39: Better error messages for invalid actions. |
14 | +- Issue #43: Deprecate ArgumentParser(..., version=XXX, ...) and friends. |
15 | +- Issue #46: Allow single character options, e.g. '-' and '+'. |
16 | +- Issue #51: Better error messages for errors like type='int'. |
17 | +- Namespace objects now support "in" (i.e. __contains__). |
18 | +- Usage and help (but not version) messages are written to stdout, not stderr. |
19 | + |
20 | + |
21 | What's New in argparse 1.0.1 |
22 | ============================ |
23 | |
24 | |
25 | === modified file 'PKG-INFO' |
26 | --- PKG-INFO 2009-10-12 18:04:37 +0000 |
27 | +++ PKG-INFO 2010-03-11 19:12:27 +0000 |
28 | @@ -1,6 +1,6 @@ |
29 | Metadata-Version: 1.0 |
30 | Name: argparse |
31 | -Version: 1.0.1 |
32 | +Version: 1.1 |
33 | Summary: Python command-line parsing library |
34 | Home-page: http://code.google.com/p/argparse/ |
35 | Author: Steven Bethard |
36 | |
37 | === modified file 'README.txt' |
38 | --- README.txt 2009-10-12 18:04:37 +0000 |
39 | +++ README.txt 2010-03-11 19:12:27 +0000 |
40 | @@ -1,5 +1,5 @@ |
41 | -argparse 1.0.1 |
42 | -============== |
43 | +argparse 1.1 |
44 | +============ |
45 | The argparse module provides an easy, declarative interface for |
46 | creating command line tools, which knows how to: |
47 | |
48 | |
49 | === modified file 'argparse.py' |
50 | --- argparse.py 2009-10-12 18:04:37 +0000 |
51 | +++ argparse.py 2010-03-11 19:12:27 +0000 |
52 | @@ -75,7 +75,7 @@ |
53 | still considered an implementation detail.) |
54 | """ |
55 | |
56 | -__version__ = '1.0.1' |
57 | +__version__ = '1.1' |
58 | __all__ = [ |
59 | 'ArgumentParser', |
60 | 'ArgumentError', |
61 | @@ -84,7 +84,7 @@ |
62 | 'FileType', |
63 | 'HelpFormatter', |
64 | 'RawDescriptionHelpFormatter', |
65 | - 'RawTextHelpFormatter' |
66 | + 'RawTextHelpFormatter', |
67 | 'ArgumentDefaultsHelpFormatter', |
68 | ] |
69 | |
70 | @@ -118,6 +118,10 @@ |
71 | result.reverse() |
72 | return result |
73 | |
74 | + |
75 | +def _callable(obj): |
76 | + return hasattr(obj, '__call__') or hasattr(obj, '__bases__') |
77 | + |
78 | # silence Python 2.6 buggy warnings about Exception.message |
79 | if _sys.version_info[:2] == (2, 6): |
80 | import warnings |
81 | @@ -133,7 +137,8 @@ |
82 | OPTIONAL = '?' |
83 | ZERO_OR_MORE = '*' |
84 | ONE_OR_MORE = '+' |
85 | -PARSER = '==PARSER==' |
86 | +PARSER = 'A...' |
87 | +REMAINDER = '...' |
88 | |
89 | # ============================= |
90 | # Utility functions and classes |
91 | @@ -500,6 +505,8 @@ |
92 | return text |
93 | |
94 | def _format_text(self, text): |
95 | + if '%(prog)' in text: |
96 | + text = text % dict(prog=self._prog) |
97 | text_width = self._width - self._current_indent |
98 | indent = ' ' * self._current_indent |
99 | return self._fill_text(text, text_width, indent) + '\n\n' |
100 | @@ -600,7 +607,9 @@ |
101 | result = '[%s [%s ...]]' % get_metavar(2) |
102 | elif action.nargs == ONE_OR_MORE: |
103 | result = '%s [%s ...]' % get_metavar(2) |
104 | - elif action.nargs is PARSER: |
105 | + elif action.nargs == REMAINDER: |
106 | + result = '...' |
107 | + elif action.nargs == PARSER: |
108 | result = '%s ...' % get_metavar(1) |
109 | else: |
110 | formats = ['%s' for _ in range(action.nargs)] |
111 | @@ -612,6 +621,9 @@ |
112 | for name in list(params): |
113 | if params[name] is SUPPRESS: |
114 | del params[name] |
115 | + for name in list(params): |
116 | + if hasattr(params[name], '__name__'): |
117 | + params[name] = params[name].__name__ |
118 | if params.get('choices') is not None: |
119 | choices_str = ', '.join([str(c) for c in params['choices']]) |
120 | params['choices'] = choices_str |
121 | @@ -716,6 +728,12 @@ |
122 | return format % dict(message=self.message, |
123 | argument_name=self.argument_name) |
124 | |
125 | + |
126 | +class ArgumentTypeError(Exception): |
127 | + """An error from trying to convert a command line string to a type.""" |
128 | + pass |
129 | + |
130 | + |
131 | # ============== |
132 | # Action classes |
133 | # ============== |
134 | @@ -1010,6 +1028,7 @@ |
135 | |
136 | def __init__(self, |
137 | option_strings, |
138 | + version=None, |
139 | dest=SUPPRESS, |
140 | default=SUPPRESS, |
141 | help=None): |
142 | @@ -1019,10 +1038,15 @@ |
143 | default=default, |
144 | nargs=0, |
145 | help=help) |
146 | + self.version = version |
147 | |
148 | def __call__(self, parser, namespace, values, option_string=None): |
149 | - parser.print_version() |
150 | - parser.exit() |
151 | + version = self.version |
152 | + if version is None: |
153 | + version = parser.version |
154 | + formatter = parser._get_formatter() |
155 | + formatter.add_text(version) |
156 | + parser.exit(message=formatter.format_help()) |
157 | |
158 | |
159 | class _SubParsersAction(Action): |
160 | @@ -1157,6 +1181,9 @@ |
161 | def __ne__(self, other): |
162 | return not (self == other) |
163 | |
164 | + def __contains__(self, key): |
165 | + return key in self.__dict__ |
166 | + |
167 | |
168 | class _ActionsContainer(object): |
169 | |
170 | @@ -1203,7 +1230,7 @@ |
171 | self._defaults = {} |
172 | |
173 | # determines whether an "option" looks like a negative number |
174 | - self._negative_number_matcher = _re.compile(r'^-\d+|-\d*.\d+$') |
175 | + self._negative_number_matcher = _re.compile(r'^-\d+$|^-\d*\.\d+$') |
176 | |
177 | # whether or not there are any optionals that look like negative |
178 | # numbers -- uses a list so it can be shared and edited |
179 | @@ -1220,7 +1247,7 @@ |
180 | return self._registries[registry_name].get(value, default) |
181 | |
182 | # ================================== |
183 | - # Namespace default settings methods |
184 | + # Namespace default accessor methods |
185 | # ================================== |
186 | def set_defaults(self, **kwargs): |
187 | self._defaults.update(kwargs) |
188 | @@ -1231,6 +1258,13 @@ |
189 | if action.dest in kwargs: |
190 | action.default = kwargs[action.dest] |
191 | |
192 | + def get_default(self, dest): |
193 | + for action in self._actions: |
194 | + if action.dest == dest and action.default is not None: |
195 | + return action.default |
196 | + return self._defaults.get(dest, None) |
197 | + |
198 | + |
199 | # ======================= |
200 | # Adding argument actions |
201 | # ======================= |
202 | @@ -1245,6 +1279,8 @@ |
203 | # argument |
204 | chars = self.prefix_chars |
205 | if not args or len(args) == 1 and args[0][0] not in chars: |
206 | + if args and 'dest' in kwargs: |
207 | + raise ValueError('dest supplied twice for positional argument') |
208 | kwargs = self._get_positional_kwargs(*args, **kwargs) |
209 | |
210 | # otherwise, we're adding an optional argument |
211 | @@ -1261,7 +1297,15 @@ |
212 | |
213 | # create the action object, and add it to the parser |
214 | action_class = self._pop_action_class(kwargs) |
215 | + if not _callable(action_class): |
216 | + raise ValueError('unknown action "%s"' % action_class) |
217 | action = action_class(**kwargs) |
218 | + |
219 | + # raise an error if the action type is not callable |
220 | + type_func = self._registry_get('type', action.type, action.type) |
221 | + if not _callable(type_func): |
222 | + raise ValueError('%r is not callable' % type_func) |
223 | + |
224 | return self._add_action(action) |
225 | |
226 | def add_argument_group(self, *args, **kwargs): |
227 | @@ -1359,12 +1403,6 @@ |
228 | option_strings = [] |
229 | long_option_strings = [] |
230 | for option_string in args: |
231 | - # error on one-or-fewer-character option strings |
232 | - if len(option_string) < 2: |
233 | - msg = _('invalid option string %r: ' |
234 | - 'must be at least two characters long') |
235 | - raise ValueError(msg % option_string) |
236 | - |
237 | # error on strings that don't start with an appropriate prefix |
238 | if not option_string[0] in self.prefix_chars: |
239 | msg = _('invalid option string %r: ' |
240 | @@ -1372,18 +1410,12 @@ |
241 | tup = option_string, self.prefix_chars |
242 | raise ValueError(msg % tup) |
243 | |
244 | - # error on strings that are all prefix characters |
245 | - if not (_set(option_string) - _set(self.prefix_chars)): |
246 | - msg = _('invalid option string %r: ' |
247 | - 'must contain characters other than %r') |
248 | - tup = option_string, self.prefix_chars |
249 | - raise ValueError(msg % tup) |
250 | - |
251 | # strings starting with two prefix characters are long options |
252 | option_strings.append(option_string) |
253 | if option_string[0] in self.prefix_chars: |
254 | - if option_string[1] in self.prefix_chars: |
255 | - long_option_strings.append(option_string) |
256 | + if len(option_string) > 1: |
257 | + if option_string[1] in self.prefix_chars: |
258 | + long_option_strings.append(option_string) |
259 | |
260 | # infer destination, '--foo-bar' -> 'foo_bar' and '-x' -> 'x' |
261 | dest = kwargs.pop('dest', None) |
262 | @@ -1393,6 +1425,9 @@ |
263 | else: |
264 | dest_option_string = option_strings[0] |
265 | dest = dest_option_string.lstrip(self.prefix_chars) |
266 | + if not dest: |
267 | + msg = _('dest= is required for options like %r') |
268 | + raise ValueError(msg % option_string) |
269 | dest = dest.replace('-', '_') |
270 | |
271 | # return the updated keyword arguments |
272 | @@ -1508,7 +1543,6 @@ |
273 | - usage -- A usage message (default: auto-generated from arguments) |
274 | - description -- A description of what the program does |
275 | - epilog -- Text following the argument descriptions |
276 | - - version -- Add a -v/--version option with the given version string |
277 | - parents -- Parsers whose arguments should be copied into this one |
278 | - formatter_class -- HelpFormatter class for printing help messages |
279 | - prefix_chars -- Characters that prefix optional arguments |
280 | @@ -1533,6 +1567,14 @@ |
281 | conflict_handler='error', |
282 | add_help=True): |
283 | |
284 | + if version is not None: |
285 | + import warnings |
286 | + warnings.warn( |
287 | + """The "version" argument to ArgumentParser is deprecated. """ |
288 | + """Please use """ |
289 | + """"add_argument(..., action='version', version="N", ...)" """ |
290 | + """instead""", DeprecationWarning) |
291 | + |
292 | superinit = super(ArgumentParser, self).__init__ |
293 | superinit(description=description, |
294 | prefix_chars=prefix_chars, |
295 | @@ -1570,6 +1612,7 @@ |
296 | if self.version: |
297 | self.add_argument( |
298 | '-v', '--version', action='version', default=SUPPRESS, |
299 | + version=self.version, |
300 | help=_("show program's version number and exit")) |
301 | |
302 | # add parent arguments and defaults |
303 | @@ -1938,7 +1981,10 @@ |
304 | try: |
305 | args_file = open(arg_string[1:]) |
306 | try: |
307 | - arg_strings = args_file.read().splitlines() |
308 | + arg_strings = [] |
309 | + for arg_line in args_file.read().splitlines(): |
310 | + for arg in self.convert_arg_line_to_args(arg_line): |
311 | + arg_strings.append(arg) |
312 | arg_strings = self._read_args_from_files(arg_strings) |
313 | new_arg_strings.extend(arg_strings) |
314 | finally: |
315 | @@ -1950,6 +1996,9 @@ |
316 | # return the modified argument list |
317 | return new_arg_strings |
318 | |
319 | + def convert_arg_line_to_args(self, arg_line): |
320 | + return [arg_line] |
321 | + |
322 | def _match_argument(self, action, arg_strings_pattern): |
323 | # match the pattern for this action to the arg strings |
324 | nargs_pattern = self._get_nargs_pattern(action) |
325 | @@ -1994,15 +2043,22 @@ |
326 | if not arg_string[0] in self.prefix_chars: |
327 | return None |
328 | |
329 | - # if it's just dashes, it was meant to be positional |
330 | - if not arg_string.strip('-'): |
331 | - return None |
332 | - |
333 | # if the option string is present in the parser, return the action |
334 | if arg_string in self._option_string_actions: |
335 | action = self._option_string_actions[arg_string] |
336 | return action, arg_string, None |
337 | |
338 | + # if it's just a single character, it was meant to be positional |
339 | + if len(arg_string) == 1: |
340 | + return None |
341 | + |
342 | + # if the option string before the "=" is present, return the action |
343 | + if '=' in arg_string: |
344 | + option_string, explicit_arg = arg_string.split('=', 1) |
345 | + if option_string in self._option_string_actions: |
346 | + action = self._option_string_actions[option_string] |
347 | + return action, option_string, explicit_arg |
348 | + |
349 | # search through all possible prefixes of the option string |
350 | # and all actions in the parser for possible interpretations |
351 | option_tuples = self._get_option_tuples(arg_string) |
352 | @@ -2100,8 +2156,12 @@ |
353 | elif nargs == ONE_OR_MORE: |
354 | nargs_pattern = '(-*A[A-]*)' |
355 | |
356 | + # allow any number of options or arguments |
357 | + elif nargs == REMAINDER: |
358 | + nargs_pattern = '([-AO]*)' |
359 | + |
360 | # allow one argument followed by any number of options or arguments |
361 | - elif nargs is PARSER: |
362 | + elif nargs == PARSER: |
363 | nargs_pattern = '(-*A[-AO]*)' |
364 | |
365 | # all others should be integers |
366 | @@ -2121,7 +2181,7 @@ |
367 | # ======================== |
368 | def _get_values(self, action, arg_strings): |
369 | # for everything but PARSER args, strip out '--' |
370 | - if action.nargs is not PARSER: |
371 | + if action.nargs not in [PARSER, REMAINDER]: |
372 | arg_strings = [s for s in arg_strings if s != '--'] |
373 | |
374 | # optional argument produces a default when not present |
375 | @@ -2150,8 +2210,12 @@ |
376 | value = self._get_value(action, arg_string) |
377 | self._check_value(action, value) |
378 | |
379 | + # REMAINDER arguments convert all values, checking none |
380 | + elif action.nargs == REMAINDER: |
381 | + value = [self._get_value(action, v) for v in arg_strings] |
382 | + |
383 | # PARSER arguments convert all values, but check only the first |
384 | - elif action.nargs is PARSER: |
385 | + elif action.nargs == PARSER: |
386 | value = [self._get_value(action, v) for v in arg_strings] |
387 | self._check_value(action, value[0]) |
388 | |
389 | @@ -2166,16 +2230,21 @@ |
390 | |
391 | def _get_value(self, action, arg_string): |
392 | type_func = self._registry_get('type', action.type, action.type) |
393 | - if not hasattr(type_func, '__call__'): |
394 | - if not hasattr(type_func, '__bases__'): # classic classes |
395 | - msg = _('%r is not callable') |
396 | - raise ArgumentError(action, msg % type_func) |
397 | + if not _callable(type_func): |
398 | + msg = _('%r is not callable') |
399 | + raise ArgumentError(action, msg % type_func) |
400 | |
401 | # convert the value to the appropriate type |
402 | try: |
403 | result = type_func(arg_string) |
404 | |
405 | - # TypeErrors or ValueErrors indicate errors |
406 | + # ArgumentTypeErrors indicate errors |
407 | + except ArgumentTypeError: |
408 | + name = getattr(action.type, '__name__', repr(action.type)) |
409 | + msg = str(_sys.exc_info()[1]) |
410 | + raise ArgumentError(action, msg) |
411 | + |
412 | + # TypeErrors or ValueErrors also indicate errors |
413 | except (TypeError, ValueError): |
414 | name = getattr(action.type, '__name__', repr(action.type)) |
415 | msg = _('invalid %s value: %r') |
416 | @@ -2224,6 +2293,11 @@ |
417 | return formatter.format_help() |
418 | |
419 | def format_version(self): |
420 | + import warnings |
421 | + warnings.warn( |
422 | + 'The format_version method is deprecated -- the "version" ' |
423 | + 'argument to ArgumentParser is no longer supported.', |
424 | + DeprecationWarning) |
425 | formatter = self._get_formatter() |
426 | formatter.add_text(self.version) |
427 | return formatter.format_help() |
428 | @@ -2235,12 +2309,21 @@ |
429 | # Help-printing methods |
430 | # ===================== |
431 | def print_usage(self, file=None): |
432 | + if file is None: |
433 | + file = _sys.stdout |
434 | self._print_message(self.format_usage(), file) |
435 | |
436 | def print_help(self, file=None): |
437 | + if file is None: |
438 | + file = _sys.stdout |
439 | self._print_message(self.format_help(), file) |
440 | |
441 | def print_version(self, file=None): |
442 | + import warnings |
443 | + warnings.warn( |
444 | + 'The print_version method is deprecated -- the "version" ' |
445 | + 'argument to ArgumentParser is no longer supported.', |
446 | + DeprecationWarning) |
447 | self._print_message(self.format_version(), file) |
448 | |
449 | def _print_message(self, message, file=None): |
450 | @@ -2254,7 +2337,7 @@ |
451 | # =============== |
452 | def exit(self, status=0, message=None): |
453 | if message: |
454 | - _sys.stderr.write(message) |
455 | + self._print_message(message, _sys.stderr) |
456 | _sys.exit(status) |
457 | |
458 | def error(self, message): |
459 | |
460 | === modified file 'debian/changelog' |
461 | --- debian/changelog 2009-10-12 18:04:37 +0000 |
462 | +++ debian/changelog 2010-03-11 19:12:27 +0000 |
463 | @@ -1,3 +1,15 @@ |
464 | +argparse (1.1-1ubuntu1) lucid; urgency=low |
465 | + |
466 | + * New upstream release (LP: #537484) |
467 | + |
468 | + -- Barry Warsaw <barry@canonical.com> Thu, 11 Mar 2010 14:09:13 -0500 |
469 | + |
470 | +argparse (1.1-1) lucid; urgency=low |
471 | + |
472 | + * New upstream release. |
473 | + |
474 | + -- Barry Warsaw <barry@canonical.com> Thu, 11 Mar 2010 11:59:54 -0500 |
475 | + |
476 | argparse (1.0.1-1) unstable; urgency=low |
477 | |
478 | * New upstream bugfix release |
479 | |
480 | === modified file 'doc/ArgumentParser.html' |
481 | --- doc/ArgumentParser.html 2009-10-12 18:04:37 +0000 |
482 | +++ doc/ArgumentParser.html 2010-03-11 19:12:27 +0000 |
483 | @@ -5,13 +5,13 @@ |
484 | <head> |
485 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
486 | |
487 | - <title>ArgumentParser objects — argparse v1.0.1 documentation</title> |
488 | + <title>ArgumentParser objects — argparse v1.1 documentation</title> |
489 | <link rel="stylesheet" href="_static/default.css" type="text/css" /> |
490 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
491 | <script type="text/javascript"> |
492 | var DOCUMENTATION_OPTIONS = { |
493 | URL_ROOT: '', |
494 | - VERSION: '1.0.1', |
495 | + VERSION: '1.1', |
496 | COLLAPSE_MODINDEX: false, |
497 | FILE_SUFFIX: '.html', |
498 | HAS_SOURCE: true |
499 | @@ -19,7 +19,7 @@ |
500 | </script> |
501 | <script type="text/javascript" src="_static/jquery.js"></script> |
502 | <script type="text/javascript" src="_static/doctools.js"></script> |
503 | - <link rel="top" title="argparse v1.0.1 documentation" href="index.html" /> |
504 | + <link rel="top" title="argparse v1.1 documentation" href="index.html" /> |
505 | <link rel="up" title="API documentation" href="api-docs.html" /> |
506 | <link rel="next" title="The add_argument() method" href="add_argument.html" /> |
507 | <link rel="prev" title="API documentation" href="api-docs.html" /> |
508 | @@ -37,7 +37,7 @@ |
509 | <li class="right" > |
510 | <a href="api-docs.html" title="API documentation" |
511 | accesskey="P">previous</a> |</li> |
512 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
513 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
514 | <li><a href="api-docs.html" accesskey="U">API documentation</a> »</li> |
515 | </ul> |
516 | </div> |
517 | @@ -52,12 +52,11 @@ |
518 | <dl class="class"> |
519 | <dt id="ArgumentParser"> |
520 | <em class="property"> |
521 | -class </em><tt class="descname">ArgumentParser</tt><big>(</big><span class="optional">[</span><em>description</em><span class="optional">]</span><span class="optional">[</span>, <em>epilog</em><span class="optional">]</span><span class="optional">[</span>, <em>prog</em><span class="optional">]</span><span class="optional">[</span>, <em>usage</em><span class="optional">]</span><span class="optional">[</span>, <em>version</em><span class="optional">]</span><span class="optional">[</span>, <em>add_help</em><span class="optional">]</span><span class="optional">[</span>, <em>argument_default</em><span class="optional">]</span><span class="optional">[</span>, <em>parents</em><span class="optional">]</span><span class="optional">[</span>, <em>prefix_chars</em><span class="optional">]</span><span class="optional">[</span>, <em>conflict_handler</em><span class="optional">]</span><span class="optional">[</span>, <em>formatter_class</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#ArgumentParser" title="Permalink to this definition">¶</a></dt> |
522 | -<dd><p>Create a new :class:ArgumentParser object. Each parameter has its own more detailed description below, but in short they are:</p> |
523 | +class </em><tt class="descname">ArgumentParser</tt><big>(</big><span class="optional">[</span><em>description</em><span class="optional">]</span><span class="optional">[</span>, <em>epilog</em><span class="optional">]</span><span class="optional">[</span>, <em>prog</em><span class="optional">]</span><span class="optional">[</span>, <em>usage</em><span class="optional">]</span><span class="optional">[</span>, <em>add_help</em><span class="optional">]</span><span class="optional">[</span>, <em>argument_default</em><span class="optional">]</span><span class="optional">[</span>, <em>parents</em><span class="optional">]</span><span class="optional">[</span>, <em>prefix_chars</em><span class="optional">]</span><span class="optional">[</span>, <em>conflict_handler</em><span class="optional">]</span><span class="optional">[</span>, <em>formatter_class</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#ArgumentParser" title="Permalink to this definition">¶</a></dt> |
524 | +<dd><p>Create a new <a title="ArgumentParser" class="reference internal" href="#ArgumentParser"><tt class="xref docutils literal"><span class="pre">ArgumentParser</span></tt></a> object. Each parameter has its own more detailed description below, but in short they are:</p> |
525 | <ul class="simple"> |
526 | <li><a class="reference internal" href="#description">description</a> - Text to display before the argument help.</li> |
527 | <li><a class="reference internal" href="#epilog">epilog</a> - Text to display after the argument help.</li> |
528 | -<li><a class="reference internal" href="#version">version</a> - A version number used to add a -v/–version option to the parser.</li> |
529 | <li><a class="reference internal" href="#add-help">add_help</a> - Add a -h/–help option to the parser. (default: True)</li> |
530 | <li><a class="reference internal" href="#argument-default">argument_default</a> - Set the global default value for arguments. (default: None)</li> |
531 | <li><a class="reference internal" href="#parents">parents</a> - A list of :class:ArgumentParser objects whose arguments should also be included.</li> |
532 | @@ -105,22 +104,6 @@ |
533 | </div> |
534 | <p>As with the <a class="reference internal" href="#description">description</a> argument, the <tt class="docutils literal"><span class="pre">epilog=</span></tt> text is by default line-wrapped, but this behavior can be adjusted with the <a class="reference internal" href="#formatter-class">formatter_class</a> argument to ArgumentParser.</p> |
535 | </div> |
536 | -<div class="section" id="version"> |
537 | -<h2>version<a class="headerlink" href="#version" title="Permalink to this headline">¶</a></h2> |
538 | -<p>Programs which want to display the program version at the command line can supply a version message as the <tt class="docutils literal"><span class="pre">version=</span></tt> argument to ArgumentParser. This will add a <tt class="docutils literal"><span class="pre">-v/--version</span></tt> option to the ArgumentParser that can be invoked to print the version string:</p> |
539 | -<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">prog</span><span class="o">=</span><span class="s">'PROG'</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="s">'</span><span class="si">%(prog)s</span><span class="s"> 3.5'</span><span class="p">)</span> |
540 | -<span class="gp">>>> </span><span class="n">parser</span><span class="o">.</span><span class="n">print_help</span><span class="p">()</span> |
541 | -<span class="go">usage: PROG [-h] [-v]</span> |
542 | - |
543 | -<span class="go">optional arguments:</span> |
544 | -<span class="go"> -h, --help show this help message and exit</span> |
545 | -<span class="go"> -v, --version show program's version number and exit</span> |
546 | -<span class="gp">>>> </span><span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">([</span><span class="s">'-v'</span><span class="p">])</span> |
547 | -<span class="go">PROG 3.5</span> |
548 | -</pre></div> |
549 | -</div> |
550 | -<p>Note you can use the <tt class="docutils literal"><span class="pre">%(prog)s</span></tt> format specifier to insert the program name into the version string.</p> |
551 | -</div> |
552 | <div class="section" id="add-help"> |
553 | <h2>add_help<a class="headerlink" href="#add-help" title="Permalink to this headline">¶</a></h2> |
554 | <p>By default, ArgumentParser objects add a <tt class="docutils literal"><span class="pre">-h/--help</span></tt> option which simply displays the parser’s help message. For example, consider a file named <tt class="docutils literal"><span class="pre">myprogram.py</span></tt> containing the following code:</p> |
555 | @@ -159,8 +142,7 @@ |
556 | <span class="go">Namespace(bar='Y', f='X')</span> |
557 | </pre></div> |
558 | </div> |
559 | -<p>The <tt class="docutils literal"><span class="pre">prefix_chars=</span></tt> argument defaults to <tt class="docutils literal"><span class="pre">'-'</span></tt>. Supplying a set of characters that does not include <tt class="docutils literal"><span class="pre">'-'</span></tt> will cause <tt class="docutils literal"><span class="pre">-f/--foo</span></tt> options to be disallowed. |
560 | -Note that most parent parsers will specify <tt class="xref docutils literal"><span class="pre">add_help()</span></tt> <tt class="docutils literal"><span class="pre">=False</span></tt>. Otherwise, the ArgumentParser will see two <tt class="docutils literal"><span class="pre">-h/--help</span></tt> options (one in the parent and one in the child) and raise an error.</p> |
561 | +<p>The <tt class="docutils literal"><span class="pre">prefix_chars=</span></tt> argument defaults to <tt class="docutils literal"><span class="pre">'-'</span></tt>. Supplying a set of characters that does not include <tt class="docutils literal"><span class="pre">'-'</span></tt> will cause <tt class="docutils literal"><span class="pre">-f/--foo</span></tt> options to be disallowed.</p> |
562 | </div> |
563 | <div class="section" id="fromfile-prefix-chars"> |
564 | <h2>fromfile_prefix_chars<a class="headerlink" href="#fromfile-prefix-chars" title="Permalink to this headline">¶</a></h2> |
565 | @@ -173,7 +155,7 @@ |
566 | <span class="go">Namespace(f='bar')</span> |
567 | </pre></div> |
568 | </div> |
569 | -<p>Arguments read from a file must be one per line (with each whole line being considered a single argument) and are treated as if they were in the same place as the original file referencing argument on the command line. |
570 | +<p>Arguments read from a file must by default be one per line (but see also <a title="convert_arg_line_to_args" class="reference external" href="other-methods.html#convert_arg_line_to_args"><tt class="xref docutils literal"><span class="pre">convert_arg_line_to_args()</span></tt></a>) and are treated as if they were in the same place as the original file referencing argument on the command line. |
571 | So in the example above, the expression <tt class="docutils literal"><span class="pre">['-f',</span> <span class="pre">'foo',</span> <span class="pre">'@args.txt']</span></tt> is considered equivalent to the expression <tt class="docutils literal"><span class="pre">['-f',</span> <span class="pre">'foo',</span> <span class="pre">'-f',</span> <span class="pre">'bar']</span></tt>.</p> |
572 | <p>The <tt class="docutils literal"><span class="pre">fromfile_prefix_chars=</span></tt> argument defaults to <tt class="xref docutils literal"><span class="pre">None</span></tt>, meaning that arguments will never be treated as file references.</p> |
573 | </div> |
574 | @@ -207,6 +189,7 @@ |
575 | <span class="go">Namespace(bar='YYY', parent=None)</span> |
576 | </pre></div> |
577 | </div> |
578 | +<p>Note that most parent parsers will specify <tt class="docutils literal"><span class="pre">add_help=False</span></tt>. Otherwise, the ArgumentParser will see two <tt class="docutils literal"><span class="pre">-h/--help</span></tt> options (one in the parent and one in the child) and raise an error.</p> |
579 | </div> |
580 | <div class="section" id="formatter-class"> |
581 | <h2>formatter_class<a class="headerlink" href="#formatter-class" title="Permalink to this headline">¶</a></h2> |
582 | @@ -396,7 +379,6 @@ |
583 | <li><a class="reference external" href="">ArgumentParser objects</a><ul> |
584 | <li><a class="reference external" href="#description">description</a></li> |
585 | <li><a class="reference external" href="#epilog">epilog</a></li> |
586 | -<li><a class="reference external" href="#version">version</a></li> |
587 | <li><a class="reference external" href="#add-help">add_help</a></li> |
588 | <li><a class="reference external" href="#prefix-chars">prefix_chars</a></li> |
589 | <li><a class="reference external" href="#fromfile-prefix-chars">fromfile_prefix_chars</a></li> |
590 | @@ -450,7 +432,7 @@ |
591 | <li class="right" > |
592 | <a href="api-docs.html" title="API documentation" |
593 | >previous</a> |</li> |
594 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
595 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
596 | <li><a href="api-docs.html" >API documentation</a> »</li> |
597 | </ul> |
598 | </div> |
599 | |
600 | === modified file 'doc/add_argument.html' |
601 | --- doc/add_argument.html 2009-10-12 18:04:37 +0000 |
602 | +++ doc/add_argument.html 2010-03-11 19:12:27 +0000 |
603 | @@ -5,13 +5,13 @@ |
604 | <head> |
605 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
606 | |
607 | - <title>The add_argument() method — argparse v1.0.1 documentation</title> |
608 | + <title>The add_argument() method — argparse v1.1 documentation</title> |
609 | <link rel="stylesheet" href="_static/default.css" type="text/css" /> |
610 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
611 | <script type="text/javascript"> |
612 | var DOCUMENTATION_OPTIONS = { |
613 | URL_ROOT: '', |
614 | - VERSION: '1.0.1', |
615 | + VERSION: '1.1', |
616 | COLLAPSE_MODINDEX: false, |
617 | FILE_SUFFIX: '.html', |
618 | HAS_SOURCE: true |
619 | @@ -19,7 +19,7 @@ |
620 | </script> |
621 | <script type="text/javascript" src="_static/jquery.js"></script> |
622 | <script type="text/javascript" src="_static/doctools.js"></script> |
623 | - <link rel="top" title="argparse v1.0.1 documentation" href="index.html" /> |
624 | + <link rel="top" title="argparse v1.1 documentation" href="index.html" /> |
625 | <link rel="up" title="API documentation" href="api-docs.html" /> |
626 | <link rel="next" title="The parse_args() method" href="parse_args.html" /> |
627 | <link rel="prev" title="ArgumentParser objects" href="ArgumentParser.html" /> |
628 | @@ -37,7 +37,7 @@ |
629 | <li class="right" > |
630 | <a href="ArgumentParser.html" title="ArgumentParser objects" |
631 | accesskey="P">previous</a> |</li> |
632 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
633 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
634 | <li><a href="api-docs.html" accesskey="U">API documentation</a> »</li> |
635 | </ul> |
636 | </div> |
637 | @@ -139,6 +139,15 @@ |
638 | </pre></div> |
639 | </div> |
640 | </li> |
641 | +<li><p class="first"><tt class="docutils literal"><span class="pre">'version'</span></tt> - This expects a <tt class="docutils literal"><span class="pre">version=</span></tt> keyword argument in the <a title="add_argument" class="reference internal" href="#add_argument"><tt class="xref docutils literal"><span class="pre">add_argument()</span></tt></a> call, and prints version information and exits when invoked.</p> |
642 | +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">argparse</span> |
643 | +<span class="gp">>>> </span><span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">prog</span><span class="o">=</span><span class="s">'PROG'</span><span class="p">)</span> |
644 | +<span class="gp">>>> </span><span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s">'-v'</span><span class="p">,</span> <span class="s">'--version'</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s">'version'</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="s">'</span><span class="si">%(prog)s</span><span class="s"> 2.0'</span><span class="p">)</span> |
645 | +<span class="gp">>>> </span><span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">([</span><span class="s">'-v'</span><span class="p">])</span> |
646 | +<span class="go">PROG 2.0</span> |
647 | +</pre></div> |
648 | +</div> |
649 | +</li> |
650 | </ul> |
651 | <p>You can also specify an arbitrary action by passing an object that implements the Action API. The easiest way to do this is to extend <tt class="docutils literal"><span class="pre">argparse.Action</span></tt>, supplying an appropriate <tt class="docutils literal"><span class="pre">__call__</span></tt> method. The <tt class="docutils literal"><span class="pre">__call__</span></tt> method accepts four parameters:</p> |
652 | <ul class="simple"> |
653 | @@ -286,7 +295,8 @@ |
654 | <span class="gp">... </span> <span class="n">value</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">string</span><span class="p">)</span> |
655 | <span class="gp">... </span> <span class="n">sqrt</span> <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">value</span><span class="p">)</span> |
656 | <span class="gp">... </span> <span class="k">if</span> <span class="n">sqrt</span> <span class="o">!=</span> <span class="nb">int</span><span class="p">(</span><span class="n">sqrt</span><span class="p">):</span> |
657 | -<span class="gp">... </span> <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">()</span> |
658 | +<span class="gp">... </span> <span class="n">msg</span> <span class="o">=</span> <span class="s">"</span><span class="si">%r</span><span class="s"> is not a perfect square"</span> <span class="o">%</span> <span class="n">string</span> |
659 | +<span class="gp">... </span> <span class="k">raise</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentTypeError</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span> |
660 | <span class="gp">... </span> <span class="k">return</span> <span class="n">value</span> |
661 | <span class="gp">...</span> |
662 | <span class="gp">>>> </span><span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">prog</span><span class="o">=</span><span class="s">'PROG'</span><span class="p">)</span> |
663 | @@ -295,7 +305,7 @@ |
664 | <span class="go">Namespace(foo=9)</span> |
665 | <span class="gp">>>> </span><span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">(</span><span class="s">'7'</span><span class="o">.</span><span class="n">split</span><span class="p">())</span> |
666 | <span class="go">usage: PROG [-h] foo</span> |
667 | -<span class="go">PROG: error: argument foo: invalid perfect_square value: '7'</span> |
668 | +<span class="go">PROG: error: argument foo: '7' is not a perfect square</span> |
669 | </pre></div> |
670 | </div> |
671 | <p>Note that if your type-checking function is just checking for a particular set of values, it may be more convenient to use the <a class="reference internal" href="#choices">choices</a> keyword argument:</p> |
672 | @@ -528,7 +538,7 @@ |
673 | <li class="right" > |
674 | <a href="ArgumentParser.html" title="ArgumentParser objects" |
675 | >previous</a> |</li> |
676 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
677 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
678 | <li><a href="api-docs.html" >API documentation</a> »</li> |
679 | </ul> |
680 | </div> |
681 | |
682 | === modified file 'doc/api-docs.html' |
683 | --- doc/api-docs.html 2009-10-12 18:04:37 +0000 |
684 | +++ doc/api-docs.html 2010-03-11 19:12:27 +0000 |
685 | @@ -5,13 +5,13 @@ |
686 | <head> |
687 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
688 | |
689 | - <title>API documentation — argparse v1.0.1 documentation</title> |
690 | + <title>API documentation — argparse v1.1 documentation</title> |
691 | <link rel="stylesheet" href="_static/default.css" type="text/css" /> |
692 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
693 | <script type="text/javascript"> |
694 | var DOCUMENTATION_OPTIONS = { |
695 | URL_ROOT: '', |
696 | - VERSION: '1.0.1', |
697 | + VERSION: '1.1', |
698 | COLLAPSE_MODINDEX: false, |
699 | FILE_SUFFIX: '.html', |
700 | HAS_SOURCE: true |
701 | @@ -19,7 +19,7 @@ |
702 | </script> |
703 | <script type="text/javascript" src="_static/jquery.js"></script> |
704 | <script type="text/javascript" src="_static/doctools.js"></script> |
705 | - <link rel="top" title="argparse v1.0.1 documentation" href="index.html" /> |
706 | + <link rel="top" title="argparse v1.1 documentation" href="index.html" /> |
707 | <link rel="next" title="ArgumentParser objects" href="ArgumentParser.html" /> |
708 | <link rel="prev" title="argparse vs. optparse" href="argparse-vs-optparse.html" /> |
709 | </head> |
710 | @@ -36,7 +36,7 @@ |
711 | <li class="right" > |
712 | <a href="argparse-vs-optparse.html" title="argparse vs. optparse" |
713 | accesskey="P">previous</a> |</li> |
714 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
715 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
716 | </ul> |
717 | </div> |
718 | |
719 | @@ -51,7 +51,6 @@ |
720 | <li class="toctree-l1"><a class="reference external" href="ArgumentParser.html">ArgumentParser objects</a><ul> |
721 | <li class="toctree-l2"><a class="reference external" href="ArgumentParser.html#description">description</a></li> |
722 | <li class="toctree-l2"><a class="reference external" href="ArgumentParser.html#epilog">epilog</a></li> |
723 | -<li class="toctree-l2"><a class="reference external" href="ArgumentParser.html#version">version</a></li> |
724 | <li class="toctree-l2"><a class="reference external" href="ArgumentParser.html#add-help">add_help</a></li> |
725 | <li class="toctree-l2"><a class="reference external" href="ArgumentParser.html#prefix-chars">prefix_chars</a></li> |
726 | <li class="toctree-l2"><a class="reference external" href="ArgumentParser.html#fromfile-prefix-chars">fromfile_prefix_chars</a></li> |
727 | @@ -93,6 +92,7 @@ |
728 | <li class="toctree-l2"><a class="reference external" href="other-methods.html#sub-commands">Sub-commands</a></li> |
729 | <li class="toctree-l2"><a class="reference external" href="other-methods.html#argument-groups">Argument groups</a></li> |
730 | <li class="toctree-l2"><a class="reference external" href="other-methods.html#mutual-exclusion">Mutual exclusion</a></li> |
731 | +<li class="toctree-l2"><a class="reference external" href="other-methods.html#customizing-file-parsing">Customizing file parsing</a></li> |
732 | </ul> |
733 | </li> |
734 | <li class="toctree-l1"><a class="reference external" href="other-utilities.html">Other utilities</a><ul> |
735 | @@ -148,7 +148,7 @@ |
736 | <li class="right" > |
737 | <a href="argparse-vs-optparse.html" title="argparse vs. optparse" |
738 | >previous</a> |</li> |
739 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
740 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
741 | </ul> |
742 | </div> |
743 | <div class="footer"> |
744 | |
745 | === modified file 'doc/argparse-vs-optparse.html' |
746 | --- doc/argparse-vs-optparse.html 2009-10-12 18:04:37 +0000 |
747 | +++ doc/argparse-vs-optparse.html 2010-03-11 19:12:27 +0000 |
748 | @@ -5,13 +5,13 @@ |
749 | <head> |
750 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
751 | |
752 | - <title>argparse vs. optparse — argparse v1.0.1 documentation</title> |
753 | + <title>argparse vs. optparse — argparse v1.1 documentation</title> |
754 | <link rel="stylesheet" href="_static/default.css" type="text/css" /> |
755 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
756 | <script type="text/javascript"> |
757 | var DOCUMENTATION_OPTIONS = { |
758 | URL_ROOT: '', |
759 | - VERSION: '1.0.1', |
760 | + VERSION: '1.1', |
761 | COLLAPSE_MODINDEX: false, |
762 | FILE_SUFFIX: '.html', |
763 | HAS_SOURCE: true |
764 | @@ -19,7 +19,7 @@ |
765 | </script> |
766 | <script type="text/javascript" src="_static/jquery.js"></script> |
767 | <script type="text/javascript" src="_static/doctools.js"></script> |
768 | - <link rel="top" title="argparse v1.0.1 documentation" href="index.html" /> |
769 | + <link rel="top" title="argparse v1.1 documentation" href="index.html" /> |
770 | <link rel="next" title="API documentation" href="api-docs.html" /> |
771 | <link rel="prev" title="Introduction to argparse" href="overview.html" /> |
772 | </head> |
773 | @@ -36,7 +36,7 @@ |
774 | <li class="right" > |
775 | <a href="overview.html" title="Introduction to argparse" |
776 | accesskey="P">previous</a> |</li> |
777 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
778 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
779 | </ul> |
780 | </div> |
781 | |
782 | @@ -345,7 +345,7 @@ |
783 | <li class="right" > |
784 | <a href="overview.html" title="Introduction to argparse" |
785 | >previous</a> |</li> |
786 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
787 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
788 | </ul> |
789 | </div> |
790 | <div class="footer"> |
791 | |
792 | === modified file 'doc/genindex.html' |
793 | --- doc/genindex.html 2009-10-12 18:04:37 +0000 |
794 | +++ doc/genindex.html 2010-03-11 19:12:27 +0000 |
795 | @@ -5,13 +5,13 @@ |
796 | <head> |
797 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
798 | |
799 | - <title>Index — argparse v1.0.1 documentation</title> |
800 | + <title>Index — argparse v1.1 documentation</title> |
801 | <link rel="stylesheet" href="_static/default.css" type="text/css" /> |
802 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
803 | <script type="text/javascript"> |
804 | var DOCUMENTATION_OPTIONS = { |
805 | URL_ROOT: '', |
806 | - VERSION: '1.0.1', |
807 | + VERSION: '1.1', |
808 | COLLAPSE_MODINDEX: false, |
809 | FILE_SUFFIX: '.html', |
810 | HAS_SOURCE: true |
811 | @@ -19,7 +19,7 @@ |
812 | </script> |
813 | <script type="text/javascript" src="_static/jquery.js"></script> |
814 | <script type="text/javascript" src="_static/doctools.js"></script> |
815 | - <link rel="top" title="argparse v1.0.1 documentation" href="index.html" /> |
816 | + <link rel="top" title="argparse v1.1 documentation" href="index.html" /> |
817 | </head> |
818 | <body> |
819 | <div class="related"> |
820 | @@ -28,7 +28,7 @@ |
821 | <li class="right" style="margin-right: 10px"> |
822 | <a href="" title="General Index" |
823 | accesskey="I">index</a></li> |
824 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
825 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
826 | </ul> |
827 | </div> |
828 | |
829 | @@ -40,7 +40,7 @@ |
830 | |
831 | <h1 id="index">Index</h1> |
832 | |
833 | - <a href="#A"><strong>A</strong></a> | <a href="#F"><strong>F</strong></a> | <a href="#P"><strong>P</strong></a> | <a href="#S"><strong>S</strong></a> |
834 | + <a href="#A"><strong>A</strong></a> | <a href="#C"><strong>C</strong></a> | <a href="#F"><strong>F</strong></a> | <a href="#G"><strong>G</strong></a> | <a href="#P"><strong>P</strong></a> | <a href="#S"><strong>S</strong></a> |
835 | |
836 | <hr /> |
837 | |
838 | @@ -56,6 +56,13 @@ |
839 | <dt><a href="ArgumentParser.html#ArgumentParser">ArgumentParser (built-in class)</a></dt> |
840 | </dl></td></tr></table> |
841 | |
842 | +<h2 id="C">C</h2> |
843 | +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> |
844 | +<dl> |
845 | + |
846 | +<dt><a href="other-methods.html#convert_arg_line_to_args">convert_arg_line_to_args()</a></dt></dl></td><td width="33%" valign="top"><dl> |
847 | +</dl></td></tr></table> |
848 | + |
849 | <h2 id="F">F</h2> |
850 | <table width="100%" class="indextable"><tr><td width="33%" valign="top"> |
851 | <dl> |
852 | @@ -63,6 +70,13 @@ |
853 | <dt><a href="other-utilities.html#FileType">FileType (built-in class)</a></dt></dl></td><td width="33%" valign="top"><dl> |
854 | </dl></td></tr></table> |
855 | |
856 | +<h2 id="G">G</h2> |
857 | +<table width="100%" class="indextable"><tr><td width="33%" valign="top"> |
858 | +<dl> |
859 | + |
860 | +<dt><a href="other-methods.html#get_default">get_default()</a></dt></dl></td><td width="33%" valign="top"><dl> |
861 | +</dl></td></tr></table> |
862 | + |
863 | <h2 id="P">P</h2> |
864 | <table width="100%" class="indextable"><tr><td width="33%" valign="top"> |
865 | <dl> |
866 | @@ -111,7 +125,7 @@ |
867 | <li class="right" style="margin-right: 10px"> |
868 | <a href="" title="General Index" |
869 | >index</a></li> |
870 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
871 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
872 | </ul> |
873 | </div> |
874 | <div class="footer"> |
875 | |
876 | === modified file 'doc/index.html' |
877 | --- doc/index.html 2009-10-12 18:04:37 +0000 |
878 | +++ doc/index.html 2010-03-11 19:12:27 +0000 |
879 | @@ -5,13 +5,13 @@ |
880 | <head> |
881 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
882 | |
883 | - <title>Documentation — argparse v1.0.1 documentation</title> |
884 | + <title>Documentation — argparse v1.1 documentation</title> |
885 | <link rel="stylesheet" href="_static/default.css" type="text/css" /> |
886 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
887 | <script type="text/javascript"> |
888 | var DOCUMENTATION_OPTIONS = { |
889 | URL_ROOT: '', |
890 | - VERSION: '1.0.1', |
891 | + VERSION: '1.1', |
892 | COLLAPSE_MODINDEX: false, |
893 | FILE_SUFFIX: '.html', |
894 | HAS_SOURCE: true |
895 | @@ -19,7 +19,7 @@ |
896 | </script> |
897 | <script type="text/javascript" src="_static/jquery.js"></script> |
898 | <script type="text/javascript" src="_static/doctools.js"></script> |
899 | - <link rel="top" title="argparse v1.0.1 documentation" href="" /> |
900 | + <link rel="top" title="argparse v1.1 documentation" href="" /> |
901 | <link rel="next" title="Introduction to argparse" href="overview.html" /> |
902 | </head> |
903 | <body> |
904 | @@ -32,7 +32,7 @@ |
905 | <li class="right" > |
906 | <a href="overview.html" title="Introduction to argparse" |
907 | accesskey="N">next</a> |</li> |
908 | - <li><a href="">argparse v1.0.1 documentation</a> »</li> |
909 | + <li><a href="">argparse v1.1 documentation</a> »</li> |
910 | </ul> |
911 | </div> |
912 | |
913 | @@ -162,7 +162,7 @@ |
914 | <li class="right" > |
915 | <a href="overview.html" title="Introduction to argparse" |
916 | >next</a> |</li> |
917 | - <li><a href="">argparse v1.0.1 documentation</a> »</li> |
918 | + <li><a href="">argparse v1.1 documentation</a> »</li> |
919 | </ul> |
920 | </div> |
921 | <div class="footer"> |
922 | |
923 | === modified file 'doc/other-methods.html' |
924 | --- doc/other-methods.html 2009-10-12 18:04:37 +0000 |
925 | +++ doc/other-methods.html 2010-03-11 19:12:27 +0000 |
926 | @@ -5,13 +5,13 @@ |
927 | <head> |
928 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
929 | |
930 | - <title>Other methods — argparse v1.0.1 documentation</title> |
931 | + <title>Other methods — argparse v1.1 documentation</title> |
932 | <link rel="stylesheet" href="_static/default.css" type="text/css" /> |
933 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
934 | <script type="text/javascript"> |
935 | var DOCUMENTATION_OPTIONS = { |
936 | URL_ROOT: '', |
937 | - VERSION: '1.0.1', |
938 | + VERSION: '1.1', |
939 | COLLAPSE_MODINDEX: false, |
940 | FILE_SUFFIX: '.html', |
941 | HAS_SOURCE: true |
942 | @@ -19,7 +19,7 @@ |
943 | </script> |
944 | <script type="text/javascript" src="_static/jquery.js"></script> |
945 | <script type="text/javascript" src="_static/doctools.js"></script> |
946 | - <link rel="top" title="argparse v1.0.1 documentation" href="index.html" /> |
947 | + <link rel="top" title="argparse v1.1 documentation" href="index.html" /> |
948 | <link rel="up" title="API documentation" href="api-docs.html" /> |
949 | <link rel="next" title="Other utilities" href="other-utilities.html" /> |
950 | <link rel="prev" title="The parse_args() method" href="parse_args.html" /> |
951 | @@ -37,7 +37,7 @@ |
952 | <li class="right" > |
953 | <a href="parse_args.html" title="The parse_args() method" |
954 | accesskey="P">previous</a> |</li> |
955 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
956 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
957 | <li><a href="api-docs.html" accesskey="U">API documentation</a> »</li> |
958 | </ul> |
959 | </div> |
960 | @@ -117,6 +117,18 @@ |
961 | <p>Parser-level defaults can be particularly useful when you’re working with multiple parsers. See the <a title="add_subparsers" class="reference internal" href="#add_subparsers"><tt class="xref docutils literal"><span class="pre">add_subparsers()</span></tt></a> method for an example of this type.</p> |
962 | </dd></dl> |
963 | |
964 | +<dl class="method"> |
965 | +<dt id="get_default"> |
966 | +<tt class="descname">get_default</tt><big>(</big><em>dest</em><big>)</big><a class="headerlink" href="#get_default" title="Permalink to this definition">¶</a></dt> |
967 | +<dd><p>Get the default value for a namespace attribute, as set by either <a title="add_argument" class="reference external" href="add_argument.html#add_argument"><tt class="xref docutils literal"><span class="pre">add_argument()</span></tt></a> or by <a title="set_defaults" class="reference internal" href="#set_defaults"><tt class="xref docutils literal"><span class="pre">set_defaults()</span></tt></a>:</p> |
968 | +<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">()</span> |
969 | +<span class="gp">>>> </span><span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s">'--foo'</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s">'badger'</span><span class="p">)</span> |
970 | +<span class="gp">>>> </span><span class="n">parser</span><span class="o">.</span><span class="n">get_default</span><span class="p">(</span><span class="s">'foo'</span><span class="p">)</span> |
971 | +<span class="go">'badger'</span> |
972 | +</pre></div> |
973 | +</div> |
974 | +</dd></dl> |
975 | + |
976 | </div> |
977 | <div class="section" id="sub-commands"> |
978 | <h2>Sub-commands<a class="headerlink" href="#sub-commands" title="Permalink to this headline">¶</a></h2> |
979 | @@ -318,6 +330,24 @@ |
980 | </dd></dl> |
981 | |
982 | </div> |
983 | +<div class="section" id="customizing-file-parsing"> |
984 | +<h2>Customizing file parsing<a class="headerlink" href="#customizing-file-parsing" title="Permalink to this headline">¶</a></h2> |
985 | +<dl class="method"> |
986 | +<dt id="convert_arg_line_to_args"> |
987 | +<tt class="descname">convert_arg_line_to_args</tt><big>(</big><em>arg_line</em><big>)</big><a class="headerlink" href="#convert_arg_line_to_args" title="Permalink to this definition">¶</a></dt> |
988 | +<dd><p>Arguments that are read from a file (see the <tt class="docutils literal"><span class="pre">fromfile_prefix_chars</span></tt> keyword argument to the <a title="ArgumentParser" class="reference external" href="ArgumentParser.html#ArgumentParser"><tt class="xref docutils literal"><span class="pre">ArgumentParser</span></tt></a> constructor) are read one argument per line. If you need fancier parsing, then you can subclass the <a title="ArgumentParser" class="reference external" href="ArgumentParser.html#ArgumentParser"><tt class="xref docutils literal"><span class="pre">ArgumentParser</span></tt></a> and override the <a title="convert_arg_line_to_args" class="reference internal" href="#convert_arg_line_to_args"><tt class="xref docutils literal"><span class="pre">convert_arg_line_to_args()</span></tt></a> method.</p> |
989 | +<p>This method takes a single argument <tt class="docutils literal"><span class="pre">arg_line</span></tt> which is a string read from the argument file. It returns a list of arguments parsed from this string. The method is called once per line read from the argument file, in order.</p> |
990 | +<p>A useful override of this method is one that treats each space-separated word as an argument:</p> |
991 | +<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">convert_arg_line_to_args</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">arg_line</span><span class="p">):</span> |
992 | + <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">arg_line</span><span class="o">.</span><span class="n">split</span><span class="p">():</span> |
993 | + <span class="k">if</span> <span class="ow">not</span> <span class="n">arg</span><span class="o">.</span><span class="n">strip</span><span class="p">():</span> |
994 | + <span class="k">continue</span> |
995 | + <span class="k">yield</span> <span class="n">arg</span> |
996 | +</pre></div> |
997 | +</div> |
998 | +</dd></dl> |
999 | + |
1000 | +</div> |
1001 | </div> |
1002 | |
1003 | |
1004 | @@ -335,6 +365,7 @@ |
1005 | <li><a class="reference external" href="#sub-commands">Sub-commands</a></li> |
1006 | <li><a class="reference external" href="#argument-groups">Argument groups</a></li> |
1007 | <li><a class="reference external" href="#mutual-exclusion">Mutual exclusion</a></li> |
1008 | +<li><a class="reference external" href="#customizing-file-parsing">Customizing file parsing</a></li> |
1009 | </ul> |
1010 | </li> |
1011 | </ul> |
1012 | @@ -379,7 +410,7 @@ |
1013 | <li class="right" > |
1014 | <a href="parse_args.html" title="The parse_args() method" |
1015 | >previous</a> |</li> |
1016 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
1017 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
1018 | <li><a href="api-docs.html" >API documentation</a> »</li> |
1019 | </ul> |
1020 | </div> |
1021 | |
1022 | === modified file 'doc/other-utilities.html' |
1023 | --- doc/other-utilities.html 2009-10-12 18:04:37 +0000 |
1024 | +++ doc/other-utilities.html 2010-03-11 19:12:27 +0000 |
1025 | @@ -5,13 +5,13 @@ |
1026 | <head> |
1027 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
1028 | |
1029 | - <title>Other utilities — argparse v1.0.1 documentation</title> |
1030 | + <title>Other utilities — argparse v1.1 documentation</title> |
1031 | <link rel="stylesheet" href="_static/default.css" type="text/css" /> |
1032 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
1033 | <script type="text/javascript"> |
1034 | var DOCUMENTATION_OPTIONS = { |
1035 | URL_ROOT: '', |
1036 | - VERSION: '1.0.1', |
1037 | + VERSION: '1.1', |
1038 | COLLAPSE_MODINDEX: false, |
1039 | FILE_SUFFIX: '.html', |
1040 | HAS_SOURCE: true |
1041 | @@ -19,7 +19,7 @@ |
1042 | </script> |
1043 | <script type="text/javascript" src="_static/jquery.js"></script> |
1044 | <script type="text/javascript" src="_static/doctools.js"></script> |
1045 | - <link rel="top" title="argparse v1.0.1 documentation" href="index.html" /> |
1046 | + <link rel="top" title="argparse v1.1 documentation" href="index.html" /> |
1047 | <link rel="up" title="API documentation" href="api-docs.html" /> |
1048 | <link rel="prev" title="Other methods" href="other-methods.html" /> |
1049 | </head> |
1050 | @@ -33,7 +33,7 @@ |
1051 | <li class="right" > |
1052 | <a href="other-methods.html" title="Other methods" |
1053 | accesskey="P">previous</a> |</li> |
1054 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
1055 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
1056 | <li><a href="api-docs.html" accesskey="U">API documentation</a> »</li> |
1057 | </ul> |
1058 | </div> |
1059 | @@ -118,7 +118,7 @@ |
1060 | <li class="right" > |
1061 | <a href="other-methods.html" title="Other methods" |
1062 | >previous</a> |</li> |
1063 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
1064 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
1065 | <li><a href="api-docs.html" >API documentation</a> »</li> |
1066 | </ul> |
1067 | </div> |
1068 | |
1069 | === modified file 'doc/overview.html' |
1070 | --- doc/overview.html 2009-10-12 18:04:37 +0000 |
1071 | +++ doc/overview.html 2010-03-11 19:12:27 +0000 |
1072 | @@ -5,13 +5,13 @@ |
1073 | <head> |
1074 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
1075 | |
1076 | - <title>Introduction to argparse — argparse v1.0.1 documentation</title> |
1077 | + <title>Introduction to argparse — argparse v1.1 documentation</title> |
1078 | <link rel="stylesheet" href="_static/default.css" type="text/css" /> |
1079 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
1080 | <script type="text/javascript"> |
1081 | var DOCUMENTATION_OPTIONS = { |
1082 | URL_ROOT: '', |
1083 | - VERSION: '1.0.1', |
1084 | + VERSION: '1.1', |
1085 | COLLAPSE_MODINDEX: false, |
1086 | FILE_SUFFIX: '.html', |
1087 | HAS_SOURCE: true |
1088 | @@ -19,7 +19,7 @@ |
1089 | </script> |
1090 | <script type="text/javascript" src="_static/jquery.js"></script> |
1091 | <script type="text/javascript" src="_static/doctools.js"></script> |
1092 | - <link rel="top" title="argparse v1.0.1 documentation" href="index.html" /> |
1093 | + <link rel="top" title="argparse v1.1 documentation" href="index.html" /> |
1094 | <link rel="next" title="argparse vs. optparse" href="argparse-vs-optparse.html" /> |
1095 | <link rel="prev" title="Documentation" href="index.html" /> |
1096 | </head> |
1097 | @@ -36,7 +36,7 @@ |
1098 | <li class="right" > |
1099 | <a href="index.html" title="Documentation" |
1100 | accesskey="P">previous</a> |</li> |
1101 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
1102 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
1103 | </ul> |
1104 | </div> |
1105 | |
1106 | @@ -150,7 +150,7 @@ |
1107 | <li class="right" > |
1108 | <a href="index.html" title="Documentation" |
1109 | >previous</a> |</li> |
1110 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
1111 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
1112 | </ul> |
1113 | </div> |
1114 | <div class="footer"> |
1115 | |
1116 | === modified file 'doc/parse_args.html' |
1117 | --- doc/parse_args.html 2009-10-12 18:04:37 +0000 |
1118 | +++ doc/parse_args.html 2010-03-11 19:12:27 +0000 |
1119 | @@ -5,13 +5,13 @@ |
1120 | <head> |
1121 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
1122 | |
1123 | - <title>The parse_args() method — argparse v1.0.1 documentation</title> |
1124 | + <title>The parse_args() method — argparse v1.1 documentation</title> |
1125 | <link rel="stylesheet" href="_static/default.css" type="text/css" /> |
1126 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
1127 | <script type="text/javascript"> |
1128 | var DOCUMENTATION_OPTIONS = { |
1129 | URL_ROOT: '', |
1130 | - VERSION: '1.0.1', |
1131 | + VERSION: '1.1', |
1132 | COLLAPSE_MODINDEX: false, |
1133 | FILE_SUFFIX: '.html', |
1134 | HAS_SOURCE: true |
1135 | @@ -19,7 +19,7 @@ |
1136 | </script> |
1137 | <script type="text/javascript" src="_static/jquery.js"></script> |
1138 | <script type="text/javascript" src="_static/doctools.js"></script> |
1139 | - <link rel="top" title="argparse v1.0.1 documentation" href="index.html" /> |
1140 | + <link rel="top" title="argparse v1.1 documentation" href="index.html" /> |
1141 | <link rel="up" title="API documentation" href="api-docs.html" /> |
1142 | <link rel="next" title="Other methods" href="other-methods.html" /> |
1143 | <link rel="prev" title="The add_argument() method" href="add_argument.html" /> |
1144 | @@ -37,7 +37,7 @@ |
1145 | <li class="right" > |
1146 | <a href="add_argument.html" title="The add_argument() method" |
1147 | accesskey="P">previous</a> |</li> |
1148 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
1149 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
1150 | <li><a href="api-docs.html" accesskey="U">API documentation</a> »</li> |
1151 | </ul> |
1152 | </div> |
1153 | @@ -263,7 +263,7 @@ |
1154 | <li class="right" > |
1155 | <a href="add_argument.html" title="The add_argument() method" |
1156 | >previous</a> |</li> |
1157 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
1158 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
1159 | <li><a href="api-docs.html" >API documentation</a> »</li> |
1160 | </ul> |
1161 | </div> |
1162 | |
1163 | === modified file 'doc/search.html' |
1164 | --- doc/search.html 2009-10-12 18:04:37 +0000 |
1165 | +++ doc/search.html 2010-03-11 19:12:27 +0000 |
1166 | @@ -5,13 +5,13 @@ |
1167 | <head> |
1168 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
1169 | |
1170 | - <title>Search — argparse v1.0.1 documentation</title> |
1171 | + <title>Search — argparse v1.1 documentation</title> |
1172 | <link rel="stylesheet" href="_static/default.css" type="text/css" /> |
1173 | <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> |
1174 | <script type="text/javascript"> |
1175 | var DOCUMENTATION_OPTIONS = { |
1176 | URL_ROOT: '', |
1177 | - VERSION: '1.0.1', |
1178 | + VERSION: '1.1', |
1179 | COLLAPSE_MODINDEX: false, |
1180 | FILE_SUFFIX: '.html', |
1181 | HAS_SOURCE: true |
1182 | @@ -20,7 +20,7 @@ |
1183 | <script type="text/javascript" src="_static/jquery.js"></script> |
1184 | <script type="text/javascript" src="_static/doctools.js"></script> |
1185 | <script type="text/javascript" src="_static/searchtools.js"></script> |
1186 | - <link rel="top" title="argparse v1.0.1 documentation" href="index.html" /> |
1187 | + <link rel="top" title="argparse v1.1 documentation" href="index.html" /> |
1188 | </head> |
1189 | <body> |
1190 | <div class="related"> |
1191 | @@ -29,7 +29,7 @@ |
1192 | <li class="right" style="margin-right: 10px"> |
1193 | <a href="genindex.html" title="General Index" |
1194 | accesskey="I">index</a></li> |
1195 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
1196 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
1197 | </ul> |
1198 | </div> |
1199 | |
1200 | @@ -77,7 +77,7 @@ |
1201 | <li class="right" style="margin-right: 10px"> |
1202 | <a href="genindex.html" title="General Index" |
1203 | >index</a></li> |
1204 | - <li><a href="index.html">argparse v1.0.1 documentation</a> »</li> |
1205 | + <li><a href="index.html">argparse v1.1 documentation</a> »</li> |
1206 | </ul> |
1207 | </div> |
1208 | |
1209 | |
1210 | === modified file 'doc/searchindex.js' |
1211 | --- doc/searchindex.js 2009-10-12 18:04:37 +0000 |
1212 | +++ doc/searchindex.js 2010-03-11 19:12:27 +0000 |
1213 | @@ -1,1 +1,1 @@ |
1214 | -Search.setIndex({desctypes:{"0":"method","1":"class"},terms:{all:[6,3,7,5,2],code:[0,7,6],partial:[8,7,2],messg:7,whatev:2,illustr:[7,5],global:6,four:5,prefix:[1,6,5],upgrad:[0,7],follow:[0,7,5,6,3],formatter_class:[8,6],whose:[5,6],typeerror:5,"const":[8,3,7,1,5],readabl:4,prefix_char:[8,7,6],program:[6,0,5,2,3],present:[7,1,2,5],sens:[5,6],worth:5,consum:[7,5],everi:3,string:[1,2,3,5,6,7],fals:[6,7,5,2],subcommand:[7,2],util:[8,0,4],parent_pars:6,default_:[],exact:7,implement:5,level:2,list:[1,2,3,5,6,7],"try":[7,6],item:[5,2],adjust:6,stderr:2,pleas:6,subparser_nam:2,bacon:1,dogmat:7,past:7,zero:[7,5],fyoyo:7,group1:2,pass:[1,2,4,5,6,7],append:5,compat:7,what:[3,7,1,6,5],abc:[7,5],sub:[8,7,2],neg:1,section:[6,7,5,2],advanc:7,brief:[6,5,2],current:[6,2],abbrevi:[8,1],version:[8,6],"new":[7,1,6,5],method:[0,1,2,3,5,6,7,8],told:5,deriv:[7,5],gener:[0,7,5,6,3],never:[7,6],here:[7,1],let:2,inher:1,path:7,along:1,infil:[4,5],modifi:2,sinc:7,interpret:5,convert:[3,4,7,1,5],produc:[7,5,2],convers:5,pick:1,action:[1,2,3,5,6,7,8],weird:6,commonli:5,mutual:[8,2],control:6,regardless:6,extra:[1,2],appli:5,modul:[0,7,5,3],prefer:7,filenam:5,api:[8,0,7,5],txt:[0,5,6],select:[5,2],add_argument_group:2,from:[1,2,3,5,6,7],describ:[6,5,2],would:[7,5],frobbl:[5,2],regist:2,two:[6,3,1,2,5],few:[7,5,2],call:[0,1,2,3,5,6,7],add_help:[8,7,6,2],recommend:2,taken:[7,1,5],rawtexthelpformatt:6,type:[0,1,2,3,4,5,6,7,8],tell:[3,1],more:[0,1,3,5,6,7],sort:[3,5,6],parser_a:2,parser_b:2,notic:[7,1],warn:5,flag:[8,7,5],indic:[6,5,2],particular:[7,5,2],known:7,hold:[3,5],easiest:[7,5,2],must:[1,6,5],dictat:7,none:[4,7,1,6,5],word:6,dest:[1,2,3,5,7,8],work:[6,2],conceptu:2,remain:[3,7,5,2],itself:5,can:[0,1,2,3,4,5,6,7],def:[7,5,2],overrid:[7,6,2],traceback:6,prompt:1,puriti:7,give:[1,6],frabbl:3,share:[7,6],add_argu:[0,1,2,3,4,5,6,7,8],accept:[7,5,2],cautiou:1,want:[6,3,7,5,2],alwai:[6,5,2],multipl:[7,5,2],thing:5,rather:[1,6],anoth:[6,5,2],check_method:7,fooaction:[7,5],write:[0,7,6,3],how:[6,3,1,2,5],sever:[6,1,2],instead:[7,5,2],narg:[0,1,3,5,6,7,8],simpl:[0,7,5,3],updat:2,parser_abc:7,foo_pars:[7,6],overridden:6,mess:6,max:[3,1],after:[6,7,1,2,5],variant:2,invok:[6,3,7,5,2],befor:[5,6],wrong:1,okai:6,mai:[6,7,1,2,5],end:[7,5,2],associ:[5,2],xfoox:7,"0x013a2410":[],"short":[1,6,5],attempt:[7,1],practic:7,stdin:[4,5],explicit:5,correspond:[3,7],ambigu:1,caus:[5,6],callback:7,type_:[],maintain:[7,6],combin:[1,2],allow:[6,7,1,2,5],callabl:[7,5],origin:[7,6],least:[5,2],help:[0,1,2,3,5,6,7,8],over:[7,6],becaus:6,through:7,same:[7,5,6],hierarchi:7,metavar_:[],still:5,subparser2:2,subparser1:2,paramet:[7,5,6],style:1,interspers:7,group:[8,2],fit:6,better:[7,2],main:2,easier:1,them:[0,5,1,6,3],good:2,"return":[3,7,1,2,5],thei:[7,1,6,5],python:[0,7,6,2],initi:[3,5],option_str:[7,5],now:[3,7],discuss:7,introduct:[0,3],choic:[1,2,3,5,7,8],allow_interspersed_arg:7,optionerror:7,name:[1,2,3,5,6,7,8],anyth:[7,5],choices_:[],separ:[1,2],easili:7,achiev:[1,6],mode:[4,7,5],each:[6,3,7,5,2],fulli:2,difficult:7,nbar:6,mean:[3,7,5,6],myprogram:6,replac:[7,6],idea:2,heavi:1,expect:[3,1,5],our:3,happen:7,beyond:[8,1],metavar:[0,1,3,5,7,8],special:[5,2],out:[0,4,5,6,3],variabl:7,accomplish:[1,6],referenc:6,space:6,foo_bar:5,newli:1,parser_xyz:7,perfect_squar:5,print:[1,2,3,5,6,7,8],factori:[4,5],math:5,common:[3,5,6],optionvalueerror:7,worthwhil:7,situat:[1,5],given:6,argv:[8,3,1,6],standard:7,mmm:1,reason:7,base:7,dictionari:7,care:[7,2],indent:6,could:[1,5],omit:5,refus:7,keep:6,fromfile_prefix_char:[8,6],turn:3,place:6,isn:[7,5],retain:6,const_:[],assign:1,first:[5,6],oper:5,rang:[3,1],directli:5,carri:3,onc:3,number:[6,7,1,2,5],restrict:5,instruct:3,alreadi:[7,1,6],construct:[7,6],wasn:5,open:[4,7,5,6],size:4,differ:[7,5,2],script:[3,2],top:2,sometim:[6,1,2],messag:[0,1,2,5,6,7],too:5,similarli:2,conveni:[7,5],"final":[],store:[3,5],monkei:7,option:[0,1,2,3,5,6,7,8],namespac:[1,2,3,4,5,6,7,8],copi:7,specifi:[0,1,2,3,5,6,7],pars:[0,1,2,3,5,7,8],store_tru:[3,7,1,2,5],exactli:[3,1,6],than:[6,7,1,2,5],format_usag:2,wide:6,kind:2,setattr:[7,5],whenev:[1,5],provid:[0,7,1,2,5],remov:6,charact:[7,1,6,5],str:5,were:[5,6],posit:[0,1,2,3,5,6,7],seri:[3,5],sai:7,abov:[6,0,1,2,3],"0x013a2380":[],group2:2,argument:[0,1,2,3,4,5,6,7,8],dash:7,add_pars:[7,2],manner:[3,7],have:[4,7,1,6,5],"__main__":[0,3],need:[6,7,5,2],seem:7,built:[3,1],equival:6,inform:[3,7,6,2],self:[7,5],append_const:5,also:[6,1,2,5],builtin:5,exampl:[0,1,2,3,5,6],take:[1,2,3,5,6,7],which:[6,7,1,2,5],singl:[1,2,3,5,6,7],uppercas:5,begin:[3,1],sure:[7,5,2],though:5,buffer:4,previou:[7,1],most:[6,3,7,5,2],regular:2,pair:[7,6],choos:[7,5],"class":[4,7,1,6,5],appear:2,don:[7,1,5],later:3,request:[4,5,2],doe:[6,7,5,2],declar:7,determin:[1,2,3,5,6,7],occasion:6,sum:[0,1,3],"0x00b8fb18":[],parser_bar:2,show:[6,0,7,5,2],text:6,filetyp:[8,0,4,5],syntax:[8,7,1],particularli:[7,6,2],hack:7,find:[3,1,2],onli:[6,7,1,2,5],textual:6,parse_known_arg:2,just:[5,2],pretti:3,"true":[1,2,3,5,6,7],parser_foo:2,figur:5,should:[0,2,3,5,6,7],store_const:[3,7,1,5],wood:1,dict:5,"__call__":[7,5],add_opt:7,variou:[5,6],get:[3,7,1,6],express:6,report:5,requir:[8,7,1,2,5],bar:[1,2,3,5,6,7],keyword:[1,2,3,5,6,7],baz:[7,5,2],dramat:7,patch:7,store_fals:[5,2],whether:[5,6],bad:[1,5],calcul:6,bac:1,contain:[1,2,5,6,7,8],where:[0,5,6],set:[6,3,7,5,2],"float":[7,5,2],see:[1,2,3,5,6,7],arg:[0,1,2,3,4,5,6,7],close:0,extend:[7,5],correctli:6,someth:3,written:0,subdir:6,between:6,"import":[0,7,5,6,3],awai:5,badger:[7,1,2],across:6,attribut:[1,2,3,5,6,7],altern:6,parent:[8,7,6,2],xrang:[3,7,1,5],disallow:[7,6],extens:7,outfil:5,come:7,addit:[6,7,5,2],both:[7,1],last:[1,6],howev:[6,7,5,2],against:7,etc:[7,1,2,5],eas:5,mani:[7,5],whole:6,simpli:[6,7,1,2,5],point:7,argumentpars:[0,1,2,3,4,5,6,7,8],dispatch:7,featur:7,suppli:[6,3,7,5,2],respect:5,assum:[0,5,2,3],duplic:7,quit:[7,5],coupl:[6,2],addition:5,three:6,empti:1,implicit:7,accumul:[3,1],secret:7,much:[3,7,1,2,5],valu:[8,7,1,6,5],basic:5,unambigu:1,print_usag:2,popul:[1,2],strategi:6,epilog:[8,6],suppress:[7,5,6],xxx:[7,5,6],great:5,ani:[6,7,5,2],understand:4,togeth:[1,5],func:2,child:6,repetit:5,those:[7,1],"case":[3,1,2,5],therefor:5,look:[3,7,1],format_help:2,formatt:6,defin:[6,5,2],"while":[7,1,6,5],behavior:[3,5,6],error:[6,7,1,2,5],argpars:[0,1,2,3,4,5,6,7],advantag:[0,7],stdout:[0,4,5],almost:[5,6],kwarg:[7,2],"__init__":7,clearli:1,perform:[5,2],make:[6,3,7,5,2],format:[6,7,5,2],sqrt:5,check:[7,1,2,5],handl:[7,5,2],complex:[7,5],help_:[],split:[1,2,3,5,6,7],document:[8,0,1],infer:5,dest_:[],complet:2,dedent:6,foo_bar_baz_pars:7,effect:2,rais:[5,6],user:[6,7,1,2,5],store_act:7,typic:[3,7,5,2],recent:6,appropri:[0,2,3,5,6,7],older:6,thu:7,inherit:[7,6],likewis:6,without:2,command:[0,1,2,3,4,5,6,7,8],thi:[0,1,2,3,4,5,6,7],conflict:6,everyth:[7,1],sibl:2,usual:[6,7,5,2],identifi:5,execut:2,add_mutually_exclusive_group:2,note:[6,7,5,2],action_:[],exclus:[8,2],expos:7,had:7,except:[6,2],add:[0,2,3,5,6,7],valid:[7,5,2],remaining_arg:7,rawdescriptionhelpformatt:6,save:[0,3],match:[6,7,1,2,5],applic:[6,2],transpar:7,read:[5,6],textwrap:6,writabl:[4,5],know:[7,5,2],print_help:[6,7,5,2],insert:[1,6],like:[1,2,3,5,6,7],specif:6,arbitrari:5,whitespac:6,manual:7,resolv:6,integ:[0,5,7,1,3],collect:6,necessari:[3,7,5,2],either:[1,2,3,5,6,7],argumenterror:[7,6],output:[6,4,5,2],unnecessari:6,encount:[3,1,5],old:[6,2],often:5,"0x00b1f020":[],interact:1,some:[1,2,3,5,6,7],back:2,intern:5,mistak:1,proper:7,librari:7,absent:5,subpars:[7,2],avoid:5,normal:[1,2,5],definit:6,per:6,exit:[0,1,2,5,6,7],prog:[1,2,5,6,7,8],foo:[1,2,3,5,6,7],refer:[1,6,5],nargs_:[],object:[0,1,2,3,4,5,6,7,8],run:[0,3],inspect:[3,2],usag:[0,1,2,5,6,7,8],argument_default:[8,6],found:1,add_subpars:[7,2],"__name__":[0,3],"super":7,xyzz:1,about:[6,3,7,5,2],actual:7,callback_:7,optpars:[0,7],constructor:[7,6,2],commit:2,disabl:6,own:[6,7,5,2],xyz:[7,2],within:6,automat:[4,5,6],suppl:2,been:[3,7,5],strip:5,wrap:6,chang:[6,7,5,2],mark:5,yyi:[5,6],your:[6,3,7,5,2],manag:3,inclus:5,fill:[3,6],log:0,wai:[6,7,1,2,5],spam:[7,1,2],support:[6,7,1,2,5],"long":[7,1,6,5],custom:[6,8,1,2,5],avail:[6,5,2],start:[3,6],interfac:[0,7,5,3],includ:[6,7,1,2,5],lot:[7,2],parse_arg:[0,1,2,3,4,5,6,7,8],treat:[6,2],"function":[1,2,5],reduc:7,creation:[6,2],form:[3,7,5],tupl:[5,2],bufsiz:[4,5],parents_:[],"0x00b8fe78":[],line:[0,1,2,3,4,5,6,7],conflict_handl:[8,6],concaten:1,made:1,input:5,temp:5,possibl:5,"default":[0,1,2,3,5,6,7,8],checkout:2,argumentdefaultshelpformatt:6,displai:[6,7,5,2],below:[7,5,6],otherwis:6,similar:7,gather:5,constant:5,creat:[0,1,2,3,4,5,6,7],"int":[0,1,2,3,5,6,7],descript:[0,2,3,5,6,8],parser:[0,1,2,3,4,5,6,7,8],"0x00b1f068":[],doesn:[7,5],strongli:2,exist:1,file:[0,2,3,4,5,6,7],xyzyx:2,simplest:1,probabl:5,again:7,readi:3,titl:2,when:[0,1,2,3,5,6,7],detail:[1,6,5],invalid:[8,7,1,5],other:[0,1,2,4,6,7,8],futur:2,scriptnam:0,varieti:1,test:7,set_default:[6,2],you:[1,2,3,5,6,7],bar_pars:[7,6],repeat:6,clean:6,why:7,consid:[5,6],"0x00adf020":[],svn:2,receiv:7,longer:[7,1,2],pseudo:[4,1],time:[7,5,2],backward:7},titles:["Documentation","The parse_args() method","Other methods","Introduction to argparse","Other utilities","The add_argument() method","ArgumentParser objects","argparse vs. optparse","API documentation"],modules:{},descrefs:{"":{parse_args:[1,0],parse_known_args:[2,0],add_mutually_exclusive_group:[2,0],set_defaults:[2,0],FileType:[4,1],add_argument:[5,0],ArgumentParser:[6,1],add_subparsers:[2,0],add_argument_group:[2,0]}},filenames:["index","parse_args","other-methods","overview","other-utilities","add_argument","ArgumentParser","argparse-vs-optparse","api-docs"]}) |
1215 | \ No newline at end of file |
1216 | +Search.setIndex({desctypes:{"0":"method","1":"class"},terms:{all:[6,3,7,5,2],code:[0,7,6],partial:[8,7,2],messg:7,whatev:2,illustr:[7,5],global:6,four:5,prefix:[1,6,5],subclass:2,follow:[0,7,5,6,3],formatter_class:[8,6],whose:[5,6],typeerror:[],"const":[8,3,7,1,5],fancier:2,readabl:4,prefix_char:[8,7,6],program:[6,0,5,2,3],present:[7,1,2,5],sens:[5,6],worth:5,consum:[7,5],everi:3,string:[1,2,3,5,6,7],fals:[6,7,5,2],subcommand:[7,2],util:[8,0,4],parent_pars:6,retriev:[],default_:[],exact:7,implement:5,level:2,list:[1,2,3,5,6,7],"try":[7,6],item:[5,2],adjust:6,stderr:2,pleas:6,subparser_nam:2,bacon:1,dogmat:7,past:7,zero:[7,5],fyoyo:7,group1:2,pass:[1,2,4,5,6,7],append:5,compat:7,what:[3,7,1,6,5],abc:[7,5],sub:[8,7,2],neg:1,section:[6,7,5,2],advanc:7,brief:[6,5,2],current:[6,2],abbrevi:[8,1],version:5,"new":[7,1,6,5],method:[0,1,2,3,5,6,7,8],told:5,deriv:[7,5],gener:[0,7,5,6,3],never:[7,6],here:[7,1],let:2,inher:1,path:7,along:1,infil:[4,5],modifi:2,sinc:7,interpret:5,convert:[3,4,7,1,5],produc:[7,5,2],convers:5,pick:1,action:[1,2,3,5,6,7,8],weird:6,commonli:5,control:6,regardless:6,extra:[1,2],appli:5,modul:[0,7,5,3],prefer:7,filenam:5,api:[8,0,7,5],txt:[0,5,6],select:[5,2],add_argument_group:2,from:[1,2,3,5,6,7],describ:[6,5,2],would:[7,5],frobbl:[5,2],regist:2,two:[6,3,1,2,5],few:[7,5,2],call:[0,1,2,3,5,6,7],add_help:[8,7,6,2],recommend:2,taken:[7,1,5],rawtexthelpformatt:6,type:[0,1,2,3,4,5,6,7,8],tell:[3,1],more:[0,1,3,5,6,7],sort:[3,5,6],parser_a:2,parser_b:2,notic:[7,1],warn:5,flag:[8,7,5],indic:[6,5,2],particular:[7,5,2],known:7,hold:[3,5],easiest:[7,5,2],must:[1,6,5],dictat:7,none:[4,7,1,6,5],word:[6,2],dest:[1,2,3,5,7,8],work:[6,2],conceptu:2,remain:[3,7,5,2],itself:5,can:[0,1,2,3,4,5,6,7],def:[7,5,2],overrid:[7,6,2],traceback:6,prompt:1,puriti:7,give:[1,6],frabbl:3,share:[7,6],add_argu:[0,1,2,3,4,5,6,7,8],accept:[7,5,2],cautiou:1,want:[6,3,7,5,2],alwai:[6,5,2],multipl:[7,5,2],thing:5,rather:[1,6],anoth:[6,5,2],check_method:7,fooaction:[7,5],write:[0,7,6,3],how:[6,3,1,2,5],sever:[6,1,2],instead:[7,5,2],narg:[0,1,3,5,6,7,8],simpl:[0,7,5,3],updat:2,parser_abc:7,foo_pars:[7,6],overridden:6,mess:6,max:[3,1],after:[6,7,1,2,5],variant:2,invok:[6,3,7,5,2],befor:[5,6],wrong:1,okai:6,mai:[6,7,1,2,5],end:[7,5,2],associ:[5,2],xfoox:7,"0x013a2410":[],"short":[1,6,5],attempt:[7,1],practic:7,stdin:[4,5],explicit:5,correspond:[3,7],ambigu:1,caus:[5,6],callback:7,type_:[],maintain:[7,6],combin:[1,2],allow:[6,7,1,2,5],callabl:[7,5],order:2,origin:[7,6],least:[5,2],help:[0,1,2,3,5,6,7,8],over:[7,6],becaus:6,through:7,same:[7,5,6],hierarchi:7,metavar_:[],still:5,subparser2:2,subparser1:2,paramet:[7,5,6],perfect:5,style:1,interspers:7,group:[8,2],fit:6,better:[7,2],main:2,easier:1,them:[0,5,1,6,3],good:2,"return":[3,7,1,2,5],greater:[],thei:[7,1,6,5],python:[0,7,6,2],initi:[3,5],option_str:[7,5],now:[3,7],discuss:7,introduct:[0,3],choic:[1,2,3,5,7,8],allow_interspersed_arg:7,optionerror:7,name:[1,2,3,5,6,7,8],anyth:[7,5],choices_:[],separ:[1,2],easili:7,achiev:[1,6],mode:[4,7,5],each:[6,3,7,5,2],fulli:2,difficult:7,nbar:6,mean:[3,7,5,6],myprogram:6,replac:[7,6],idea:2,heavi:1,expect:[3,1,5],our:3,happen:7,beyond:[8,1],metavar:[0,1,3,5,7,8],special:[5,2],out:[0,4,5,6,3],variabl:7,accomplish:[1,6],referenc:6,space:[6,2],foo_bar:5,newli:1,parser_xyz:7,perfect_squar:5,print:[1,2,3,5,6,7,8],factori:[4,5],math:5,common:[3,5,6],optionvalueerror:7,worthwhil:7,situat:[1,5],given:6,argv:[8,3,1,6],standard:7,mmm:1,reason:7,base:7,dictionari:7,care:[7,2],indent:6,could:[1,5],omit:5,refus:7,keep:6,fromfile_prefix_char:[8,6,2],turn:3,place:6,isn:[7,5],retain:6,const_:[],assign:1,first:[5,6],oper:5,rang:[3,1],directli:5,carri:3,onc:[3,2],number:[7,1,2,5],restrict:5,instruct:3,alreadi:[7,1,6],construct:[7,6],wasn:5,open:[4,7,5,6],size:4,differ:[7,5,2],script:[3,2],top:2,sometim:[6,1,2],messag:[0,1,2,5,6,7],too:5,similarli:2,conveni:[7,5],"final":[],store:[3,5],monkei:7,option:[0,1,2,3,5,6,7,8],namespac:[1,2,3,4,5,6,7,8],copi:7,specifi:[0,1,2,3,5,6,7],pars:[0,1,2,3,5,7,8],store_tru:[3,7,1,2,5],exactli:[3,1,6],than:[6,7,1,2,5],format_usag:2,wide:6,kind:2,setattr:[7,5],whenev:[1,5],provid:[0,7,1,2,5],remov:6,charact:[7,1,6,5],str:5,were:[5,6],posit:[0,1,2,3,5,6,7],seri:[3,5],sai:7,abov:[6,0,1,2,3],"0x013a2380":[],group2:2,argument:[0,1,2,3,4,5,6,7,8],dash:7,add_pars:[7,2],manner:[3,7],have:[4,7,1,6,5],"__main__":[0,3],need:[6,7,5,2],seem:7,squar:5,equival:6,inform:[6,3,7,5,2],self:[7,5,2],append_const:5,also:[6,1,2,5],builtin:5,exampl:[0,1,2,3,5,6],take:[1,2,3,5,6,7],which:[6,7,1,2,5],singl:[1,2,3,5,6,7],uppercas:5,begin:[3,1],sure:[7,5,2],though:5,buffer:4,previou:[7,1],most:[6,3,7,5,2],regular:2,pair:[7,6],choos:[7,5],"class":[4,7,1,6,5],appear:2,don:[7,1,5],gather:5,request:[4,5,2],doe:[6,7,5,2],declar:7,determin:[1,2,3,5,6,7],occasion:6,sum:[0,1,3],"0x00b8fb18":[],parser_bar:2,show:[6,0,7,5,2],text:6,filetyp:[8,0,4,5],syntax:[8,7,1],particularli:[7,6,2],hack:7,find:[3,1,2],onli:[6,7,1,2,5],textual:6,parse_known_arg:2,just:[5,2],pretti:3,"true":[1,2,3,5,6,7],parser_foo:2,figur:5,start:[3,6],should:[0,2,3,5,6,7],store_const:[3,7,1,5],wood:1,dict:5,"__call__":[7,5],add_opt:7,variou:[5,6],get:[6,3,7,1,2],express:6,report:5,requir:[8,7,1,2,5],bar:[1,2,3,5,6,7],keyword:[1,2,3,5,6,7],baz:[7,5,2],dramat:7,yield:2,patch:7,store_fals:[5,2],whether:[5,6],bad:[1,5],calcul:6,bac:1,contain:[1,2,5,6,7,8],where:[0,5,6],set:[6,3,7,5,2],"float":[7,5,2],see:[1,2,3,5,6,7],arg:[0,1,2,3,4,5,6,7],close:0,extend:[7,5],correctli:6,someth:3,written:0,subdir:6,between:6,"import":[0,7,5,6,3],awai:5,badger:[7,1,2],across:6,attribut:[1,2,3,5,6,7],altern:6,parent:[8,7,6,2],xrang:[3,7,1,5],disallow:[7,6],extens:7,outfil:5,come:7,addit:[6,7,5,2],both:[7,1],last:[1,6],howev:[6,7,5,2],against:7,etc:[7,1,2,5],eas:5,mani:[7,5],whole:[],simpli:[6,7,1,2,5],point:7,argumentpars:[0,1,2,3,4,5,6,7,8],dispatch:7,featur:7,suppli:[6,3,7,5,2],respect:5,assum:[0,5,2,3],duplic:7,quit:[7,5],coupl:[6,2],addition:5,three:6,empti:1,implicit:7,accumul:[3,1],secret:7,much:[3,7,1,2,5],valu:[1,2,5,6,7,8],basic:5,unambigu:1,print_usag:2,popul:[1,2],strategi:6,epilog:[8,6],suppress:[7,5,6],xxx:[7,5,6],great:5,ani:[6,7,5,2],upgrad:[0,7],understand:4,togeth:[1,5],func:2,child:6,repetit:5,those:[7,1],"case":[3,1,2,5],therefor:5,look:[3,7,1],format_help:2,formatt:6,defin:[6,5,2],"while":[7,1,6,5],behavior:[3,5,6],error:[6,7,1,2,5],argpars:[0,1,2,3,4,5,6,7],advantag:[0,7],stdout:[0,4,5],readi:3,kwarg:[7,2],arg_lin:2,"__init__":7,clearli:1,perform:[5,2],make:[6,3,7,5,2],format:[6,7,5,2],sqrt:5,check:[7,1,2,5],handl:[7,5,2],complex:[7,5],help_:[],split:[1,2,3,5,6,7],document:[8,0,1],infer:5,dest_:[],complet:2,dedent:6,foo_bar_baz_pars:7,effect:2,rais:[5,6],user:[6,7,1,2,5],store_act:7,typic:[3,7,5,2],recent:6,appropri:[0,2,3,5,6,7],older:6,argumenttypeerror:5,thu:7,inherit:[7,6],likewis:6,without:2,command:[0,1,2,3,4,5,6,7,8],thi:[0,1,2,3,4,5,6,7],conflict:6,everyth:[7,1],sibl:2,usual:[6,7,5,2],identifi:5,execut:2,add_mutually_exclusive_group:2,note:[6,7,5,2],action_:[],exclus:[8,2],expos:7,had:7,except:[6,2],add:[0,2,3,5,6,7],valid:[7,5,2],remaining_arg:7,rawdescriptionhelpformatt:6,save:[0,3],match:[6,7,1,2,5],applic:[6,2],transpar:7,read:[6,5,2],textwrap:6,writabl:[4,5],built:[3,1],know:[7,5,2],print_help:[6,7,5,2],like:[1,2,3,5,6,7],insert:1,get_default:2,specif:6,arbitrari:5,whitespac:6,manual:7,resolv:6,integ:[0,5,7,1,3],collect:6,necessari:[3,7,5,2],either:[1,2,3,5,6,7],argumenterror:[7,6],output:[6,4,5,2],unnecessari:6,encount:[3,1,5],old:[6,2],often:5,"0x00b1f020":[],interact:1,some:[1,2,3,5,6,7],back:2,intern:5,mistak:1,proper:7,librari:7,absent:5,subpars:[7,2],avoid:5,normal:[1,2,5],definit:6,per:[6,2],exit:[0,1,2,5,6,7],prog:[1,2,5,6,7,8],foo:[1,2,3,5,6,7],refer:[1,6,5],nargs_:[],object:[0,1,2,3,4,5,6,7,8],run:[0,3],inspect:[3,2],usag:[0,1,2,5,6,7,8],argument_default:[8,6],found:1,add_subpars:[7,2],"__name__":[0,3],"super":7,xyzz:1,about:[6,3,7,5,2],actual:7,meth:[],callback_:7,optpars:[0,7],constructor:[7,6,2],commit:2,disabl:6,own:[6,7,5,2],xyz:[7,2],within:6,automat:[4,5,6],suppl:2,been:[3,7,5],strip:[5,2],wrap:6,chang:[6,7,5,2],mark:5,yyi:[5,6],your:[6,3,7,5,2],manag:3,inclus:5,fill:[3,6],log:0,wai:[6,7,1,2,5],spam:[7,1,2],support:[6,7,1,2,5],"long":[7,1,6,5],custom:[6,8,1,2,5],avail:[6,5,2],almost:[5,6],interfac:[0,7,5,3],includ:[6,7,1,2,5],lot:[7,2],parse_arg:[0,1,2,3,4,5,6,7,8],treat:[6,2],"function":[1,2,5],reduc:7,creation:[6,2],form:[3,7,5],tupl:[5,2],bufsiz:[4,5],continu:2,msg:5,parents_:[],"0x00b8fe78":[],line:[0,1,2,3,4,5,6,7],conflict_handl:[8,6],concaten:1,made:1,input:5,temp:5,possibl:5,"default":[0,1,2,3,5,6,7,8],checkout:2,argumentdefaultshelpformatt:6,displai:[6,7,5,2],below:[7,5,6],otherwis:6,similar:7,later:3,constant:5,creat:[0,1,2,3,4,5,6,7],"int":[0,1,2,3,5,6,7],descript:[0,2,3,5,6,8],parser:[0,1,2,3,4,5,6,7,8],"0x00b1f068":[],doesn:[7,5],strongli:2,exist:1,file:[0,2,3,4,5,6,7,8],xyzyx:2,simplest:1,probabl:5,again:7,mutual:[8,2],titl:2,when:[0,1,2,3,5,6,7],detail:[1,6,5],invalid:[8,7,1,5],other:[0,1,2,4,6,7,8],futur:2,scriptnam:0,varieti:1,test:7,set_default:[6,2],you:[1,2,3,5,6,7],bar_pars:[7,6],repeat:6,clean:6,why:7,consid:[5,6],"0x00adf020":[],svn:2,receiv:7,longer:[7,1,2],pseudo:[4,1],time:[7,5,2],backward:7,convert_arg_line_to_arg:[6,2]},titles:["Documentation","The parse_args() method","Other methods","Introduction to argparse","Other utilities","The add_argument() method","ArgumentParser objects","argparse vs. optparse","API documentation"],modules:{},descrefs:{"":{parse_args:[1,0],parse_known_args:[2,0],add_mutually_exclusive_group:[2,0],set_defaults:[2,0],FileType:[4,1],add_argument:[5,0],ArgumentParser:[6,1],convert_arg_line_to_args:[2,0],get_default:[2,0],add_subparsers:[2,0],add_argument_group:[2,0]}},filenames:["index","parse_args","other-methods","overview","other-utilities","add_argument","ArgumentParser","argparse-vs-optparse","api-docs"]}) |
1217 | \ No newline at end of file |
1218 | |
1219 | === modified file 'doc/source/ArgumentParser.rst' |
1220 | --- doc/source/ArgumentParser.rst 2009-10-12 18:04:37 +0000 |
1221 | +++ doc/source/ArgumentParser.rst 2010-03-11 19:12:27 +0000 |
1222 | @@ -1,13 +1,12 @@ |
1223 | ArgumentParser objects |
1224 | ====================== |
1225 | |
1226 | -.. class:: ArgumentParser([description], [epilog], [prog], [usage], [version], [add_help], [argument_default], [parents], [prefix_chars], [conflict_handler], [formatter_class]) |
1227 | +.. class:: ArgumentParser([description], [epilog], [prog], [usage], [add_help], [argument_default], [parents], [prefix_chars], [conflict_handler], [formatter_class]) |
1228 | |
1229 | - Create a new :class:ArgumentParser object. Each parameter has its own more detailed description below, but in short they are: |
1230 | + Create a new :class:`ArgumentParser` object. Each parameter has its own more detailed description below, but in short they are: |
1231 | |
1232 | * description_ - Text to display before the argument help. |
1233 | * epilog_ - Text to display after the argument help. |
1234 | - * version_ - A version number used to add a -v/--version option to the parser. |
1235 | * add_help_ - Add a -h/--help option to the parser. (default: True) |
1236 | * argument_default_ - Set the global default value for arguments. (default: None) |
1237 | * parents_ - A list of :class:ArgumentParser objects whose arguments should also be included. |
1238 | @@ -59,24 +58,6 @@ |
1239 | As with the description_ argument, the ``epilog=`` text is by default line-wrapped, but this behavior can be adjusted with the formatter_class_ argument to ArgumentParser. |
1240 | |
1241 | |
1242 | -version |
1243 | -------- |
1244 | - |
1245 | -Programs which want to display the program version at the command line can supply a version message as the ``version=`` argument to ArgumentParser. This will add a ``-v/--version`` option to the ArgumentParser that can be invoked to print the version string:: |
1246 | - |
1247 | - >>> parser = argparse.ArgumentParser(prog='PROG', version='%(prog)s 3.5') |
1248 | - >>> parser.print_help() |
1249 | - usage: PROG [-h] [-v] |
1250 | - |
1251 | - optional arguments: |
1252 | - -h, --help show this help message and exit |
1253 | - -v, --version show program's version number and exit |
1254 | - >>> parser.parse_args(['-v']) |
1255 | - PROG 3.5 |
1256 | - |
1257 | -Note you can use the ``%(prog)s`` format specifier to insert the program name into the version string. |
1258 | - |
1259 | - |
1260 | add_help |
1261 | -------- |
1262 | |
1263 | @@ -119,7 +100,6 @@ |
1264 | Namespace(bar='Y', f='X') |
1265 | |
1266 | The ``prefix_chars=`` argument defaults to ``'-'``. Supplying a set of characters that does not include ``'-'`` will cause ``-f/--foo`` options to be disallowed. |
1267 | -Note that most parent parsers will specify :meth:`add_help` ``=False``. Otherwise, the ArgumentParser will see two ``-h/--help`` options (one in the parent and one in the child) and raise an error. |
1268 | |
1269 | |
1270 | fromfile_prefix_chars |
1271 | @@ -134,12 +114,11 @@ |
1272 | >>> parser.parse_args(['-f', 'foo', '@args.txt']) |
1273 | Namespace(f='bar') |
1274 | |
1275 | -Arguments read from a file must be one per line (with each whole line being considered a single argument) and are treated as if they were in the same place as the original file referencing argument on the command line. |
1276 | +Arguments read from a file must by default be one per line (but see also :meth:`convert_arg_line_to_args`) and are treated as if they were in the same place as the original file referencing argument on the command line. |
1277 | So in the example above, the expression ``['-f', 'foo', '@args.txt']`` is considered equivalent to the expression ``['-f', 'foo', '-f', 'bar']``. |
1278 | |
1279 | The ``fromfile_prefix_chars=`` argument defaults to ``None``, meaning that arguments will never be treated as file references. |
1280 | |
1281 | - |
1282 | argument_default |
1283 | ---------------- |
1284 | |
1285 | @@ -172,6 +151,8 @@ |
1286 | >>> bar_parser.parse_args(['--bar', 'YYY']) |
1287 | Namespace(bar='YYY', parent=None) |
1288 | |
1289 | +Note that most parent parsers will specify ``add_help=False``. Otherwise, the ArgumentParser will see two ``-h/--help`` options (one in the parent and one in the child) and raise an error. |
1290 | + |
1291 | |
1292 | formatter_class |
1293 | --------------- |
1294 | |
1295 | === modified file 'doc/source/add_argument.rst' |
1296 | --- doc/source/add_argument.rst 2009-08-27 15:36:52 +0000 |
1297 | +++ doc/source/add_argument.rst 2010-03-11 19:12:27 +0000 |
1298 | @@ -85,6 +85,14 @@ |
1299 | >>> parser.parse_args('--str --int'.split()) |
1300 | Namespace(types=[<type 'str'>, <type 'int'>]) |
1301 | |
1302 | +* ``'version'`` - This expects a ``version=`` keyword argument in the :meth:`add_argument` call, and prints version information and exits when invoked. |
1303 | + |
1304 | + >>> import argparse |
1305 | + >>> parser = argparse.ArgumentParser(prog='PROG') |
1306 | + >>> parser.add_argument('-v', '--version', action='version', version='%(prog)s 2.0') |
1307 | + >>> parser.parse_args(['-v']) |
1308 | + PROG 2.0 |
1309 | + |
1310 | You can also specify an arbitrary action by passing an object that implements the Action API. The easiest way to do this is to extend ``argparse.Action``, supplying an appropriate ``__call__`` method. The ``__call__`` method accepts four parameters: |
1311 | |
1312 | * ``parser`` - The ArgumentParser object which contains this action. |
1313 | @@ -236,7 +244,8 @@ |
1314 | ... value = int(string) |
1315 | ... sqrt = math.sqrt(value) |
1316 | ... if sqrt != int(sqrt): |
1317 | - ... raise TypeError() |
1318 | + ... msg = "%r is not a perfect square" % string |
1319 | + ... raise argparse.ArgumentTypeError(msg) |
1320 | ... return value |
1321 | ... |
1322 | >>> parser = argparse.ArgumentParser(prog='PROG') |
1323 | @@ -245,7 +254,7 @@ |
1324 | Namespace(foo=9) |
1325 | >>> parser.parse_args('7'.split()) |
1326 | usage: PROG [-h] foo |
1327 | - PROG: error: argument foo: invalid perfect_square value: '7' |
1328 | + PROG: error: argument foo: '7' is not a perfect square |
1329 | |
1330 | Note that if your type-checking function is just checking for a particular set of values, it may be more convenient to use the choices_ keyword argument:: |
1331 | |
1332 | |
1333 | === modified file 'doc/source/conf.py' |
1334 | --- doc/source/conf.py 2009-10-12 18:04:37 +0000 |
1335 | +++ doc/source/conf.py 2010-03-11 19:12:27 +0000 |
1336 | @@ -45,9 +45,9 @@ |
1337 | # built documents. |
1338 | # |
1339 | # The short X.Y version. |
1340 | -version = '1.0.1' |
1341 | +version = '1.1' |
1342 | # The full version, including alpha/beta/rc tags. |
1343 | -release = '1.0.1' |
1344 | +release = '1.1' |
1345 | |
1346 | # The language for content autogenerated by Sphinx. Refer to documentation |
1347 | # for a list of supported languages. |
1348 | |
1349 | === modified file 'doc/source/other-methods.rst' |
1350 | --- doc/source/other-methods.rst 2009-08-27 15:36:52 +0000 |
1351 | +++ doc/source/other-methods.rst 2010-03-11 19:12:27 +0000 |
1352 | @@ -67,6 +67,14 @@ |
1353 | |
1354 | Parser-level defaults can be particularly useful when you're working with multiple parsers. See the :meth:`add_subparsers` method for an example of this type. |
1355 | |
1356 | +.. method:: get_default(dest) |
1357 | + |
1358 | + Get the default value for a namespace attribute, as set by either :meth:`add_argument` or by :meth:`set_defaults`:: |
1359 | + |
1360 | + >>> parser = argparse.ArgumentParser() |
1361 | + >>> parser.add_argument('--foo', default='badger') |
1362 | + >>> parser.get_default('foo') |
1363 | + 'badger' |
1364 | |
1365 | Sub-commands |
1366 | ------------ |
1367 | @@ -269,3 +277,19 @@ |
1368 | Note that currently mutually exclusive argument groups do not support the ``title`` and ``description`` arguments of :meth:`add_argument_group`. This may change in the future however, so you are *strongly* recommended to specify ``required`` as a keyword argument if you use it. |
1369 | |
1370 | |
1371 | +Customizing file parsing |
1372 | +------------------------ |
1373 | + |
1374 | +.. method:: convert_arg_line_to_args(arg_line) |
1375 | + |
1376 | + Arguments that are read from a file (see the ``fromfile_prefix_chars`` keyword argument to the :class:`ArgumentParser` constructor) are read one argument per line. If you need fancier parsing, then you can subclass the :class:`ArgumentParser` and override the :meth:`convert_arg_line_to_args` method. |
1377 | + |
1378 | + This method takes a single argument ``arg_line`` which is a string read from the argument file. It returns a list of arguments parsed from this string. The method is called once per line read from the argument file, in order. |
1379 | + |
1380 | + A useful override of this method is one that treats each space-separated word as an argument:: |
1381 | + |
1382 | + def convert_arg_line_to_args(self, arg_line): |
1383 | + for arg in arg_line.split(): |
1384 | + if not arg.strip(): |
1385 | + continue |
1386 | + yield arg |
1387 | |
1388 | === modified file 'setup.py' |
1389 | --- setup.py 2009-10-12 18:04:37 +0000 |
1390 | +++ setup.py 2010-03-11 19:12:27 +0000 |
1391 | @@ -24,10 +24,12 @@ |
1392 | readme_file = open(os.path.join(os.path.dirname(__file__), 'README.txt')) |
1393 | readme_text = readme_file.read() |
1394 | readme_file.close() |
1395 | - main_desc_regexp = r'^argparse\s*[\d.]*\s*\n=======+\s*\n(.*)Requirements ' |
1396 | - main_desc, = re.findall(main_desc_regexp, readme_text, re.DOTALL) |
1397 | + main_desc_regexp = r'^argparse\s*[\w.]*\s*\n=======+\s*\n(.*)Requirements ' |
1398 | + main_desc_re_c = re.compile(main_desc_regexp, re.DOTALL) |
1399 | + main_desc, = main_desc_re_c.findall(readme_text) |
1400 | avail_desc_regexp = r'Availability & Documentation\s*\n-----+\s*\n(.*)' |
1401 | - avail_desc, = re.findall(avail_desc_regexp, readme_text, re.DOTALL) |
1402 | + avail_desc_re_c = re.compile(avail_desc_regexp, re.DOTALL) |
1403 | + avail_desc, = avail_desc_re_c.findall(readme_text) |
1404 | return main_desc + avail_desc |
1405 | |
1406 | distutils.core.setup( |
1407 | |
1408 | === modified file 'test/test_argparse.py' |
1409 | --- test/test_argparse.py 2009-10-12 18:04:37 +0000 |
1410 | +++ test/test_argparse.py 2010-03-11 19:12:27 +0000 |
1411 | @@ -52,6 +52,21 @@ |
1412 | message='BaseException.message has been deprecated as of Python 2.6', |
1413 | category=DeprecationWarning) |
1414 | |
1415 | +# silence warnings about version argument - these are expected |
1416 | +import warnings |
1417 | +warnings.filterwarnings( |
1418 | + action='ignore', |
1419 | + message='The "version" argument to ArgumentParser is deprecated.', |
1420 | + category=DeprecationWarning) |
1421 | +warnings.filterwarnings( |
1422 | + action='ignore', |
1423 | + message='The format_version method is deprecated', |
1424 | + category=DeprecationWarning) |
1425 | +warnings.filterwarnings( |
1426 | + action='ignore', |
1427 | + message='The print_version method is deprecated', |
1428 | + category=DeprecationWarning) |
1429 | + |
1430 | |
1431 | class TestCase(unittest.TestCase): |
1432 | |
1433 | @@ -109,31 +124,43 @@ |
1434 | |
1435 | class ArgumentParserError(Exception): |
1436 | |
1437 | - def __init__(self, message, error_code): |
1438 | - Exception.__init__(self, message) |
1439 | + def __init__(self, message, stdout=None, stderr=None, error_code=None): |
1440 | + Exception.__init__(self, message, stdout, stderr) |
1441 | self.message = message |
1442 | + self.stdout = stdout |
1443 | + self.stderr = stderr |
1444 | self.error_code = error_code |
1445 | |
1446 | |
1447 | -def stderr_to_parser_error(func, *args, **kwargs): |
1448 | - # if this is being called recursively and stderr is already being |
1449 | +def stderr_to_parser_error(parse_args, *args, **kwargs): |
1450 | + # if this is being called recursively and stderr or stdout is already being |
1451 | # redirected, simply call the function and let the enclosing function |
1452 | # catch the exception |
1453 | - if isinstance(sys.stderr, StringIO): |
1454 | - return func(*args, **kwargs) |
1455 | + if isinstance(sys.stderr, StringIO) or isinstance(sys.stdout, StringIO): |
1456 | + return parse_args(*args, **kwargs) |
1457 | |
1458 | # if this is not being called recursively, redirect stderr and |
1459 | # use it as the ArgumentParserError message |
1460 | + old_stdout = sys.stdout |
1461 | old_stderr = sys.stderr |
1462 | + sys.stdout = StringIO() |
1463 | sys.stderr = StringIO() |
1464 | try: |
1465 | try: |
1466 | - return func(*args, **kwargs) |
1467 | + result = parse_args(*args, **kwargs) |
1468 | + for key in list(vars(result)): |
1469 | + if getattr(result, key) is sys.stdout: |
1470 | + setattr(result, key, old_stdout) |
1471 | + if getattr(result, key) is sys.stderr: |
1472 | + setattr(result, key, old_stderr) |
1473 | + return result |
1474 | except SystemExit: |
1475 | code = sys.exc_info()[1].code |
1476 | - message = sys.stderr.getvalue() |
1477 | - raise ArgumentParserError(message, code) |
1478 | + stdout = sys.stdout.getvalue() |
1479 | + stderr = sys.stderr.getvalue() |
1480 | + raise ArgumentParserError("SystemExit", stdout, stderr, code) |
1481 | finally: |
1482 | + sys.stdout = old_stdout |
1483 | sys.stderr = old_stderr |
1484 | |
1485 | |
1486 | @@ -175,6 +202,8 @@ |
1487 | # default parser signature is empty |
1488 | if not hasattr(cls, 'parser_signature'): |
1489 | cls.parser_signature = Sig() |
1490 | + if not hasattr(cls, 'parser_class'): |
1491 | + cls.parser_class = ErrorRaisingArgumentParser |
1492 | |
1493 | # --------------------------------------- |
1494 | # functions for adding optional arguments |
1495 | @@ -238,7 +267,7 @@ |
1496 | def _get_parser(self, tester): |
1497 | args = tester.parser_signature.args |
1498 | kwargs = tester.parser_signature.kwargs |
1499 | - parser = ErrorRaisingArgumentParser(*args, **kwargs) |
1500 | + parser = tester.parser_class(*args, **kwargs) |
1501 | self._add_arguments(parser, tester.argument_signatures) |
1502 | return parser |
1503 | |
1504 | @@ -401,6 +430,25 @@ |
1505 | ] |
1506 | |
1507 | |
1508 | +class TestOptionalsDoubleDashPrefixMatch(ParserTestCase): |
1509 | + """Tests when one double-dash option string is a prefix of another""" |
1510 | + |
1511 | + argument_signatures = [ |
1512 | + Sig('--badger', action='store_true'), |
1513 | + Sig('--ba'), |
1514 | + ] |
1515 | + failures = ['--bar', '--b', '--ba', '--b=2', '--badge 5'] |
1516 | + successes = [ |
1517 | + ('', NS(badger=False, ba=None)), |
1518 | + ('--ba X', NS(badger=False, ba='X')), |
1519 | + ('--ba=X', NS(badger=False, ba='X')), |
1520 | + ('--bad', NS(badger=True, ba=None)), |
1521 | + ('--badg', NS(badger=True, ba=None)), |
1522 | + ('--badge', NS(badger=True, ba=None)), |
1523 | + ('--badger', NS(badger=True, ba=None)), |
1524 | + ] |
1525 | + |
1526 | + |
1527 | class TestOptionalsSingleDoubleDash(ParserTestCase): |
1528 | """Test an Optional with single- and double-dash option strings""" |
1529 | |
1530 | @@ -1121,6 +1169,23 @@ |
1531 | ] |
1532 | |
1533 | |
1534 | +class TestOptionalsAlmostNumericAndPositionals(ParserTestCase): |
1535 | + """Tests negative number args when almost numeric options are present""" |
1536 | + |
1537 | + argument_signatures = [ |
1538 | + Sig('x', nargs='?'), |
1539 | + Sig('-k4', dest='y', action='store_true'), |
1540 | + ] |
1541 | + failures = ['-k3'] |
1542 | + successes = [ |
1543 | + ('', NS(x=None, y=False)), |
1544 | + ('-2', NS(x='-2', y=False)), |
1545 | + ('a', NS(x='a', y=False)), |
1546 | + ('-k4', NS(x=None, y=True)), |
1547 | + ('-k4 a', NS(x='a', y=True)), |
1548 | + ] |
1549 | + |
1550 | + |
1551 | class TestEmptyAndSpaceContainingArguments(ParserTestCase): |
1552 | |
1553 | argument_signatures = [ |
1554 | @@ -1140,6 +1205,25 @@ |
1555 | ] |
1556 | |
1557 | |
1558 | +class TestPrefixCharacterOnlyArguments(ParserTestCase): |
1559 | + |
1560 | + parser_signature = Sig(prefix_chars='-+') |
1561 | + argument_signatures = [ |
1562 | + Sig('-', dest='x', nargs='?', const='badger'), |
1563 | + Sig('+', dest='y', type=int, default=42), |
1564 | + Sig('-+-', dest='z', action='store_true'), |
1565 | + ] |
1566 | + failures = ['-y', '+ -'] |
1567 | + successes = [ |
1568 | + ('', NS(x=None, y=42, z=False)), |
1569 | + ('-', NS(x='badger', y=42, z=False)), |
1570 | + ('- X', NS(x='X', y=42, z=False)), |
1571 | + ('+ -3', NS(x=None, y=-3, z=False)), |
1572 | + ('-+-', NS(x=None, y=42, z=True)), |
1573 | + ('- ===', NS(x='===', y=42, z=False)), |
1574 | + ] |
1575 | + |
1576 | + |
1577 | class TestNargsZeroOrMore(ParserTestCase): |
1578 | """Tests specifying an args for an Optional that accepts zero or more""" |
1579 | |
1580 | @@ -1156,6 +1240,19 @@ |
1581 | ] |
1582 | |
1583 | |
1584 | +class TestNargsRemainder(ParserTestCase): |
1585 | + """Tests specifying a positional with nargs=REMAINDER""" |
1586 | + |
1587 | + argument_signatures = [Sig('x'), Sig('y', nargs='...'), Sig('-z')] |
1588 | + failures = ['', '-z', '-z Z'] |
1589 | + successes = [ |
1590 | + ('X', NS(x='X', y=[], z=None)), |
1591 | + ('-z Z X', NS(x='X', y=[], z='Z')), |
1592 | + ('X A B -z Z', NS(x='X', y=['A', 'B', '-z', 'Z'], z=None)), |
1593 | + ('X Y --foo', NS(x='X', y=['Y', '--foo'], z=None)), |
1594 | + ] |
1595 | + |
1596 | + |
1597 | class TestOptionLike(ParserTestCase): |
1598 | """Tests options that may or may not be arguments""" |
1599 | |
1600 | @@ -1276,6 +1373,37 @@ |
1601 | ] |
1602 | |
1603 | |
1604 | +class TestArgumentsFromFileConverter(TempDirMixin, ParserTestCase): |
1605 | + """Test reading arguments from a file""" |
1606 | + |
1607 | + def setUp(self): |
1608 | + super(TestArgumentsFromFileConverter, self).setUp() |
1609 | + file_texts = [ |
1610 | + ('hello', 'hello world!\n'), |
1611 | + ] |
1612 | + for path, text in file_texts: |
1613 | + file = open(path, 'w') |
1614 | + file.write(text) |
1615 | + file.close() |
1616 | + |
1617 | + class FromFileConverterArgumentParser(ErrorRaisingArgumentParser): |
1618 | + |
1619 | + def convert_arg_line_to_args(self, arg_line): |
1620 | + for arg in arg_line.split(): |
1621 | + if not arg.strip(): |
1622 | + continue |
1623 | + yield arg |
1624 | + parser_class = FromFileConverterArgumentParser |
1625 | + parser_signature = Sig(fromfile_prefix_chars='@') |
1626 | + argument_signatures = [ |
1627 | + Sig('y', nargs='+'), |
1628 | + ] |
1629 | + failures = [] |
1630 | + successes = [ |
1631 | + ('@hello X', NS(y=['hello', 'world!', 'X'])), |
1632 | + ] |
1633 | + |
1634 | + |
1635 | # ===================== |
1636 | # Type conversion tests |
1637 | # ===================== |
1638 | @@ -1718,10 +1846,10 @@ |
1639 | self.parser.parse_args(args_str.split()) |
1640 | except ArgumentParserError: |
1641 | err = sys.exc_info()[1] |
1642 | - if err.message != expected_help: |
1643 | + if err.stdout != expected_help: |
1644 | print(repr(expected_help)) |
1645 | - print(repr(err.message)) |
1646 | - self.assertEqual(err.message, expected_help) |
1647 | + print(repr(err.stdout)) |
1648 | + self.assertEqual(err.stdout, expected_help) |
1649 | |
1650 | def test_subparser1_help(self): |
1651 | self._test_subparser_help('5.0 1 -h', textwrap.dedent('''\ |
1652 | @@ -2449,6 +2577,50 @@ |
1653 | self.assertEqual(NS(w='WW', x='X', y='YY', z='Z'), |
1654 | parser.parse_args([])) |
1655 | |
1656 | +# ================= |
1657 | +# Get default tests |
1658 | +# ================= |
1659 | + |
1660 | +class TestGetDefault(TestCase): |
1661 | + |
1662 | + def test_get_default(self): |
1663 | + parser = ErrorRaisingArgumentParser() |
1664 | + self.assertEqual(None, parser.get_default("foo")) |
1665 | + self.assertEqual(None, parser.get_default("bar")) |
1666 | + |
1667 | + parser.add_argument("--foo") |
1668 | + self.assertEqual(None, parser.get_default("foo")) |
1669 | + self.assertEqual(None, parser.get_default("bar")) |
1670 | + |
1671 | + parser.add_argument("--bar", type=int, default=42) |
1672 | + self.assertEqual(None, parser.get_default("foo")) |
1673 | + self.assertEqual(42, parser.get_default("bar")) |
1674 | + |
1675 | + parser.set_defaults(foo="badger") |
1676 | + self.assertEqual("badger", parser.get_default("foo")) |
1677 | + self.assertEqual(42, parser.get_default("bar")) |
1678 | + |
1679 | +# ========================== |
1680 | +# Namespace 'contains' tests |
1681 | +# ========================== |
1682 | + |
1683 | +class TestNamespaceContainsSimple(TestCase): |
1684 | + |
1685 | + def test_empty(self): |
1686 | + ns = argparse.Namespace() |
1687 | + self.assertEquals('' in ns, False) |
1688 | + self.assertEquals('' not in ns, True) |
1689 | + self.assertEquals('x' in ns, False) |
1690 | + |
1691 | + def test_non_empty(self): |
1692 | + ns = argparse.Namespace(x=1, y=2) |
1693 | + self.assertEquals('x' in ns, True) |
1694 | + self.assertEquals('x' not in ns, False) |
1695 | + self.assertEquals('y' in ns, True) |
1696 | + self.assertEquals('' in ns, False) |
1697 | + self.assertEquals('xx' in ns, False) |
1698 | + self.assertEquals('z' in ns, False) |
1699 | + |
1700 | # ===================== |
1701 | # Help formatting tests |
1702 | # ===================== |
1703 | @@ -2461,8 +2633,9 @@ |
1704 | |
1705 | class AddTests(object): |
1706 | |
1707 | - def __init__(self, test_class, func_suffix): |
1708 | + def __init__(self, test_class, func_suffix, std_name): |
1709 | self.func_suffix = func_suffix |
1710 | + self.std_name = std_name |
1711 | |
1712 | for test_func in [self.test_format, |
1713 | self.test_print, |
1714 | @@ -2513,13 +2686,13 @@ |
1715 | def test_print(self, tester): |
1716 | parser = self._get_parser(tester) |
1717 | print_ = getattr(parser, 'print_%s' % self.func_suffix) |
1718 | - oldstderr = sys.stderr |
1719 | - sys.stderr = StringIO() |
1720 | + old_stream = getattr(sys, self.std_name) |
1721 | + setattr(sys, self.std_name, StringIO()) |
1722 | try: |
1723 | print_() |
1724 | - parser_text = sys.stderr.getvalue() |
1725 | + parser_text = getattr(sys, self.std_name).getvalue() |
1726 | finally: |
1727 | - sys.stderr = oldstderr |
1728 | + setattr(sys, self.std_name, old_stream) |
1729 | self._test(tester, parser_text) |
1730 | |
1731 | def test_print_file(self, tester): |
1732 | @@ -2531,8 +2704,10 @@ |
1733 | self._test(tester, parser_text) |
1734 | |
1735 | # add tests for {format,print}_{usage,help,version} |
1736 | - for func_suffix in ['usage', 'help', 'version']: |
1737 | - AddTests(cls, func_suffix) |
1738 | + for func_suffix, std_name in [('usage', 'stdout'), |
1739 | + ('help', 'stdout'), |
1740 | + ('version', 'stderr')]: |
1741 | + AddTests(cls, func_suffix, std_name) |
1742 | |
1743 | bases = TestCase, |
1744 | HelpTestCase = TestHelpFormattingMetaclass('HelpTestCase', bases, {}) |
1745 | @@ -3125,7 +3300,7 @@ |
1746 | |
1747 | parser_signature = Sig(prog='PROG') |
1748 | argument_signatures = [ |
1749 | - Sig('-x', type='int', |
1750 | + Sig('-x', type=int, |
1751 | help='x %(prog)s %(default)s %(type)s %%'), |
1752 | Sig('-y', action='store_const', default=42, const='XXX', |
1753 | help='y %(prog)s %(default)s %(const)s'), |
1754 | @@ -3595,9 +3770,31 @@ |
1755 | self.assertValueError('--') |
1756 | self.assertValueError('---') |
1757 | |
1758 | + def test_invalid_type(self): |
1759 | + self.assertValueError('--foo', type='int') |
1760 | + |
1761 | def test_invalid_action(self): |
1762 | - self.assertTypeError('-x', action='foo') |
1763 | - self.assertTypeError('foo', action='baz') |
1764 | + self.assertValueError('-x', action='foo') |
1765 | + self.assertValueError('foo', action='baz') |
1766 | + parser = argparse.ArgumentParser() |
1767 | + try: |
1768 | + parser.add_argument("--foo", action="store-true") |
1769 | + except ValueError: |
1770 | + e = sys.exc_info()[1] |
1771 | + expected = 'unknown action' |
1772 | + msg = 'expected %r, found %r' % (expected, e) |
1773 | + self.failUnless(expected in str(e), msg) |
1774 | + |
1775 | + def test_multiple_dest(self): |
1776 | + parser = argparse.ArgumentParser() |
1777 | + parser.add_argument(dest='foo') |
1778 | + try: |
1779 | + parser.add_argument('bar', dest='baz') |
1780 | + except ValueError: |
1781 | + e = sys.exc_info()[1] |
1782 | + expected = 'dest supplied twice for positional argument' |
1783 | + msg = 'expected %r, found %r' % (expected, e) |
1784 | + self.failUnless(expected in str(e), msg) |
1785 | |
1786 | def test_no_argument_actions(self): |
1787 | for action in ['store_const', 'store_true', 'store_false', |
1788 | @@ -3754,24 +3951,23 @@ |
1789 | class TestOptionalsHelpVersionActions(TestCase): |
1790 | """Test the help and version actions""" |
1791 | |
1792 | - def _get_error_message(self, func, *args, **kwargs): |
1793 | + def _get_error(self, func, *args, **kwargs): |
1794 | try: |
1795 | func(*args, **kwargs) |
1796 | except ArgumentParserError: |
1797 | - err = sys.exc_info()[1] |
1798 | - return err.message |
1799 | + return sys.exc_info()[1] |
1800 | else: |
1801 | self.assertRaises(ArgumentParserError, func, *args, **kwargs) |
1802 | |
1803 | def assertPrintHelpExit(self, parser, args_str): |
1804 | self.assertEqual( |
1805 | parser.format_help(), |
1806 | - self._get_error_message(parser.parse_args, args_str.split())) |
1807 | + self._get_error(parser.parse_args, args_str.split()).stdout) |
1808 | |
1809 | def assertPrintVersionExit(self, parser, args_str): |
1810 | self.assertEqual( |
1811 | parser.format_version(), |
1812 | - self._get_error_message(parser.parse_args, args_str.split())) |
1813 | + self._get_error(parser.parse_args, args_str.split()).stderr) |
1814 | |
1815 | def assertArgumentParserError(self, parser, *args): |
1816 | self.assertRaises(ArgumentParserError, parser.parse_args, args) |
1817 | @@ -3783,6 +3979,11 @@ |
1818 | self.assertPrintVersionExit(parser, '-v') |
1819 | self.assertPrintVersionExit(parser, '--version') |
1820 | |
1821 | + def test_version_format(self): |
1822 | + parser = ErrorRaisingArgumentParser(prog='PPP', version='%(prog)s 3.5') |
1823 | + msg = self._get_error(parser.parse_args, ['-v']).stderr |
1824 | + self.assertEqual('PPP 3.5\n', msg) |
1825 | + |
1826 | def test_version_no_help(self): |
1827 | parser = ErrorRaisingArgumentParser(add_help=False, version='1.0') |
1828 | self.assertArgumentParserError(parser, '-h') |
1829 | @@ -3790,6 +3991,12 @@ |
1830 | self.assertPrintVersionExit(parser, '-v') |
1831 | self.assertPrintVersionExit(parser, '--version') |
1832 | |
1833 | + def test_version_action(self): |
1834 | + parser = ErrorRaisingArgumentParser(prog='XXX') |
1835 | + parser.add_argument('-V', action='version', version='%(prog)s 3.7') |
1836 | + msg = self._get_error(parser.parse_args, ['-V']).stderr |
1837 | + self.assertEqual('XXX 3.7\n', msg) |
1838 | + |
1839 | def test_no_help(self): |
1840 | parser = ErrorRaisingArgumentParser(add_help=False) |
1841 | self.assertArgumentParserError(parser, '-h') |
1842 | @@ -3916,11 +4123,16 @@ |
1843 | |
1844 | class TestEncoding(TestCase): |
1845 | |
1846 | + def _test_module_encoding(self, path): |
1847 | + path, _ = os.path.splitext(path) |
1848 | + path += ".py" |
1849 | + codecs.open(path, 'r', 'utf8').read() |
1850 | + |
1851 | def test_argparse_module_encoding(self): |
1852 | - text = codecs.open(argparse.__file__, 'r', 'utf8').read() |
1853 | + self._test_module_encoding(argparse.__file__) |
1854 | |
1855 | def test_test_argparse_module_encoding(self): |
1856 | - text = codecs.open(__file__, 'r', 'utf8').read() |
1857 | + self._test_module_encoding(__file__) |
1858 | |
1859 | # =================== |
1860 | # ArgumentError tests |
1861 | @@ -3933,6 +4145,28 @@ |
1862 | error = argparse.ArgumentError(None, msg) |
1863 | self.failUnlessEqual(str(error), msg) |
1864 | |
1865 | +# ======================= |
1866 | +# ArgumentTypeError tests |
1867 | +# ======================= |
1868 | + |
1869 | +class TestArgumentError(TestCase): |
1870 | + |
1871 | + def test_argument_type_error(self): |
1872 | + |
1873 | + def spam(string): |
1874 | + raise argparse.ArgumentTypeError('spam!') |
1875 | + |
1876 | + parser = ErrorRaisingArgumentParser(prog='PROG', add_help=False) |
1877 | + parser.add_argument('x', type=spam) |
1878 | + try: |
1879 | + parser.parse_args(['XXX']) |
1880 | + except ArgumentParserError: |
1881 | + expected = 'usage: PROG x\nPROG: error: argument x: spam!\n' |
1882 | + msg = sys.exc_info()[1].stderr |
1883 | + self.failUnlessEqual(expected, msg) |
1884 | + else: |
1885 | + self.fail() |
1886 | + |
1887 | # ====================== |
1888 | # parse_known_args tests |
1889 | # ====================== |
1890 | @@ -3957,5 +4191,16 @@ |
1891 | self.failUnlessEqual(NS(v=3, spam=True, badger="B"), args) |
1892 | self.failUnlessEqual(["C", "--foo", "4"], extras) |
1893 | |
1894 | +# ============================ |
1895 | +# from argparse import * tests |
1896 | +# ============================ |
1897 | + |
1898 | +class TestImportStar(TestCase): |
1899 | + |
1900 | + def test(self): |
1901 | + for name in argparse.__all__: |
1902 | + self.failUnless(hasattr(argparse, name)) |
1903 | + |
1904 | + |
1905 | if __name__ == '__main__': |
1906 | unittest.main() |
On Friday 12 Mar 2010 00:36:31 Barry Warsaw wrote:
> You have been requested to review the proposed merge of
> lp:~barry/argparse/11ubuntu into lp:ubuntu/argparse.
>
> Updates argparse to upstream version 1.1
Hello barry,
argparse 1.1 was uploaded to Debian around a week back. It is in unstable
right now and should move to testing in a day or two.
Regards, www.researchut. com
Ritesh
--
Ritesh Raj Sarraf
RESEARCHUT - http://
"Necessity is the mother of invention."