本文整理汇总了Python中optparse.OptionValueError方法的典型用法代码示例。如果您正苦于以下问题:Python optparse.OptionValueError方法的具体用法?Python optparse.OptionValueError怎么用?Python optparse.OptionValueError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类optparse
的用法示例。
在下文中一共展示了optparse.OptionValueError方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _applyConfigurationToValues
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionValueError [as 别名]
def _applyConfigurationToValues(self, parser, config, values):
for name, value, filename in config:
if name in option_blacklist:
continue
try:
self._processConfigValue(name, value, values, parser)
except NoSuchOptionError, exc:
self._file_error(
"Error reading config file %r: "
"no such option %r" % (filename, exc.name),
name=name, filename=filename)
except optparse.OptionValueError, exc:
msg = str(exc).replace('--' + name, repr(name), 1)
self._file_error("Error reading config file %r: "
"%s" % (filename, msg),
name=name, filename=filename)
示例2: process
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionValueError [as 别名]
def process(self, opt, value, values, parser):
"""
Call the validator function on applicable settings and
evaluate the 'overrides' option.
Extends `optparse.Option.process`.
"""
result = optparse.Option.process(self, opt, value, values, parser)
setting = self.dest
if setting:
if self.validator:
value = getattr(values, setting)
try:
new_value = self.validator(setting, value, parser)
except Exception as error:
raise optparse.OptionValueError(
'Error in option "%s":\n %s'
% (opt, ErrorString(error)))
setattr(values, setting, new_value)
if self.overrides:
setattr(values, self.overrides, None)
return result
示例3: process
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionValueError [as 别名]
def process(self, opt, value, values, parser):
"""
Call the validator function on applicable settings and
evaluate the 'overrides' option.
Extends `optparse.Option.process`.
"""
result = optparse.Option.process(self, opt, value, values, parser)
setting = self.dest
if setting:
if self.validator:
value = getattr(values, setting)
try:
new_value = self.validator(setting, value, parser)
except Exception, error:
raise (optparse.OptionValueError(
'Error in option "%s":\n %s'
% (opt, ErrorString(error))),
None, sys.exc_info()[2])
setattr(values, setting, new_value)
if self.overrides:
setattr(values, self.overrides, None)
示例4: process
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionValueError [as 别名]
def process(self, opt, value, values, parser):
"""
Call the validator function on applicable settings and
evaluate the 'overrides' option.
Extends `optparse.Option.process`.
"""
result = optparse.Option.process(self, opt, value, values, parser)
setting = self.dest
if setting:
if self.validator:
value = getattr(values, setting)
try:
new_value = self.validator(setting, value, parser)
except Exception as error:
raise (optparse.OptionValueError(
'Error in option "%s":\n %s'
% (opt, ErrorString(error))),
None, sys.exc_info()[2])
setattr(values, setting, new_value)
if self.overrides:
setattr(values, self.overrides, None)
return result
示例5: _multiple_choice_validator
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionValueError [as 别名]
def _multiple_choice_validator(choices, name, value):
values = utils._check_csv(value)
for csv_value in values:
if csv_value not in choices:
msg = "option %s: invalid value: %r, should be in %s"
raise optparse.OptionValueError(msg % (name, csv_value, choices))
return values
示例6: _choice_validator
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionValueError [as 别名]
def _choice_validator(choices, name, value):
if value not in choices:
msg = "option %s: invalid value: %r, should be in %s"
raise optparse.OptionValueError(msg % (name, value, choices))
return value
# pylint: disable=unused-argument
示例7: _yn_validator
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionValueError [as 别名]
def _yn_validator(opt, _, value):
if isinstance(value, int):
return bool(value)
if value in ('y', 'yes'):
return True
if value in ('n', 'no'):
return False
msg = "option %s: invalid yn value %r, should be in (y, yes, n, no)"
raise optparse.OptionValueError(msg % (opt, value))
示例8: _non_empty_string_validator
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionValueError [as 别名]
def _non_empty_string_validator(opt, _, value):
if not value:
msg = "indent string can't be empty."
raise optparse.OptionValueError(msg)
return utils._unquote(value)
示例9: _call_validator
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionValueError [as 别名]
def _call_validator(opttype, optdict, option, value):
if opttype not in VALIDATORS:
raise Exception('Unsupported type "%s"' % opttype)
try:
return VALIDATORS[opttype](optdict, option, value)
except TypeError:
try:
return VALIDATORS[opttype](value)
except Exception:
raise optparse.OptionValueError('%s value (%r) should be of type %s' %
(option, value, opttype))
示例10: check_default
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionValueError [as 别名]
def check_default(self, option, key, val):
try:
return option.check_value(key, val)
except optparse.OptionValueError as exc:
print("An error occurred during configuration: %s" % exc)
sys.exit(3)
示例11: _choice_validator
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionValueError [as 别名]
def _choice_validator(choices, name, value):
if value not in choices:
msg = "option %s: invalid value: %r, should be in %s"
raise optparse.OptionValueError(msg % (name, value, choices))
return value
# pylint: disable=unused-argument
示例12: _yn_validator
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionValueError [as 别名]
def _yn_validator(opt, _, value):
if isinstance(value, int):
return bool(value)
if value in ("y", "yes"):
return True
if value in ("n", "no"):
return False
msg = "option %s: invalid yn value %r, should be in (y, yes, n, no)"
raise optparse.OptionValueError(msg % (opt, value))
示例13: error
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionValueError [as 别名]
def error(self, msg):
# overridden OptionValueError exception handler
self.print_usage(sys.stderr)
sys.stderr.write("SCons Error: %s\n" % msg)
sys.exit(2)
示例14: _process_args
# 需要导入模块: import optparse [as 别名]
# 或者: from optparse import OptionValueError [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