Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../lib64/python2....
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
'Namespace',
[73] Fix | Delete
'Action',
[74] Fix | Delete
'ONE_OR_MORE',
[75] Fix | Delete
'OPTIONAL',
[76] Fix | Delete
'PARSER',
[77] Fix | Delete
'REMAINDER',
[78] Fix | Delete
'SUPPRESS',
[79] Fix | Delete
'ZERO_OR_MORE',
[80] Fix | Delete
]
[81] Fix | Delete
[82] Fix | Delete
[83] Fix | Delete
import collections as _collections
[84] Fix | Delete
import copy as _copy
[85] Fix | Delete
import os as _os
[86] Fix | Delete
import re as _re
[87] Fix | Delete
import sys as _sys
[88] Fix | Delete
import textwrap as _textwrap
[89] Fix | Delete
[90] Fix | Delete
from gettext import gettext as _
[91] Fix | Delete
[92] Fix | Delete
[93] Fix | Delete
def _callable(obj):
[94] Fix | Delete
return hasattr(obj, '__call__') or hasattr(obj, '__bases__')
[95] Fix | Delete
[96] Fix | Delete
[97] Fix | Delete
SUPPRESS = '==SUPPRESS=='
[98] Fix | Delete
[99] Fix | Delete
OPTIONAL = '?'
[100] Fix | Delete
ZERO_OR_MORE = '*'
[101] Fix | Delete
ONE_OR_MORE = '+'
[102] Fix | Delete
PARSER = 'A...'
[103] Fix | Delete
REMAINDER = '...'
[104] Fix | Delete
_UNRECOGNIZED_ARGS_ATTR = '_unrecognized_args'
[105] Fix | Delete
[106] Fix | Delete
# =============================
[107] Fix | Delete
# Utility functions and classes
[108] Fix | Delete
# =============================
[109] Fix | Delete
[110] Fix | Delete
class _AttributeHolder(object):
[111] Fix | Delete
"""Abstract base class that provides __repr__.
[112] Fix | Delete
[113] Fix | Delete
The __repr__ method returns a string in the format::
[114] Fix | Delete
ClassName(attr=name, attr=name, ...)
[115] Fix | Delete
The attributes are determined either by a class-level attribute,
[116] Fix | Delete
'_kwarg_names', or by inspecting the instance __dict__.
[117] Fix | Delete
"""
[118] Fix | Delete
[119] Fix | Delete
def __repr__(self):
[120] Fix | Delete
type_name = type(self).__name__
[121] Fix | Delete
arg_strings = []
[122] Fix | Delete
for arg in self._get_args():
[123] Fix | Delete
arg_strings.append(repr(arg))
[124] Fix | Delete
for name, value in self._get_kwargs():
[125] Fix | Delete
arg_strings.append('%s=%r' % (name, value))
[126] Fix | Delete
return '%s(%s)' % (type_name, ', '.join(arg_strings))
[127] Fix | Delete
[128] Fix | Delete
def _get_kwargs(self):
[129] Fix | Delete
return sorted(self.__dict__.items())
[130] Fix | Delete
[131] Fix | Delete
def _get_args(self):
[132] Fix | Delete
return []
[133] Fix | Delete
[134] Fix | Delete
[135] Fix | Delete
def _ensure_value(namespace, name, value):
[136] Fix | Delete
if getattr(namespace, name, None) is None:
[137] Fix | Delete
setattr(namespace, name, value)
[138] Fix | Delete
return getattr(namespace, name)
[139] Fix | Delete
[140] Fix | Delete
[141] Fix | Delete
# ===============
[142] Fix | Delete
# Formatting Help
[143] Fix | Delete
# ===============
[144] Fix | Delete
[145] Fix | Delete
class HelpFormatter(object):
[146] Fix | Delete
"""Formatter for generating usage messages and argument help strings.
[147] Fix | Delete
[148] Fix | Delete
Only the name of this class is considered a public API. All the methods
[149] Fix | Delete
provided by the class are considered an implementation detail.
[150] Fix | Delete
"""
[151] Fix | Delete
[152] Fix | Delete
def __init__(self,
[153] Fix | Delete
prog,
[154] Fix | Delete
indent_increment=2,
[155] Fix | Delete
max_help_position=24,
[156] Fix | Delete
width=None):
[157] Fix | Delete
[158] Fix | Delete
# default setting for width
[159] Fix | Delete
if width is None:
[160] Fix | Delete
try:
[161] Fix | Delete
width = int(_os.environ['COLUMNS'])
[162] Fix | Delete
except (KeyError, ValueError):
[163] Fix | Delete
width = 80
[164] Fix | Delete
width -= 2
[165] Fix | Delete
[166] Fix | Delete
self._prog = prog
[167] Fix | Delete
self._indent_increment = indent_increment
[168] Fix | Delete
self._max_help_position = max_help_position
[169] Fix | Delete
self._max_help_position = min(max_help_position,
[170] Fix | Delete
max(width - 20, indent_increment * 2))
[171] Fix | Delete
self._width = width
[172] Fix | Delete
[173] Fix | Delete
self._current_indent = 0
[174] Fix | Delete
self._level = 0
[175] Fix | Delete
self._action_max_length = 0
[176] Fix | Delete
[177] Fix | Delete
self._root_section = self._Section(self, None)
[178] Fix | Delete
self._current_section = self._root_section
[179] Fix | Delete
[180] Fix | Delete
self._whitespace_matcher = _re.compile(r'\s+')
[181] Fix | Delete
self._long_break_matcher = _re.compile(r'\n\n\n+')
[182] Fix | Delete
[183] Fix | Delete
# ===============================
[184] Fix | Delete
# Section and indentation methods
[185] Fix | Delete
# ===============================
[186] Fix | Delete
def _indent(self):
[187] Fix | Delete
self._current_indent += self._indent_increment
[188] Fix | Delete
self._level += 1
[189] Fix | Delete
[190] Fix | Delete
def _dedent(self):
[191] Fix | Delete
self._current_indent -= self._indent_increment
[192] Fix | Delete
assert self._current_indent >= 0, 'Indent decreased below 0.'
[193] Fix | Delete
self._level -= 1
[194] Fix | Delete
[195] Fix | Delete
class _Section(object):
[196] Fix | Delete
[197] Fix | Delete
def __init__(self, formatter, parent, heading=None):
[198] Fix | Delete
self.formatter = formatter
[199] Fix | Delete
self.parent = parent
[200] Fix | Delete
self.heading = heading
[201] Fix | Delete
self.items = []
[202] Fix | Delete
[203] Fix | Delete
def format_help(self):
[204] Fix | Delete
# format the indented section
[205] Fix | Delete
if self.parent is not None:
[206] Fix | Delete
self.formatter._indent()
[207] Fix | Delete
join = self.formatter._join_parts
[208] Fix | Delete
for func, args in self.items:
[209] Fix | Delete
func(*args)
[210] Fix | Delete
item_help = join([func(*args) for func, args in self.items])
[211] Fix | Delete
if self.parent is not None:
[212] Fix | Delete
self.formatter._dedent()
[213] Fix | Delete
[214] Fix | Delete
# return nothing if the section was empty
[215] Fix | Delete
if not item_help:
[216] Fix | Delete
return ''
[217] Fix | Delete
[218] Fix | Delete
# add the heading if the section was non-empty
[219] Fix | Delete
if self.heading is not SUPPRESS and self.heading is not None:
[220] Fix | Delete
current_indent = self.formatter._current_indent
[221] Fix | Delete
heading = '%*s%s:\n' % (current_indent, '', self.heading)
[222] Fix | Delete
else:
[223] Fix | Delete
heading = ''
[224] Fix | Delete
[225] Fix | Delete
# join the section-initial newline, the heading and the help
[226] Fix | Delete
return join(['\n', heading, item_help, '\n'])
[227] Fix | Delete
[228] Fix | Delete
def _add_item(self, func, args):
[229] Fix | Delete
self._current_section.items.append((func, args))
[230] Fix | Delete
[231] Fix | Delete
# ========================
[232] Fix | Delete
# Message building methods
[233] Fix | Delete
# ========================
[234] Fix | Delete
def start_section(self, heading):
[235] Fix | Delete
self._indent()
[236] Fix | Delete
section = self._Section(self, self._current_section, heading)
[237] Fix | Delete
self._add_item(section.format_help, [])
[238] Fix | Delete
self._current_section = section
[239] Fix | Delete
[240] Fix | Delete
def end_section(self):
[241] Fix | Delete
self._current_section = self._current_section.parent
[242] Fix | Delete
self._dedent()
[243] Fix | Delete
[244] Fix | Delete
def add_text(self, text):
[245] Fix | Delete
if text is not SUPPRESS and text is not None:
[246] Fix | Delete
self._add_item(self._format_text, [text])
[247] Fix | Delete
[248] Fix | Delete
def add_usage(self, usage, actions, groups, prefix=None):
[249] Fix | Delete
if usage is not SUPPRESS:
[250] Fix | Delete
args = usage, actions, groups, prefix
[251] Fix | Delete
self._add_item(self._format_usage, args)
[252] Fix | Delete
[253] Fix | Delete
def add_argument(self, action):
[254] Fix | Delete
if action.help is not SUPPRESS:
[255] Fix | Delete
[256] Fix | Delete
# find all invocations
[257] Fix | Delete
get_invocation = self._format_action_invocation
[258] Fix | Delete
invocations = [get_invocation(action)]
[259] Fix | Delete
for subaction in self._iter_indented_subactions(action):
[260] Fix | Delete
invocations.append(get_invocation(subaction))
[261] Fix | Delete
[262] Fix | Delete
# update the maximum item length
[263] Fix | Delete
invocation_length = max([len(s) for s in invocations])
[264] Fix | Delete
action_length = invocation_length + self._current_indent
[265] Fix | Delete
self._action_max_length = max(self._action_max_length,
[266] Fix | Delete
action_length)
[267] Fix | Delete
[268] Fix | Delete
# add the item to the list
[269] Fix | Delete
self._add_item(self._format_action, [action])
[270] Fix | Delete
[271] Fix | Delete
def add_arguments(self, actions):
[272] Fix | Delete
for action in actions:
[273] Fix | Delete
self.add_argument(action)
[274] Fix | Delete
[275] Fix | Delete
# =======================
[276] Fix | Delete
# Help-formatting methods
[277] Fix | Delete
# =======================
[278] Fix | Delete
def format_help(self):
[279] Fix | Delete
help = self._root_section.format_help()
[280] Fix | Delete
if help:
[281] Fix | Delete
help = self._long_break_matcher.sub('\n\n', help)
[282] Fix | Delete
help = help.strip('\n') + '\n'
[283] Fix | Delete
return help
[284] Fix | Delete
[285] Fix | Delete
def _join_parts(self, part_strings):
[286] Fix | Delete
return ''.join([part
[287] Fix | Delete
for part in part_strings
[288] Fix | Delete
if part and part is not SUPPRESS])
[289] Fix | Delete
[290] Fix | Delete
def _format_usage(self, usage, actions, groups, prefix):
[291] Fix | Delete
if prefix is None:
[292] Fix | Delete
prefix = _('usage: ')
[293] Fix | Delete
[294] Fix | Delete
# if usage is specified, use that
[295] Fix | Delete
if usage is not None:
[296] Fix | Delete
usage = usage % dict(prog=self._prog)
[297] Fix | Delete
[298] Fix | Delete
# if no optionals or positionals are available, usage is just prog
[299] Fix | Delete
elif usage is None and not actions:
[300] Fix | Delete
usage = '%(prog)s' % dict(prog=self._prog)
[301] Fix | Delete
[302] Fix | Delete
# if optionals and positionals are available, calculate usage
[303] Fix | Delete
elif usage is None:
[304] Fix | Delete
prog = '%(prog)s' % dict(prog=self._prog)
[305] Fix | Delete
[306] Fix | Delete
# split optionals from positionals
[307] Fix | Delete
optionals = []
[308] Fix | Delete
positionals = []
[309] Fix | Delete
for action in actions:
[310] Fix | Delete
if action.option_strings:
[311] Fix | Delete
optionals.append(action)
[312] Fix | Delete
else:
[313] Fix | Delete
positionals.append(action)
[314] Fix | Delete
[315] Fix | Delete
# build full usage string
[316] Fix | Delete
format = self._format_actions_usage
[317] Fix | Delete
action_usage = format(optionals + positionals, groups)
[318] Fix | Delete
usage = ' '.join([s for s in [prog, action_usage] if s])
[319] Fix | Delete
[320] Fix | Delete
# wrap the usage parts if it's too long
[321] Fix | Delete
text_width = self._width - self._current_indent
[322] Fix | Delete
if len(prefix) + len(usage) > text_width:
[323] Fix | Delete
[324] Fix | Delete
# break usage into wrappable parts
[325] Fix | Delete
part_regexp = (
[326] Fix | Delete
r'\(.*?\)+(?=\s|$)|'
[327] Fix | Delete
r'\[.*?\]+(?=\s|$)|'
[328] Fix | Delete
r'\S+'
[329] Fix | Delete
)
[330] Fix | Delete
opt_usage = format(optionals, groups)
[331] Fix | Delete
pos_usage = format(positionals, groups)
[332] Fix | Delete
opt_parts = _re.findall(part_regexp, opt_usage)
[333] Fix | Delete
pos_parts = _re.findall(part_regexp, pos_usage)
[334] Fix | Delete
assert ' '.join(opt_parts) == opt_usage
[335] Fix | Delete
assert ' '.join(pos_parts) == pos_usage
[336] Fix | Delete
[337] Fix | Delete
# helper for wrapping lines
[338] Fix | Delete
def get_lines(parts, indent, prefix=None):
[339] Fix | Delete
lines = []
[340] Fix | Delete
line = []
[341] Fix | Delete
if prefix is not None:
[342] Fix | Delete
line_len = len(prefix) - 1
[343] Fix | Delete
else:
[344] Fix | Delete
line_len = len(indent) - 1
[345] Fix | Delete
for part in parts:
[346] Fix | Delete
if line_len + 1 + len(part) > text_width and line:
[347] Fix | Delete
lines.append(indent + ' '.join(line))
[348] Fix | Delete
line = []
[349] Fix | Delete
line_len = len(indent) - 1
[350] Fix | Delete
line.append(part)
[351] Fix | Delete
line_len += len(part) + 1
[352] Fix | Delete
if line:
[353] Fix | Delete
lines.append(indent + ' '.join(line))
[354] Fix | Delete
if prefix is not None:
[355] Fix | Delete
lines[0] = lines[0][len(indent):]
[356] Fix | Delete
return lines
[357] Fix | Delete
[358] Fix | Delete
# if prog is short, follow it with optionals or positionals
[359] Fix | Delete
if len(prefix) + len(prog) <= 0.75 * text_width:
[360] Fix | Delete
indent = ' ' * (len(prefix) + len(prog) + 1)
[361] Fix | Delete
if opt_parts:
[362] Fix | Delete
lines = get_lines([prog] + opt_parts, indent, prefix)
[363] Fix | Delete
lines.extend(get_lines(pos_parts, indent))
[364] Fix | Delete
elif pos_parts:
[365] Fix | Delete
lines = get_lines([prog] + pos_parts, indent, prefix)
[366] Fix | Delete
else:
[367] Fix | Delete
lines = [prog]
[368] Fix | Delete
[369] Fix | Delete
# if prog is long, put it on its own line
[370] Fix | Delete
else:
[371] Fix | Delete
indent = ' ' * len(prefix)
[372] Fix | Delete
parts = opt_parts + pos_parts
[373] Fix | Delete
lines = get_lines(parts, indent)
[374] Fix | Delete
if len(lines) > 1:
[375] Fix | Delete
lines = []
[376] Fix | Delete
lines.extend(get_lines(opt_parts, indent))
[377] Fix | Delete
lines.extend(get_lines(pos_parts, indent))
[378] Fix | Delete
lines = [prog] + lines
[379] Fix | Delete
[380] Fix | Delete
# join lines into usage
[381] Fix | Delete
usage = '\n'.join(lines)
[382] Fix | Delete
[383] Fix | Delete
# prefix with 'usage:'
[384] Fix | Delete
return '%s%s\n\n' % (prefix, usage)
[385] Fix | Delete
[386] Fix | Delete
def _format_actions_usage(self, actions, groups):
[387] Fix | Delete
# find group indices and identify actions in groups
[388] Fix | Delete
group_actions = set()
[389] Fix | Delete
inserts = {}
[390] Fix | Delete
for group in groups:
[391] Fix | Delete
try:
[392] Fix | Delete
start = actions.index(group._group_actions[0])
[393] Fix | Delete
except ValueError:
[394] Fix | Delete
continue
[395] Fix | Delete
else:
[396] Fix | Delete
end = start + len(group._group_actions)
[397] Fix | Delete
if actions[start:end] == group._group_actions:
[398] Fix | Delete
for action in group._group_actions:
[399] Fix | Delete
group_actions.add(action)
[400] Fix | Delete
if not group.required:
[401] Fix | Delete
if start in inserts:
[402] Fix | Delete
inserts[start] += ' ['
[403] Fix | Delete
else:
[404] Fix | Delete
inserts[start] = '['
[405] Fix | Delete
inserts[end] = ']'
[406] Fix | Delete
else:
[407] Fix | Delete
if start in inserts:
[408] Fix | Delete
inserts[start] += ' ('
[409] Fix | Delete
else:
[410] Fix | Delete
inserts[start] = '('
[411] Fix | Delete
inserts[end] = ')'
[412] Fix | Delete
for i in range(start + 1, end):
[413] Fix | Delete
inserts[i] = '|'
[414] Fix | Delete
[415] Fix | Delete
# collect all actions format strings
[416] Fix | Delete
parts = []
[417] Fix | Delete
for i, action in enumerate(actions):
[418] Fix | Delete
[419] Fix | Delete
# suppressed arguments are marked with None
[420] Fix | Delete
# remove | separators for suppressed arguments
[421] Fix | Delete
if action.help is SUPPRESS:
[422] Fix | Delete
parts.append(None)
[423] Fix | Delete
if inserts.get(i) == '|':
[424] Fix | Delete
inserts.pop(i)
[425] Fix | Delete
elif inserts.get(i + 1) == '|':
[426] Fix | Delete
inserts.pop(i + 1)
[427] Fix | Delete
[428] Fix | Delete
# produce all arg strings
[429] Fix | Delete
elif not action.option_strings:
[430] Fix | Delete
part = self._format_args(action, action.dest)
[431] Fix | Delete
[432] Fix | Delete
# if it's in a group, strip the outer []
[433] Fix | Delete
if action in group_actions:
[434] Fix | Delete
if part[0] == '[' and part[-1] == ']':
[435] Fix | Delete
part = part[1:-1]
[436] Fix | Delete
[437] Fix | Delete
# add the action string to the list
[438] Fix | Delete
parts.append(part)
[439] Fix | Delete
[440] Fix | Delete
# produce the first way to invoke the option in brackets
[441] Fix | Delete
else:
[442] Fix | Delete
option_string = action.option_strings[0]
[443] Fix | Delete
[444] Fix | Delete
# if the Optional doesn't take a value, format is:
[445] Fix | Delete
# -s or --long
[446] Fix | Delete
if action.nargs == 0:
[447] Fix | Delete
part = '%s' % option_string
[448] Fix | Delete
[449] Fix | Delete
# if the Optional takes a value, format is:
[450] Fix | Delete
# -s ARGS or --long ARGS
[451] Fix | Delete
else:
[452] Fix | Delete
default = action.dest.upper()
[453] Fix | Delete
args_string = self._format_args(action, default)
[454] Fix | Delete
part = '%s %s' % (option_string, args_string)
[455] Fix | Delete
[456] Fix | Delete
# make it look optional if it's not required or in a group
[457] Fix | Delete
if not action.required and action not in group_actions:
[458] Fix | Delete
part = '[%s]' % part
[459] Fix | Delete
[460] Fix | Delete
# add the action string to the list
[461] Fix | Delete
parts.append(part)
[462] Fix | Delete
[463] Fix | Delete
# insert things at the necessary indices
[464] Fix | Delete
for i in sorted(inserts, reverse=True):
[465] Fix | Delete
parts[i:i] = [inserts[i]]
[466] Fix | Delete
[467] Fix | Delete
# join all the action items with spaces
[468] Fix | Delete
text = ' '.join([item for item in parts if item is not None])
[469] Fix | Delete
[470] Fix | Delete
# clean up separators for mutually exclusive groups
[471] Fix | Delete
open = r'[\[(]'
[472] Fix | Delete
close = r'[\])]'
[473] Fix | Delete
text = _re.sub(r'(%s) ' % open, r'\1', text)
[474] Fix | Delete
text = _re.sub(r' (%s)' % close, r'\1', text)
[475] Fix | Delete
text = _re.sub(r'%s *%s' % (open, close), r'', text)
[476] Fix | Delete
text = _re.sub(r'\(([^|]*)\)', r'\1', text)
[477] Fix | Delete
text = text.strip()
[478] Fix | Delete
[479] Fix | Delete
# return the text
[480] Fix | Delete
return text
[481] Fix | Delete
[482] Fix | Delete
def _format_text(self, text):
[483] Fix | Delete
if '%(prog)' in text:
[484] Fix | Delete
text = text % dict(prog=self._prog)
[485] Fix | Delete
text_width = max(self._width - self._current_indent, 11)
[486] Fix | Delete
indent = ' ' * self._current_indent
[487] Fix | Delete
return self._fill_text(text, text_width, indent) + '\n\n'
[488] Fix | Delete
[489] Fix | Delete
def _format_action(self, action):
[490] Fix | Delete
# determine the required width and the entry label
[491] Fix | Delete
help_position = min(self._action_max_length + 2,
[492] Fix | Delete
self._max_help_position)
[493] Fix | Delete
help_width = max(self._width - help_position, 11)
[494] Fix | Delete
action_width = help_position - self._current_indent - 2
[495] Fix | Delete
action_header = self._format_action_invocation(action)
[496] Fix | Delete
[497] Fix | Delete
# ho nelp; start on same line and add a final newline
[498] Fix | Delete
if not action.help:
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function