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