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