本文整理汇总了Python中optparse.BadOptionError方法的典型用法代码示例。如果您正苦于以下问题:Python optparse.BadOptionError方法的具体用法?Python optparse.BadOptionError怎么用?Python optparse.BadOptionError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类optparse
的用法示例。
在下文中一共展示了optparse.BadOptionError方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _process_args
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import BadOptionError [as 别名]
def _process_args(self, largs, rargs, values):
"""little hack to support all --some_option=value parameters"""
while rargs:
arg = rargs[0]
if arg == "--":
del rargs[0]
return
elif arg[0:2] == "--":
# if parser does not know about the option
# pass it along (make it anonymous)
try:
opt = arg.split('=', 1)[0]
self._match_long_opt(opt)
except BadOptionError:
largs.append(arg)
del rargs[0]
else:
self._process_long_opt(rargs, values)
elif arg[:1] == "-" and len(arg) > 1:
self._process_short_opts(rargs, values)
elif self.allow_interspersed_args:
largs.append(arg)
del rargs[0]
示例2: _process_args
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import BadOptionError [as 别名]
def _process_args(self, largs, rargs, values):
while rargs:
try:
OptionParser._process_args(self,largs,rargs,values)
except (BadOptionError,AmbiguousOptionError) as e:
largs.append(e.opt_str)
示例3: _process_args
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import BadOptionError [as 别名]
def _process_args(self, largs, rargs, values):
while rargs:
try:
OptionParser._process_args(self,largs,rargs,values)
except (BadOptionError,AmbiguousOptionError) as e:
largs.append(e.opt_str)
示例4: _match_long_opt
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import BadOptionError [as 别名]
def _match_long_opt(self, opt):
"""Disable abbreviations."""
if opt not in self._long_opt:
raise optparse.BadOptionError(opt)
return opt
# pylint: disable=abstract-method; by design?
示例5: _process_args
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import BadOptionError [as 别名]
def _process_args(self, largs, rargs, values):
try:
return optparse.OptionParser._process_args(self, largs, rargs, values)
except (optparse.BadOptionError, optparse.OptionValueError), err:
if self.final:
raise err
示例6: _process_long_opt
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import BadOptionError [as 别名]
def _process_long_opt(self, rargs, values):
try:
OptionParser._process_long_opt(self, rargs, values)
except BadOptionError as err:
self.largs.append(err.opt_str)
示例7: _process_short_opts
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import BadOptionError [as 别名]
def _process_short_opts(self, rargs, values):
try:
OptionParser._process_short_opts(self, rargs, values)
except BadOptionError as err:
self.largs.append(err.opt_str)
示例8: _match_long_opt
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import BadOptionError [as 别名]
def _match_long_opt(self, opt):
match = optparse._match_abbrev(opt, self._long_opt)
if not self.matchPartialOptions and opt != match:
raise optparse.BadOptionError("no such option: %s" % opt)
return match
示例9: option_callback_W
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import BadOptionError [as 别名]
def option_callback_W(option, opt, value, parser):
# Options preceded by a "-Wl," are simply treated as though the "-Wl,"
# is not there? I don't understand the purpose of this code...
if len(value) < 4 or value[0:3] != "l,-":
raise optparse.BadOptionError("not in '-Wl,<opt>' form: %s%s" % (opt, value))
opt = value[2:]
if opt not in ["-L", "-R", "--rpath"]:
raise optparse.BadOptionError("-Wl option must be -L, -R" " or --rpath, not " + value[2:])
# Push the linker option onto the list for further parsing.
parser.rargs.insert(0, value)