當前位置: 首頁>>代碼示例>>Python>>正文


Python optparse.OptionValueError方法代碼示例

本文整理匯總了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) 
開發者ID:singhj,項目名稱:locality-sensitive-hashing,代碼行數:18,代碼來源:config.py

示例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 
開發者ID:skarlekar,項目名稱:faces,代碼行數:23,代碼來源:frontend.py

示例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) 
開發者ID:skarlekar,項目名稱:faces,代碼行數:23,代碼來源:frontend.py

示例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 
開發者ID:jmwright,項目名稱:cadquery-freecad-module,代碼行數:24,代碼來源:frontend.py

示例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 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:9,代碼來源:config.py

示例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 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:9,代碼來源:config.py

示例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)) 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:11,代碼來源:config.py

示例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) 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:7,代碼來源:config.py

示例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)) 
開發者ID:AtomLinter,項目名稱:linter-pylama,代碼行數:13,代碼來源:config.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:8,代碼來源:baseparser.py

示例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 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:10,代碼來源:config.py

示例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)) 
開發者ID:sofia-netsurv,項目名稱:python-netsurv,代碼行數:11,代碼來源:config.py

示例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) 
開發者ID:Autodesk,項目名稱:arnold-usd,代碼行數:7,代碼來源:SConsOptions.py

示例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 
開發者ID:virtualrealitysystems,項目名稱:aumfor,代碼行數:8,代碼來源:conf.py


注:本文中的optparse.OptionValueError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。