我们从Python开源项目中,提取了以下18个代码示例,用于说明如何使用optparse.BadOptionError()。
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]
def _process_long_opt(self, rargs, values): try: optparse.OptionParser._process_long_opt(self, rargs, values) except optparse.BadOptionError, err: self.largs.append(err.opt_str)
def _process_short_opts(self, rargs, values): try: optparse.OptionParser._process_short_opts(self, rargs, values) except optparse.BadOptionError, err: self.largs.append(err.opt_str)
def _process_long_opt(self, rargs, values): try: optparse.OptionParser._process_long_opt(self, rargs, values) except optparse.BadOptionError: pass
def _process_short_opts(self, rargs, values): try: optparse.OptionParser._process_short_opts(self, rargs, values) except optparse.BadOptionError: pass
def _process_args(self, largs, rargs, values): while rargs: try: optparse.OptionParser._process_args(self, largs, rargs, values) except (optparse.BadOptionError, optparse.AmbiguousOptionError), e: largs.append(e.opt_str)
def _match_long_opt(self, opt): # This disable shortcuts so that '--ignorecount' is not parsed '--ignore' which conflics with "vw --ignore" if opt in self._long_opt: return opt raise optparse.BadOptionError(opt)
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
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)
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)
def _process_args(self, largs, rargs, values): while rargs: try: optparse.OptionParser._process_args(self, largs, rargs, values) except (optparse.BadOptionError, optparse.AmbiguousOptionError) as exc: largs.append(exc.opt_str)
def _process_args(_, largs, rargs, values): while rargs: try: optparse.OptionParser._process_args(_, largs, rargs, values) except (optparse.BadOptionError, optparse.AmbiguousOptionError) as E: largs.append(E.opt_str)