Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../proc/self/root/lib/0xtools
File: argparse.py
# Author: Steven J. Bethard <steven.bethard@gmail.com>.
[0] Fix | Delete
# Maintainer: Thomas Waldmann <tw@waldmann-edv.de>
[1] Fix | Delete
[2] Fix | Delete
# argparse is (c) 2006-2009 Steven J. Bethard <steven.bethard@gmail.com>.
[3] Fix | Delete
#
[4] Fix | Delete
# The argparse module was contributed to Python as of Python 2.7 and thus
[5] Fix | Delete
# was licensed under the Python license. Same license applies to all files in
[6] Fix | Delete
# the argparse package project.
[7] Fix | Delete
#
[8] Fix | Delete
# For details about the Python License, please see doc/Python-License.txt.
[9] Fix | Delete
#
[10] Fix | Delete
# History
[11] Fix | Delete
# -------
[12] Fix | Delete
#
[13] Fix | Delete
# Before (and including) argparse 1.1, the argparse package was licensed under
[14] Fix | Delete
# Apache License v2.0.
[15] Fix | Delete
#
[16] Fix | Delete
# After argparse 1.1, all project files from the argparse project were deleted
[17] Fix | Delete
# due to license compatibility issues between Apache License 2.0 and GNU GPL v2.
[18] Fix | Delete
#
[19] Fix | Delete
# The project repository then had a clean start with some files taken from
[20] Fix | Delete
# Python 2.7.1, so definitely all files are under Python License now.
[21] Fix | Delete
[22] Fix | Delete
[23] Fix | Delete
"""Command-line parsing library
[24] Fix | Delete
[25] Fix | Delete
This module is an optparse-inspired command-line parsing library that:
[26] Fix | Delete
[27] Fix | Delete
- handles both optional and positional arguments
[28] Fix | Delete
- produces highly informative usage messages
[29] Fix | Delete
- supports parsers that dispatch to sub-parsers
[30] Fix | Delete
[31] Fix | Delete
The following is a simple usage example that sums integers from the
[32] Fix | Delete
command-line and writes the result to a file::
[33] Fix | Delete
[34] Fix | Delete
parser = argparse.ArgumentParser(
[35] Fix | Delete
description='sum the integers at the command line')
[36] Fix | Delete
parser.add_argument(
[37] Fix | Delete
'integers', metavar='int', nargs='+', type=int,
[38] Fix | Delete
help='an integer to be summed')
[39] Fix | Delete
parser.add_argument(
[40] Fix | Delete
'--log', default=sys.stdout, type=argparse.FileType('w'),
[41] Fix | Delete
help='the file where the sum should be written')
[42] Fix | Delete
args = parser.parse_args()
[43] Fix | Delete
args.log.write('%s' % sum(args.integers))
[44] Fix | Delete
args.log.close()
[45] Fix | Delete
[46] Fix | Delete
The module contains the following public classes:
[47] Fix | Delete
[48] Fix | Delete
- ArgumentParser -- The main entry point for command-line parsing. As the
[49] Fix | Delete
example above shows, the add_argument() method is used to populate
[50] Fix | Delete
the parser with actions for optional and positional arguments. Then
[51] Fix | Delete
the parse_args() method is invoked to convert the args at the
[52] Fix | Delete
command-line into an object with attributes.
[53] Fix | Delete
[54] Fix | Delete
- ArgumentError -- The exception raised by ArgumentParser objects when
[55] Fix | Delete
there are errors with the parser's actions. Errors raised while
[56] Fix | Delete
parsing the command-line are caught by ArgumentParser and emitted
[57] Fix | Delete
as command-line messages.
[58] Fix | Delete
[59] Fix | Delete
- FileType -- A factory for defining types of files to be created. As the
[60] Fix | Delete
example above shows, instances of FileType are typically passed as
[61] Fix | Delete
the type= argument of add_argument() calls.
[62] Fix | Delete
[63] Fix | Delete
- Action -- The base class for parser actions. Typically actions are
[64] Fix | Delete
selected by passing strings like 'store_true' or 'append_const' to
[65] Fix | Delete
the action= argument of add_argument(). However, for greater
[66] Fix | Delete
customization of ArgumentParser actions, subclasses of Action may
[67] Fix | Delete
be defined and passed as the action= argument.
[68] Fix | Delete
[69] Fix | Delete
- HelpFormatter, RawDescriptionHelpFormatter, RawTextHelpFormatter,
[70] Fix | Delete
ArgumentDefaultsHelpFormatter -- Formatter classes which
[71] Fix | Delete
may be passed as the formatter_class= argument to the
[72] Fix | Delete
ArgumentParser constructor. HelpFormatter is the default,
[73] Fix | Delete
RawDescriptionHelpFormatter and RawTextHelpFormatter tell the parser
[74] Fix | Delete
not to change the formatting for help text, and
[75] Fix | Delete
ArgumentDefaultsHelpFormatter adds information about argument defaults
[76] Fix | Delete
to the help.
[77] Fix | Delete
[78] Fix | Delete
All other classes in this module are considered implementation details.
[79] Fix | Delete
(Also note that HelpFormatter and RawDescriptionHelpFormatter are only
[80] Fix | Delete
considered public as object names -- the API of the formatter objects is
[81] Fix | Delete
still considered an implementation detail.)
[82] Fix | Delete
"""
[83] Fix | Delete
[84] Fix | Delete
__version__ = '1.1'
[85] Fix | Delete
__all__ = [
[86] Fix | Delete
'ArgumentParser',
[87] Fix | Delete
'ArgumentError',
[88] Fix | Delete
'ArgumentTypeError',
[89] Fix | Delete
'FileType',
[90] Fix | Delete
'HelpFormatter',
[91] Fix | Delete
'ArgumentDefaultsHelpFormatter',
[92] Fix | Delete
'RawDescriptionHelpFormatter',
[93] Fix | Delete
'RawTextHelpFormatter',
[94] Fix | Delete
'Namespace',
[95] Fix | Delete
'Action',
[96] Fix | Delete
'ONE_OR_MORE',
[97] Fix | Delete
'OPTIONAL',
[98] Fix | Delete
'PARSER',
[99] Fix | Delete
'REMAINDER',
[100] Fix | Delete
'SUPPRESS',
[101] Fix | Delete
'ZERO_OR_MORE',
[102] Fix | Delete
]
[103] Fix | Delete
[104] Fix | Delete
[105] Fix | Delete
import collections as _collections
[106] Fix | Delete
import copy as _copy
[107] Fix | Delete
import os as _os
[108] Fix | Delete
import re as _re
[109] Fix | Delete
import sys as _sys
[110] Fix | Delete
import textwrap as _textwrap
[111] Fix | Delete
[112] Fix | Delete
from gettext import gettext as _
[113] Fix | Delete
[114] Fix | Delete
[115] Fix | Delete
def _callable(obj):
[116] Fix | Delete
return hasattr(obj, '__call__') or hasattr(obj, '__bases__')
[117] Fix | Delete
[118] Fix | Delete
[119] Fix | Delete
SUPPRESS = '==SUPPRESS=='
[120] Fix | Delete
[121] Fix | Delete
OPTIONAL = '?'
[122] Fix | Delete
ZERO_OR_MORE = '*'
[123] Fix | Delete
ONE_OR_MORE = '+'
[124] Fix | Delete
PARSER = 'A...'
[125] Fix | Delete
REMAINDER = '...'
[126] Fix | Delete
_UNRECOGNIZED_ARGS_ATTR = '_unrecognized_args'
[127] Fix | Delete
[128] Fix | Delete
# =============================
[129] Fix | Delete
# Utility functions and classes
[130] Fix | Delete
# =============================
[131] Fix | Delete
[132] Fix | Delete
class _AttributeHolder(object):
[133] Fix | Delete
"""Abstract base class that provides __repr__.
[134] Fix | Delete
[135] Fix | Delete
The __repr__ method returns a string in the format::
[136] Fix | Delete
ClassName(attr=name, attr=name, ...)
[137] Fix | Delete
The attributes are determined either by a class-level attribute,
[138] Fix | Delete
'_kwarg_names', or by inspecting the instance __dict__.
[139] Fix | Delete
"""
[140] Fix | Delete
[141] Fix | Delete
def __repr__(self):
[142] Fix | Delete
type_name = type(self).__name__
[143] Fix | Delete
arg_strings = []
[144] Fix | Delete
for arg in self._get_args():
[145] Fix | Delete
arg_strings.append(repr(arg))
[146] Fix | Delete
for name, value in self._get_kwargs():
[147] Fix | Delete
arg_strings.append('%s=%r' % (name, value))
[148] Fix | Delete
return '%s(%s)' % (type_name, ', '.join(arg_strings))
[149] Fix | Delete
[150] Fix | Delete
def _get_kwargs(self):
[151] Fix | Delete
return sorted(self.__dict__.items())
[152] Fix | Delete
[153] Fix | Delete
def _get_args(self):
[154] Fix | Delete
return []
[155] Fix | Delete
[156] Fix | Delete
[157] Fix | Delete
def _ensure_value(namespace, name, value):
[158] Fix | Delete
if getattr(namespace, name, None) is None:
[159] Fix | Delete
setattr(namespace, name, value)
[160] Fix | Delete
return getattr(namespace, name)
[161] Fix | Delete
[162] Fix | Delete
[163] Fix | Delete
# ===============
[164] Fix | Delete
# Formatting Help
[165] Fix | Delete
# ===============
[166] Fix | Delete
[167] Fix | Delete
class HelpFormatter(object):
[168] Fix | Delete
"""Formatter for generating usage messages and argument help strings.
[169] Fix | Delete
[170] Fix | Delete
Only the name of this class is considered a public API. All the methods
[171] Fix | Delete
provided by the class are considered an implementation detail.
[172] Fix | Delete
"""
[173] Fix | Delete
[174] Fix | Delete
def __init__(self,
[175] Fix | Delete
prog,
[176] Fix | Delete
indent_increment=2,
[177] Fix | Delete
max_help_position=24,
[178] Fix | Delete
width=None):
[179] Fix | Delete
[180] Fix | Delete
# default setting for width
[181] Fix | Delete
if width is None:
[182] Fix | Delete
try:
[183] Fix | Delete
width = int(_os.environ['COLUMNS'])
[184] Fix | Delete
except (KeyError, ValueError):
[185] Fix | Delete
width = 80
[186] Fix | Delete
width -= 2
[187] Fix | Delete
[188] Fix | Delete
self._prog = prog
[189] Fix | Delete
self._indent_increment = indent_increment
[190] Fix | Delete
self._max_help_position = max_help_position
[191] Fix | Delete
self._width = width
[192] Fix | Delete
[193] Fix | Delete
self._current_indent = 0
[194] Fix | Delete
self._level = 0
[195] Fix | Delete
self._action_max_length = 0
[196] Fix | Delete
[197] Fix | Delete
self._root_section = self._Section(self, None)
[198] Fix | Delete
self._current_section = self._root_section
[199] Fix | Delete
[200] Fix | Delete
self._whitespace_matcher = _re.compile(r'\s+')
[201] Fix | Delete
self._long_break_matcher = _re.compile(r'\n\n\n+')
[202] Fix | Delete
[203] Fix | Delete
# ===============================
[204] Fix | Delete
# Section and indentation methods
[205] Fix | Delete
# ===============================
[206] Fix | Delete
def _indent(self):
[207] Fix | Delete
self._current_indent += self._indent_increment
[208] Fix | Delete
self._level += 1
[209] Fix | Delete
[210] Fix | Delete
def _dedent(self):
[211] Fix | Delete
self._current_indent -= self._indent_increment
[212] Fix | Delete
assert self._current_indent >= 0, 'Indent decreased below 0.'
[213] Fix | Delete
self._level -= 1
[214] Fix | Delete
[215] Fix | Delete
class _Section(object):
[216] Fix | Delete
[217] Fix | Delete
def __init__(self, formatter, parent, heading=None):
[218] Fix | Delete
self.formatter = formatter
[219] Fix | Delete
self.parent = parent
[220] Fix | Delete
self.heading = heading
[221] Fix | Delete
self.items = []
[222] Fix | Delete
[223] Fix | Delete
def format_help(self):
[224] Fix | Delete
# format the indented section
[225] Fix | Delete
if self.parent is not None:
[226] Fix | Delete
self.formatter._indent()
[227] Fix | Delete
join = self.formatter._join_parts
[228] Fix | Delete
for func, args in self.items:
[229] Fix | Delete
func(*args)
[230] Fix | Delete
item_help = join([func(*args) for func, args in self.items])
[231] Fix | Delete
if self.parent is not None:
[232] Fix | Delete
self.formatter._dedent()
[233] Fix | Delete
[234] Fix | Delete
# return nothing if the section was empty
[235] Fix | Delete
if not item_help:
[236] Fix | Delete
return ''
[237] Fix | Delete
[238] Fix | Delete
# add the heading if the section was non-empty
[239] Fix | Delete
if self.heading is not SUPPRESS and self.heading is not None:
[240] Fix | Delete
current_indent = self.formatter._current_indent
[241] Fix | Delete
heading = '%*s%s:\n' % (current_indent, '', self.heading)
[242] Fix | Delete
else:
[243] Fix | Delete
heading = ''
[244] Fix | Delete
[245] Fix | Delete
# join the section-initial newline, the heading and the help
[246] Fix | Delete
return join(['\n', heading, item_help, '\n'])
[247] Fix | Delete
[248] Fix | Delete
def _add_item(self, func, args):
[249] Fix | Delete
self._current_section.items.append((func, args))
[250] Fix | Delete
[251] Fix | Delete
# ========================
[252] Fix | Delete
# Message building methods
[253] Fix | Delete
# ========================
[254] Fix | Delete
def start_section(self, heading):
[255] Fix | Delete
self._indent()
[256] Fix | Delete
section = self._Section(self, self._current_section, heading)
[257] Fix | Delete
self._add_item(section.format_help, [])
[258] Fix | Delete
self._current_section = section
[259] Fix | Delete
[260] Fix | Delete
def end_section(self):
[261] Fix | Delete
self._current_section = self._current_section.parent
[262] Fix | Delete
self._dedent()
[263] Fix | Delete
[264] Fix | Delete
def add_text(self, text):
[265] Fix | Delete
if text is not SUPPRESS and text is not None:
[266] Fix | Delete
self._add_item(self._format_text, [text])
[267] Fix | Delete
[268] Fix | Delete
def add_usage(self, usage, actions, groups, prefix=None):
[269] Fix | Delete
if usage is not SUPPRESS:
[270] Fix | Delete
args = usage, actions, groups, prefix
[271] Fix | Delete
self._add_item(self._format_usage, args)
[272] Fix | Delete
[273] Fix | Delete
def add_argument(self, action):
[274] Fix | Delete
if action.help is not SUPPRESS:
[275] Fix | Delete
[276] Fix | Delete
# find all invocations
[277] Fix | Delete
get_invocation = self._format_action_invocation
[278] Fix | Delete
invocations = [get_invocation(action)]
[279] Fix | Delete
for subaction in self._iter_indented_subactions(action):
[280] Fix | Delete
invocations.append(get_invocation(subaction))
[281] Fix | Delete
[282] Fix | Delete
# update the maximum item length
[283] Fix | Delete
invocation_length = max([len(s) for s in invocations])
[284] Fix | Delete
action_length = invocation_length + self._current_indent
[285] Fix | Delete
self._action_max_length = max(self._action_max_length,
[286] Fix | Delete
action_length)
[287] Fix | Delete
[288] Fix | Delete
# add the item to the list
[289] Fix | Delete
self._add_item(self._format_action, [action])
[290] Fix | Delete
[291] Fix | Delete
def add_arguments(self, actions):
[292] Fix | Delete
for action in actions:
[293] Fix | Delete
self.add_argument(action)
[294] Fix | Delete
[295] Fix | Delete
# =======================
[296] Fix | Delete
# Help-formatting methods
[297] Fix | Delete
# =======================
[298] Fix | Delete
def format_help(self):
[299] Fix | Delete
help = self._root_section.format_help()
[300] Fix | Delete
if help:
[301] Fix | Delete
help = self._long_break_matcher.sub('\n\n', help)
[302] Fix | Delete
help = help.strip('\n') + '\n'
[303] Fix | Delete
return help
[304] Fix | Delete
[305] Fix | Delete
def _join_parts(self, part_strings):
[306] Fix | Delete
return ''.join([part
[307] Fix | Delete
for part in part_strings
[308] Fix | Delete
if part and part is not SUPPRESS])
[309] Fix | Delete
[310] Fix | Delete
def _format_usage(self, usage, actions, groups, prefix):
[311] Fix | Delete
if prefix is None:
[312] Fix | Delete
prefix = _('usage: ')
[313] Fix | Delete
[314] Fix | Delete
# if usage is specified, use that
[315] Fix | Delete
if usage is not None:
[316] Fix | Delete
usage = usage % dict(prog=self._prog)
[317] Fix | Delete
[318] Fix | Delete
# if no optionals or positionals are available, usage is just prog
[319] Fix | Delete
elif usage is None and not actions:
[320] Fix | Delete
usage = '%(prog)s' % dict(prog=self._prog)
[321] Fix | Delete
[322] Fix | Delete
# if optionals and positionals are available, calculate usage
[323] Fix | Delete
elif usage is None:
[324] Fix | Delete
prog = '%(prog)s' % dict(prog=self._prog)
[325] Fix | Delete
[326] Fix | Delete
# split optionals from positionals
[327] Fix | Delete
optionals = []
[328] Fix | Delete
positionals = []
[329] Fix | Delete
for action in actions:
[330] Fix | Delete
if action.option_strings:
[331] Fix | Delete
optionals.append(action)
[332] Fix | Delete
else:
[333] Fix | Delete
positionals.append(action)
[334] Fix | Delete
[335] Fix | Delete
# build full usage string
[336] Fix | Delete
format = self._format_actions_usage
[337] Fix | Delete
action_usage = format(optionals + positionals, groups)
[338] Fix | Delete
usage = ' '.join([s for s in [prog, action_usage] if s])
[339] Fix | Delete
[340] Fix | Delete
# wrap the usage parts if it's too long
[341] Fix | Delete
text_width = self._width - self._current_indent
[342] Fix | Delete
if len(prefix) + len(usage) > text_width:
[343] Fix | Delete
[344] Fix | Delete
# break usage into wrappable parts
[345] Fix | Delete
part_regexp = r'\(.*?\)+|\[.*?\]+|\S+'
[346] Fix | Delete
opt_usage = format(optionals, groups)
[347] Fix | Delete
pos_usage = format(positionals, groups)
[348] Fix | Delete
opt_parts = _re.findall(part_regexp, opt_usage)
[349] Fix | Delete
pos_parts = _re.findall(part_regexp, pos_usage)
[350] Fix | Delete
assert ' '.join(opt_parts) == opt_usage
[351] Fix | Delete
assert ' '.join(pos_parts) == pos_usage
[352] Fix | Delete
[353] Fix | Delete
# helper for wrapping lines
[354] Fix | Delete
def get_lines(parts, indent, prefix=None):
[355] Fix | Delete
lines = []
[356] Fix | Delete
line = []
[357] Fix | Delete
if prefix is not None:
[358] Fix | Delete
line_len = len(prefix) - 1
[359] Fix | Delete
else:
[360] Fix | Delete
line_len = len(indent) - 1
[361] Fix | Delete
for part in parts:
[362] Fix | Delete
if line_len + 1 + len(part) > text_width:
[363] Fix | Delete
lines.append(indent + ' '.join(line))
[364] Fix | Delete
line = []
[365] Fix | Delete
line_len = len(indent) - 1
[366] Fix | Delete
line.append(part)
[367] Fix | Delete
line_len += len(part) + 1
[368] Fix | Delete
if line:
[369] Fix | Delete
lines.append(indent + ' '.join(line))
[370] Fix | Delete
if prefix is not None:
[371] Fix | Delete
lines[0] = lines[0][len(indent):]
[372] Fix | Delete
return lines
[373] Fix | Delete
[374] Fix | Delete
# if prog is short, follow it with optionals or positionals
[375] Fix | Delete
if len(prefix) + len(prog) <= 0.75 * text_width:
[376] Fix | Delete
indent = ' ' * (len(prefix) + len(prog) + 1)
[377] Fix | Delete
if opt_parts:
[378] Fix | Delete
lines = get_lines([prog] + opt_parts, indent, prefix)
[379] Fix | Delete
lines.extend(get_lines(pos_parts, indent))
[380] Fix | Delete
elif pos_parts:
[381] Fix | Delete
lines = get_lines([prog] + pos_parts, indent, prefix)
[382] Fix | Delete
else:
[383] Fix | Delete
lines = [prog]
[384] Fix | Delete
[385] Fix | Delete
# if prog is long, put it on its own line
[386] Fix | Delete
else:
[387] Fix | Delete
indent = ' ' * len(prefix)
[388] Fix | Delete
parts = opt_parts + pos_parts
[389] Fix | Delete
lines = get_lines(parts, indent)
[390] Fix | Delete
if len(lines) > 1:
[391] Fix | Delete
lines = []
[392] Fix | Delete
lines.extend(get_lines(opt_parts, indent))
[393] Fix | Delete
lines.extend(get_lines(pos_parts, indent))
[394] Fix | Delete
lines = [prog] + lines
[395] Fix | Delete
[396] Fix | Delete
# join lines into usage
[397] Fix | Delete
usage = '\n'.join(lines)
[398] Fix | Delete
[399] Fix | Delete
# prefix with 'usage:'
[400] Fix | Delete
return '%s%s\n\n' % (prefix, usage)
[401] Fix | Delete
[402] Fix | Delete
def _format_actions_usage(self, actions, groups):
[403] Fix | Delete
# find group indices and identify actions in groups
[404] Fix | Delete
group_actions = set()
[405] Fix | Delete
inserts = {}
[406] Fix | Delete
for group in groups:
[407] Fix | Delete
try:
[408] Fix | Delete
start = actions.index(group._group_actions[0])
[409] Fix | Delete
except ValueError:
[410] Fix | Delete
continue
[411] Fix | Delete
else:
[412] Fix | Delete
end = start + len(group._group_actions)
[413] Fix | Delete
if actions[start:end] == group._group_actions:
[414] Fix | Delete
for action in group._group_actions:
[415] Fix | Delete
group_actions.add(action)
[416] Fix | Delete
if not group.required:
[417] Fix | Delete
if start in inserts:
[418] Fix | Delete
inserts[start] += ' ['
[419] Fix | Delete
else:
[420] Fix | Delete
inserts[start] = '['
[421] Fix | Delete
inserts[end] = ']'
[422] Fix | Delete
else:
[423] Fix | Delete
if start in inserts:
[424] Fix | Delete
inserts[start] += ' ('
[425] Fix | Delete
else:
[426] Fix | Delete
inserts[start] = '('
[427] Fix | Delete
inserts[end] = ')'
[428] Fix | Delete
for i in range(start + 1, end):
[429] Fix | Delete
inserts[i] = '|'
[430] Fix | Delete
[431] Fix | Delete
# collect all actions format strings
[432] Fix | Delete
parts = []
[433] Fix | Delete
for i, action in enumerate(actions):
[434] Fix | Delete
[435] Fix | Delete
# suppressed arguments are marked with None
[436] Fix | Delete
# remove | separators for suppressed arguments
[437] Fix | Delete
if action.help is SUPPRESS:
[438] Fix | Delete
parts.append(None)
[439] Fix | Delete
if inserts.get(i) == '|':
[440] Fix | Delete
inserts.pop(i)
[441] Fix | Delete
elif inserts.get(i + 1) == '|':
[442] Fix | Delete
inserts.pop(i + 1)
[443] Fix | Delete
[444] Fix | Delete
# produce all arg strings
[445] Fix | Delete
elif not action.option_strings:
[446] Fix | Delete
part = self._format_args(action, action.dest)
[447] Fix | Delete
[448] Fix | Delete
# if it's in a group, strip the outer []
[449] Fix | Delete
if action in group_actions:
[450] Fix | Delete
if part[0] == '[' and part[-1] == ']':
[451] Fix | Delete
part = part[1:-1]
[452] Fix | Delete
[453] Fix | Delete
# add the action string to the list
[454] Fix | Delete
parts.append(part)
[455] Fix | Delete
[456] Fix | Delete
# produce the first way to invoke the option in brackets
[457] Fix | Delete
else:
[458] Fix | Delete
option_string = action.option_strings[0]
[459] Fix | Delete
[460] Fix | Delete
# if the Optional doesn't take a value, format is:
[461] Fix | Delete
# -s or --long
[462] Fix | Delete
if action.nargs == 0:
[463] Fix | Delete
part = '%s' % option_string
[464] Fix | Delete
[465] Fix | Delete
# if the Optional takes a value, format is:
[466] Fix | Delete
# -s ARGS or --long ARGS
[467] Fix | Delete
else:
[468] Fix | Delete
default = action.dest.upper()
[469] Fix | Delete
args_string = self._format_args(action, default)
[470] Fix | Delete
part = '%s %s' % (option_string, args_string)
[471] Fix | Delete
[472] Fix | Delete
# make it look optional if it's not required or in a group
[473] Fix | Delete
if not action.required and action not in group_actions:
[474] Fix | Delete
part = '[%s]' % part
[475] Fix | Delete
[476] Fix | Delete
# add the action string to the list
[477] Fix | Delete
parts.append(part)
[478] Fix | Delete
[479] Fix | Delete
# insert things at the necessary indices
[480] Fix | Delete
for i in sorted(inserts, reverse=True):
[481] Fix | Delete
parts[i:i] = [inserts[i]]
[482] Fix | Delete
[483] Fix | Delete
# join all the action items with spaces
[484] Fix | Delete
text = ' '.join([item for item in parts if item is not None])
[485] Fix | Delete
[486] Fix | Delete
# clean up separators for mutually exclusive groups
[487] Fix | Delete
open = r'[\[(]'
[488] Fix | Delete
close = r'[\])]'
[489] Fix | Delete
text = _re.sub(r'(%s) ' % open, r'\1', text)
[490] Fix | Delete
text = _re.sub(r' (%s)' % close, r'\1', text)
[491] Fix | Delete
text = _re.sub(r'%s *%s' % (open, close), r'', text)
[492] Fix | Delete
text = _re.sub(r'\(([^|]*)\)', r'\1', text)
[493] Fix | Delete
text = text.strip()
[494] Fix | Delete
[495] Fix | Delete
# return the text
[496] Fix | Delete
return text
[497] Fix | Delete
[498] Fix | Delete
def _format_text(self, text):
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function