本文整理汇总了Python中argparse.HelpFormatter方法的典型用法代码示例。如果您正苦于以下问题:Python argparse.HelpFormatter方法的具体用法?Python argparse.HelpFormatter怎么用?Python argparse.HelpFormatter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类argparse
的用法示例。
在下文中一共展示了argparse.HelpFormatter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_arguments
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def get_arguments(self):
''' Returns parser.args() containing all program arguments '''
parser = argparse.ArgumentParser(usage=argparse.SUPPRESS,
formatter_class=lambda prog: argparse.HelpFormatter(
prog, max_help_position=80, width=130))
self._add_global_args(parser.add_argument_group(Color.s('{C}SETTINGS{W}')))
self._add_wep_args(parser.add_argument_group(Color.s('{C}WEP{W}')))
self._add_wpa_args(parser.add_argument_group(Color.s('{C}WPA{W}')))
self._add_wps_args(parser.add_argument_group(Color.s('{C}WPS{W}')))
self._add_pmkid_args(parser.add_argument_group(Color.s('{C}PMKID{W}')))
self._add_eviltwin_args(parser.add_argument_group(Color.s('{C}EVIL TWIN{W}')))
self._add_command_args(parser.add_argument_group(Color.s('{C}COMMANDS{W}')))
return parser.parse_args()
示例2: main
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def main(argv):
def formatter(prog):
return argparse.HelpFormatter(prog, max_help_position=100, width=200)
argparser = argparse.ArgumentParser('NLI Client', formatter_class=formatter)
argparser.add_argument('s1', action='store', type=str)
argparser.add_argument('s2', action='store', type=str)
argparser.add_argument('--url', '-u', action='store', type=str, default='http://127.0.0.1:8889/v1/nli')
args = argparser.parse_args(argv)
sentence1 = args.s1
sentence2 = args.s2
url = args.url
prediction = call_service(url=url, sentence1=sentence1, sentence2=sentence2)
print(prediction)
示例3: main
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def main(argv):
def formatter(prog):
return argparse.HelpFormatter(prog, max_help_position=100, width=200)
argparser = argparse.ArgumentParser('Filtering tool for filtering away infrequent entities from Knowledge Graphs',
formatter_class=formatter)
argparser.add_argument('triples', type=str, help='File containing triples')
argparser.add_argument('entities', type=str, help='File containing entities')
args = argparser.parse_args(argv)
triples_path = args.triples
entities_path = args.entities
triples = read_triples(triples_path)
with iopen(entities_path, mode='r') as f:
entities = set([line.strip() for line in f.readlines()])
for (s, p, o) in triples:
if s in entities and o in entities:
print("%s\t%s\t%s" % (s, p, o))
示例4: _find_actions
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def _find_actions(self, subparsers, actions_module):
for attr in (a for a in dir(actions_module) if a.startswith('do_')):
# I prefer to be hypen-separated instead of underscores.
command = attr[3:].replace('_', '-')
callback = getattr(actions_module, attr)
desc = callback.__doc__ or ''
help = desc.strip().split('\n')[0]
arguments = getattr(callback, 'arguments', [])
subparser = subparsers.add_parser(command, help=help,
description=desc,
add_help=False,
formatter_class=HelpFormatter)
subparser.add_argument('-h', '--help', action='help',
help=argparse.SUPPRESS)
self.subcommands[command] = subparser
for (args, kwargs) in arguments:
subparser.add_argument(*args, **kwargs)
subparser.set_defaults(func=callback)
示例5: _find_actions
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def _find_actions(self, subparsers, actions_module):
for attr in (a for a in dir(actions_module) if a.startswith('do_')):
# I prefer to be hyphen-separated instead of underscores.
command = attr[3:].replace('_', '-')
callback = getattr(actions_module, attr)
desc = callback.__doc__ or ''
help = desc.strip().split('\n')[0]
arguments = getattr(callback, 'arguments', [])
subparser = subparsers.add_parser(command,
help=help,
description=desc,
add_help=False,
formatter_class=HelpFormatter)
subparser.add_argument('-h', '--help',
action='help',
help=argparse.SUPPRESS)
self.subcommands[command] = subparser
for (args, kwargs) in arguments:
subparser.add_argument(*args, **kwargs)
subparser.set_defaults(func=callback)
示例6: download_parser
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def download_parser(description):
class SortedHelpFormatter(HelpFormatter):
def add_arguments(self, actions):
actions = sorted(actions, key=attrgetter("option_strings"))
super(SortedHelpFormatter, self).add_arguments(actions)
parser = ArgumentParser(
description=description, formatter_class=SortedHelpFormatter
)
parser.add_argument("--force", action="store_true", help="override existing files")
parser.add_argument(
"--formats", nargs="+", metavar="FORMAT", help="ebook formats (epub, mobi, pdf)"
)
parser.add_argument(
"--with-code-files", action="store_true", help="download code files"
)
return parser
示例7: __init__
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def __init__(
self, add_blink_args=True, add_model_args=False,
description='BLINK parser',
):
super().__init__(
description=description,
allow_abbrev=False,
conflict_handler='resolve',
formatter_class=argparse.HelpFormatter,
add_help=add_blink_args,
)
self.blink_home = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
)
os.environ['BLINK_HOME'] = self.blink_home
self.add_arg = self.add_argument
self.overridable = {}
if add_blink_args:
self.add_blink_args()
if add_model_args:
self.add_model_args()
示例8: _split_lines
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def _split_lines(self, text, width):
if text.startswith('R|'):
lines = text[2:].splitlines()
offsets = [re.match("^[ \t]*", l).group(0) for l in lines]
wrapped = []
for i in range(len(lines)):
li = lines[i]
o = offsets[i]
ol = len(o)
init_wrap = argparse._textwrap.fill(li, width).splitlines()
first = init_wrap[0]
rest = "\n".join(init_wrap[1:])
rest_wrap = argparse._textwrap.fill(rest, width - ol).splitlines()
offset_lines = [o + wl for wl in rest_wrap]
wrapped = wrapped + [first] + offset_lines
return wrapped
return argparse.HelpFormatter._split_lines(self, text, width)
示例9: __init__
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def __init__(self, *args, group_name=None, **kwargs):
super().__init__(*args, formatter_class=HelpFormatter, add_help=False, **kwargs)
self.add_argument(
'--help', dest='help', action='store_true', default=False,
help='Show this help message and exit.'
)
self._optionals.title = 'Options'
if group_name is None:
self.epilog = (
f"Run 'lbrynet COMMAND --help' for more information on a command or group."
)
else:
self.epilog = (
f"Run 'lbrynet {group_name} COMMAND --help' for more information on a command."
)
self.set_defaults(group=group_name, group_parser=self)
示例10: get_args
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def get_args():
parser = argparse.ArgumentParser( prog="primefaces.py",
formatter_class=lambda prog: argparse.HelpFormatter(prog,max_help_position=50),
epilog= '''
This script exploits an expression language remote code execution flaw in the Primefaces JSF framework.
Primefaces versions prior to 5.2.21, 5.3.8 or 6.0 are vulnerable to a padding oracle attack,
due to the use of weak crypto and default encryption password and salt.
''')
parser.add_argument("target", help="Target Host")
parser.add_argument("-pw", "--password", default="primefaces", help="Primefaces Password (Default = primefaces")
parser.add_argument("-pt", "--path", default="/javax.faces.resource/dynamiccontent.properties.xhtml", help="Path to dynamiccontent.properties (Default = /javax.faces.resource/dynamiccontent.properties.xhtml)")
parser.add_argument("-c", "--cmd", default="whoami", help="Command to execute. (Default = whoami)")
parser.add_argument("-px", "--proxy", default="", help="Configure a proxy in the format http://127.0.0.1:8080/ (Default = None)")
parser.add_argument("-ck", "--cookie", default="", help="Configure a cookie in the format 'COOKIE=VALUE; COOKIE2=VALUE2;' (Default = None)")
parser.add_argument("-o", "--oracle", default="0", help="Exploit the target with Padding Oracle. Use 1 to activate. (Default = 0) (SLOW)")
parser.add_argument("-pl", "--payload", default="", help="EL Encrypted payload. That function is meant to be used with the Padding Oracle generated payload. (Default = None) ")
args = parser.parse_args()
return args
示例11: _split_lines
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def _split_lines(self, text, width):
""" Split the given text by the given display width.
If the text is not prefixed with "R|" then the standard
:func:`argparse.HelpFormatter._split_lines` function is used, otherwise raw
formatting is processed,
Parameters
----------
text: str
The help text that is to be formatted for display
width: int
The display width, in characters, for the help text
"""
if text.startswith("R|"):
text = self._whitespace_matcher_limited.sub(' ', text).strip()[2:]
output = list()
for txt in text.splitlines():
indent = ""
if txt.startswith("L|"):
indent = " "
txt = " - {}".format(txt[2:])
output.extend(textwrap.wrap(txt, width, subsequent_indent=indent))
return output
return argparse.HelpFormatter._split_lines(self, text, width)
示例12: __init__
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def __init__(self, prog=''):
argparse.HelpFormatter.__init__(
self, prog, max_help_position=100, width=150)
示例13: _format_action_invocation
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def _format_action_invocation(self, action):
orgstr = argparse.HelpFormatter._format_action_invocation(self, action)
if orgstr and orgstr[0] != "-": # only optional arguments
return orgstr
res = getattr(action, "_formatted_action_invocation", None)
if res:
return res
options = orgstr.split(", ")
if len(options) == 2 and (len(options[0]) == 2 or len(options[1]) == 2):
# a shortcut for '-h, --help' or '--abc', '-a'
action._formatted_action_invocation = orgstr
return orgstr
return_list = []
option_map = getattr(action, "map_long_option", {})
if option_map is None:
option_map = {}
short_long = {}
for option in options:
if len(option) == 2 or option[2] == " ":
continue
if not option.startswith("--"):
raise ArgumentError(
'long optional argument without "--": [%s]' % (option), self
)
xxoption = option[2:]
if xxoption.split()[0] not in option_map:
shortened = xxoption.replace("-", "")
if shortened not in short_long or len(short_long[shortened]) < len(
xxoption
):
short_long[shortened] = xxoption
# now short_long has been filled out to the longest with dashes
# **and** we keep the right option ordering from add_argument
for option in options:
if len(option) == 2 or option[2] == " ":
return_list.append(option)
if option[2:] == short_long.get(option.replace("-", "")):
return_list.append(option.replace(" ", "=", 1))
action._formatted_action_invocation = ", ".join(return_list)
return action._formatted_action_invocation
示例14: test_parser
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def test_parser(self):
parser = argparse.ArgumentParser(prog='PROG')
string = (
"ArgumentParser(prog='PROG', usage=None, description=None, "
"version=None, formatter_class=%r, conflict_handler='error', "
"add_help=True)" % argparse.HelpFormatter)
self.assertStringEqual(parser, string)
# ===============
# Namespace tests
# ===============
示例15: _split_lines
# 需要导入模块: import argparse [as 别名]
# 或者: from argparse import HelpFormatter [as 别名]
def _split_lines(self, text, width):
if text.startswith('R|'):
return text[2:].splitlines()
return argparse.HelpFormatter._split_lines(self, text, width)