Beispiel #1
0
 def _check_choice(self):
     if self.type == "choice":
         if self.choices is None:
             raise OptionError(
                 "must supply a list of choices for type 'choice'", self)
         elif type(self.choices) not in (TupleType, ListType):
             raise OptionError(
                 "choices must be a list of strings ('%s' supplied)"
                 % string.split(str(type(self.choices)),"'")[1], self)
     elif self.choices is not None:
         raise OptionError(
             "must not supply choices for type %s" % (repr(self.type),), self)
Beispiel #2
0
 def _check_nargs(self):
     if self.action in self.TYPED_ACTIONS:
         if self.nargs is None:
             self.nargs = 1
     elif self.nargs is not None:
         raise OptionError(
             "'nargs' must not be supplied for action %s" %
             (repr(self.action), ), self)
Beispiel #3
0
 def _check_opt_strings(self, opts):
     # Filter out None because early versions of Optik had exactly
     # one short option and one long option, either of which
     # could be None.
     opts = filter(None, opts)
     if not opts:
         raise OptionError("at least one option string must be supplied",
                           self)
     return opts
Beispiel #4
0
 def _check_callback(self):
     if self.action == "callback":
         if not callable(self.callback):
             raise OptionError(
                 "callback not callable: %s" % (repr(self.callback), ),
                 self)
         if (self.callback_args is not None
                 and type(self.callback_args) is not TupleType):
             raise OptionError(
                 "callback_args, if supplied, must be a tuple: not %s" %
                 (repr(self.callback_args), ), self)
         if (self.callback_kwargs is not None
                 and type(self.callback_kwargs) is not DictType):
             raise OptionError(
                 "callback_kwargs, if supplied, must be a dict: not %s" %
                 (repr(self.callback_kwargs), ), self)
     else:
         if self.callback is not None:
             raise OptionError(
                 "callback supplied (%s) for non-callback option" %
                 (repr(self.callback), ), self)
         if self.callback_args is not None:
             raise OptionError(
                 "callback_args supplied for non-callback option", self)
         if self.callback_kwargs is not None:
             raise OptionError(
                 "callback_kwargs supplied for non-callback option", self)
Beispiel #5
0
 def _set_attrs(self, attrs):
     for attr in self.ATTRS:
         if attrs.has_key(attr):
             setattr(self, attr, attrs[attr])
             del attrs[attr]
         else:
             if attr == 'default':
                 setattr(self, attr, NO_DEFAULT)
             else:
                 setattr(self, attr, None)
     if attrs:
         raise OptionError(
             "invalid keyword arguments: %s" %
             string.join(attrs.keys(), ", "), self)
Beispiel #6
0
 def _check_const(self):
     if self.action != "store_const" and self.const is not None:
         raise OptionError(
             "'const' must not be supplied for action %s" %
             (repr(self.action), ), self)