Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3....
File: optparse.py
option.process(opt, value, values, self)
[1500] Fix | Delete
[1501] Fix | Delete
def _process_short_opts(self, rargs, values):
[1502] Fix | Delete
arg = rargs.pop(0)
[1503] Fix | Delete
stop = False
[1504] Fix | Delete
i = 1
[1505] Fix | Delete
for ch in arg[1:]:
[1506] Fix | Delete
opt = "-" + ch
[1507] Fix | Delete
option = self._short_opt.get(opt)
[1508] Fix | Delete
i += 1 # we have consumed a character
[1509] Fix | Delete
[1510] Fix | Delete
if not option:
[1511] Fix | Delete
raise BadOptionError(opt)
[1512] Fix | Delete
if option.takes_value():
[1513] Fix | Delete
# Any characters left in arg? Pretend they're the
[1514] Fix | Delete
# next arg, and stop consuming characters of arg.
[1515] Fix | Delete
if i < len(arg):
[1516] Fix | Delete
rargs.insert(0, arg[i:])
[1517] Fix | Delete
stop = True
[1518] Fix | Delete
[1519] Fix | Delete
nargs = option.nargs
[1520] Fix | Delete
if len(rargs) < nargs:
[1521] Fix | Delete
self.error(ngettext(
[1522] Fix | Delete
"%(option)s option requires %(number)d argument",
[1523] Fix | Delete
"%(option)s option requires %(number)d arguments",
[1524] Fix | Delete
nargs) % {"option": opt, "number": nargs})
[1525] Fix | Delete
elif nargs == 1:
[1526] Fix | Delete
value = rargs.pop(0)
[1527] Fix | Delete
else:
[1528] Fix | Delete
value = tuple(rargs[0:nargs])
[1529] Fix | Delete
del rargs[0:nargs]
[1530] Fix | Delete
[1531] Fix | Delete
else: # option doesn't take a value
[1532] Fix | Delete
value = None
[1533] Fix | Delete
[1534] Fix | Delete
option.process(opt, value, values, self)
[1535] Fix | Delete
[1536] Fix | Delete
if stop:
[1537] Fix | Delete
break
[1538] Fix | Delete
[1539] Fix | Delete
[1540] Fix | Delete
# -- Feedback methods ----------------------------------------------
[1541] Fix | Delete
[1542] Fix | Delete
def get_prog_name(self):
[1543] Fix | Delete
if self.prog is None:
[1544] Fix | Delete
return os.path.basename(sys.argv[0])
[1545] Fix | Delete
else:
[1546] Fix | Delete
return self.prog
[1547] Fix | Delete
[1548] Fix | Delete
def expand_prog_name(self, s):
[1549] Fix | Delete
return s.replace("%prog", self.get_prog_name())
[1550] Fix | Delete
[1551] Fix | Delete
def get_description(self):
[1552] Fix | Delete
return self.expand_prog_name(self.description)
[1553] Fix | Delete
[1554] Fix | Delete
def exit(self, status=0, msg=None):
[1555] Fix | Delete
if msg:
[1556] Fix | Delete
sys.stderr.write(msg)
[1557] Fix | Delete
sys.exit(status)
[1558] Fix | Delete
[1559] Fix | Delete
def error(self, msg):
[1560] Fix | Delete
"""error(msg : string)
[1561] Fix | Delete
[1562] Fix | Delete
Print a usage message incorporating 'msg' to stderr and exit.
[1563] Fix | Delete
If you override this in a subclass, it should not return -- it
[1564] Fix | Delete
should either exit or raise an exception.
[1565] Fix | Delete
"""
[1566] Fix | Delete
self.print_usage(sys.stderr)
[1567] Fix | Delete
self.exit(2, "%s: error: %s\n" % (self.get_prog_name(), msg))
[1568] Fix | Delete
[1569] Fix | Delete
def get_usage(self):
[1570] Fix | Delete
if self.usage:
[1571] Fix | Delete
return self.formatter.format_usage(
[1572] Fix | Delete
self.expand_prog_name(self.usage))
[1573] Fix | Delete
else:
[1574] Fix | Delete
return ""
[1575] Fix | Delete
[1576] Fix | Delete
def print_usage(self, file=None):
[1577] Fix | Delete
"""print_usage(file : file = stdout)
[1578] Fix | Delete
[1579] Fix | Delete
Print the usage message for the current program (self.usage) to
[1580] Fix | Delete
'file' (default stdout). Any occurrence of the string "%prog" in
[1581] Fix | Delete
self.usage is replaced with the name of the current program
[1582] Fix | Delete
(basename of sys.argv[0]). Does nothing if self.usage is empty
[1583] Fix | Delete
or not defined.
[1584] Fix | Delete
"""
[1585] Fix | Delete
if self.usage:
[1586] Fix | Delete
print(self.get_usage(), file=file)
[1587] Fix | Delete
[1588] Fix | Delete
def get_version(self):
[1589] Fix | Delete
if self.version:
[1590] Fix | Delete
return self.expand_prog_name(self.version)
[1591] Fix | Delete
else:
[1592] Fix | Delete
return ""
[1593] Fix | Delete
[1594] Fix | Delete
def print_version(self, file=None):
[1595] Fix | Delete
"""print_version(file : file = stdout)
[1596] Fix | Delete
[1597] Fix | Delete
Print the version message for this program (self.version) to
[1598] Fix | Delete
'file' (default stdout). As with print_usage(), any occurrence
[1599] Fix | Delete
of "%prog" in self.version is replaced by the current program's
[1600] Fix | Delete
name. Does nothing if self.version is empty or undefined.
[1601] Fix | Delete
"""
[1602] Fix | Delete
if self.version:
[1603] Fix | Delete
print(self.get_version(), file=file)
[1604] Fix | Delete
[1605] Fix | Delete
def format_option_help(self, formatter=None):
[1606] Fix | Delete
if formatter is None:
[1607] Fix | Delete
formatter = self.formatter
[1608] Fix | Delete
formatter.store_option_strings(self)
[1609] Fix | Delete
result = []
[1610] Fix | Delete
result.append(formatter.format_heading(_("Options")))
[1611] Fix | Delete
formatter.indent()
[1612] Fix | Delete
if self.option_list:
[1613] Fix | Delete
result.append(OptionContainer.format_option_help(self, formatter))
[1614] Fix | Delete
result.append("\n")
[1615] Fix | Delete
for group in self.option_groups:
[1616] Fix | Delete
result.append(group.format_help(formatter))
[1617] Fix | Delete
result.append("\n")
[1618] Fix | Delete
formatter.dedent()
[1619] Fix | Delete
# Drop the last "\n", or the header if no options or option groups:
[1620] Fix | Delete
return "".join(result[:-1])
[1621] Fix | Delete
[1622] Fix | Delete
def format_epilog(self, formatter):
[1623] Fix | Delete
return formatter.format_epilog(self.epilog)
[1624] Fix | Delete
[1625] Fix | Delete
def format_help(self, formatter=None):
[1626] Fix | Delete
if formatter is None:
[1627] Fix | Delete
formatter = self.formatter
[1628] Fix | Delete
result = []
[1629] Fix | Delete
if self.usage:
[1630] Fix | Delete
result.append(self.get_usage() + "\n")
[1631] Fix | Delete
if self.description:
[1632] Fix | Delete
result.append(self.format_description(formatter) + "\n")
[1633] Fix | Delete
result.append(self.format_option_help(formatter))
[1634] Fix | Delete
result.append(self.format_epilog(formatter))
[1635] Fix | Delete
return "".join(result)
[1636] Fix | Delete
[1637] Fix | Delete
def print_help(self, file=None):
[1638] Fix | Delete
"""print_help(file : file = stdout)
[1639] Fix | Delete
[1640] Fix | Delete
Print an extended help message, listing all options and any
[1641] Fix | Delete
help text provided with them, to 'file' (default stdout).
[1642] Fix | Delete
"""
[1643] Fix | Delete
if file is None:
[1644] Fix | Delete
file = sys.stdout
[1645] Fix | Delete
file.write(self.format_help())
[1646] Fix | Delete
[1647] Fix | Delete
# class OptionParser
[1648] Fix | Delete
[1649] Fix | Delete
[1650] Fix | Delete
def _match_abbrev(s, wordmap):
[1651] Fix | Delete
"""_match_abbrev(s : string, wordmap : {string : Option}) -> string
[1652] Fix | Delete
[1653] Fix | Delete
Return the string key in 'wordmap' for which 's' is an unambiguous
[1654] Fix | Delete
abbreviation. If 's' is found to be ambiguous or doesn't match any of
[1655] Fix | Delete
'words', raise BadOptionError.
[1656] Fix | Delete
"""
[1657] Fix | Delete
# Is there an exact match?
[1658] Fix | Delete
if s in wordmap:
[1659] Fix | Delete
return s
[1660] Fix | Delete
else:
[1661] Fix | Delete
# Isolate all words with s as a prefix.
[1662] Fix | Delete
possibilities = [word for word in wordmap.keys()
[1663] Fix | Delete
if word.startswith(s)]
[1664] Fix | Delete
# No exact match, so there had better be just one possibility.
[1665] Fix | Delete
if len(possibilities) == 1:
[1666] Fix | Delete
return possibilities[0]
[1667] Fix | Delete
elif not possibilities:
[1668] Fix | Delete
raise BadOptionError(s)
[1669] Fix | Delete
else:
[1670] Fix | Delete
# More than one possible completion: ambiguous prefix.
[1671] Fix | Delete
possibilities.sort()
[1672] Fix | Delete
raise AmbiguousOptionError(s, possibilities)
[1673] Fix | Delete
[1674] Fix | Delete
[1675] Fix | Delete
# Some day, there might be many Option classes. As of Optik 1.3, the
[1676] Fix | Delete
# preferred way to instantiate Options is indirectly, via make_option(),
[1677] Fix | Delete
# which will become a factory function when there are many Option
[1678] Fix | Delete
# classes.
[1679] Fix | Delete
make_option = Option
[1680] Fix | Delete
[1681] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function