Ejemplo n.º 1
0
def check_builtin(option, opt, value):
    (cvt, what) = _builtin_cvt[option.type]
    try:
        return cvt(value)
    except ValueError:
        raise OptionValueError(
            _("option %s: invalid %s value: %r") % (opt, what, value))
Ejemplo n.º 2
0
def check_choice(option, opt, value):
    if value in option.choices:
        return value
    else:
        choices = ", ".join(map(repr, option.choices))
        raise OptionValueError(
            _("option %s: invalid choice: %r (choose from %s)") %
            (opt, value, choices))
Ejemplo n.º 3
0
 def format_usage(self, usage):
     return "%s  %s\n" % (self.format_heading(_("Usage")), usage)
Ejemplo n.º 4
0
 def format_usage(self, usage):
     return _("Usage: %s\n") % usage
Ejemplo n.º 5
0
    else:  # decimal
        radix = 10

    return type(val, radix)


def _parse_int(val):
    return _parse_num(val, int)


def _parse_long(val):
    return _parse_num(val, long)


_builtin_cvt = {
    "int": (_parse_int, _("integer")),
    "long": (_parse_long, _("long integer")),
    "float": (float, _("floating-point")),
    "complex": (complex, _("complex"))
}


def check_builtin(option, opt, value):
    (cvt, what) = _builtin_cvt[option.type]
    try:
        return cvt(value)
    except ValueError:
        raise OptionValueError(
            _("option %s: invalid %s value: %r") % (opt, what, value))