本文整理匯總了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)