Issue #23921: Standardized documentation whitespace formatting.

Original patch by James Edwards.
This commit is contained in:
Serhiy Storchaka 2016-05-10 12:01:23 +03:00
parent 387235085c
commit dba903993a
63 changed files with 445 additions and 409 deletions

View file

@ -25,7 +25,7 @@ GNU/POSIX syntax, and additionally generates usage and help messages for you.
Here's an example of using :mod:`optparse` in a simple script::
from optparse import OptionParser
[...]
...
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename",
help="write report to FILE", metavar="FILE")
@ -252,7 +252,7 @@ First, you need to import the OptionParser class; then, early in the main
program, create an OptionParser instance::
from optparse import OptionParser
[...]
...
parser = OptionParser()
Then you can start defining options. The basic syntax is::
@ -718,7 +718,7 @@ you can call :func:`OptionParser.error` to signal an application-defined error
condition::
(options, args) = parser.parse_args()
[...]
...
if options.a and options.b:
parser.error("options -a and -b are mutually exclusive")
@ -758,7 +758,7 @@ Putting it all together
Here's what :mod:`optparse`\ -based scripts usually look like::
from optparse import OptionParser
[...]
...
def main():
usage = "usage: %prog [options] arg"
parser = OptionParser(usage)
@ -768,13 +768,13 @@ Here's what :mod:`optparse`\ -based scripts usually look like::
action="store_true", dest="verbose")
parser.add_option("-q", "--quiet",
action="store_false", dest="verbose")
[...]
...
(options, args) = parser.parse_args()
if len(args) != 1:
parser.error("incorrect number of arguments")
if options.verbose:
print("reading %s..." % options.filename)
[...]
...
if __name__ == "__main__":
main()
@ -1409,7 +1409,7 @@ If you're not careful, it's easy to define options with conflicting option
strings::
parser.add_option("-n", "--dry-run", ...)
[...]
...
parser.add_option("-n", "--noisy", ...)
(This is particularly true if you've defined your own OptionParser subclass with
@ -1450,7 +1450,7 @@ that option. If the user asks for help, the help message will reflect that::
Options:
--dry-run do no harm
[...]
...
-n, --noisy be noisy
It's possible to whittle away the option strings for a previously-added option
@ -1465,7 +1465,7 @@ At this point, the original ``-n``/``--dry-run`` option is no longer
accessible, so :mod:`optparse` removes it, leaving this help text::
Options:
[...]
...
-n, --noisy be noisy
--dry-run new dry-run option
@ -1701,7 +1701,7 @@ seen, but blow up if it comes after ``-b`` in the command-line. ::
if parser.values.b:
raise OptionValueError("can't use -a after -b")
parser.values.a = 1
[...]
...
parser.add_option("-a", action="callback", callback=check_order)
parser.add_option("-b", action="store_true", dest="b")
@ -1719,7 +1719,7 @@ message and the flag that it sets must be generalized. ::
if parser.values.b:
raise OptionValueError("can't use %s after -b" % opt_str)
setattr(parser.values, option.dest, 1)
[...]
...
parser.add_option("-a", action="callback", callback=check_order, dest='a')
parser.add_option("-b", action="store_true", dest="b")
parser.add_option("-c", action="callback", callback=check_order, dest='c')
@ -1739,7 +1739,7 @@ should not be called when the moon is full, all you have to do is this::
raise OptionValueError("%s option invalid when moon is full"
% opt_str)
setattr(parser.values, option.dest, 1)
[...]
...
parser.add_option("--foo",
action="callback", callback=check_moon, dest="foo")
@ -1762,7 +1762,7 @@ Here's an example that just emulates the standard ``"store"`` action::
def store_value(option, opt_str, value, parser):
setattr(parser.values, option.dest, value)
[...]
...
parser.add_option("--foo",
action="callback", callback=store_value,
type="int", nargs=3, dest="foo")
@ -1824,9 +1824,9 @@ arguments::
del parser.rargs[:len(value)]
setattr(parser.values, option.dest, value)
[...]
parser.add_option("-c", "--callback", dest="vararg_attr",
action="callback", callback=vararg_callback)
...
parser.add_option("-c", "--callback", dest="vararg_attr",
action="callback", callback=vararg_callback)
.. _optparse-extending-optparse: