Exemplo n.º 1
0
    def validate(self, value):
        if value is None:
            return value

        value = super(IntegerArgument, self).validate(value)
        if not isinstance(value, int):
            raise InvalidArgument("Expected an integer for %s received %r" %
                                  (self.name, value))
        return value
Exemplo n.º 2
0
    def override(self, **kwargs):
        for key, value in kwargs.items():
            try:
                arg = self._arguments[key]
            except KeyError:
                raise Fail("%s received unsupported argument %s" % (self, key))
            else:
                if value != self.arguments.get(key):
                    if not arg.allow_override:
                        raise Fail(
                            "%s doesn't allow overriding argument '%s'" %
                            (self, key))

                    try:
                        self.arguments[key] = arg.validate(value)
                    except InvalidArgument, exc:
                        raise InvalidArgument("%s %s" % (self, exc))
Exemplo n.º 3
0
    def __init__(self, name, env=None, provider=None, **kwargs):
        if isinstance(name, list):
            name = name.pop(0)

        if hasattr(self, 'name'):
            return

        self.env = env or Environment.get_instance()
        self.name = name

        self.provider = provider or getattr(self, 'provider', None)

        self.arguments = {}
        for key, value in kwargs.items():
            try:
                arg = self._arguments[key]
            except KeyError:
                raise Fail("%s received unsupported argument %s" % (self, key))
            else:
                try:
                    self.arguments[key] = arg.validate(value)
                except InvalidArgument, exc:
                    raise InvalidArgument("%s %s" % (self, exc))
Exemplo n.º 4
0
 def validate(self, value):
     value = super(BooleanArgument, self).validate(value)
     if not value in (True, False):
         raise InvalidArgument("Expected a boolean for %s received %r" %
                               (self.name, value))
     return value
Exemplo n.º 5
0
 def validate(self, value):
     if self.required and value is None:
         raise InvalidArgument("Required argument %s missing" % self.name)
     return value