Пример #1
0
    def __init__(self, allowed_values):
        if (not isinstance(allowed_values, collections.Sequence) or
                isinstance(allowed_values, six.string_types)):
            msg = _('AllowedValues must be a list or a string')
            raise exception.InvalidSchemaError(message=msg)

        self.allowed = tuple(allowed_values)
Пример #2
0
    def __init__(self,
                 description=None,
                 default=None,
                 required=False,
                 schema=None,
                 updatable=False,
                 readonly=False,
                 constraints=None):

        if schema is not None:
            if type(self) not in (List, Map):
                msg = _('Schema valid only for List or Map, not '
                        '"%s"') % self[self.TYPE]
                raise exception.InvalidSchemaError(message=msg)

        if self[self.TYPE] == self.LIST:
            self.schema = AnyIndexDict(schema)
        else:
            self.schema = schema

        self.description = description
        self.default = default
        self.required = required
        self.updatable = updatable
        self.constraints = constraints or []
        self.readonly = readonly
        self._len = None
Пример #3
0
    def _validate_default(self, context):
        if self.default is None:
            return

        try:
            self.validate(self.default, context)
        except (ValueError, TypeError) as exc:
            raise exception.InvalidSchemaError(
                message=_('Invalid default %(default)s (%(exc)s)') %
                dict(default=self.default, exc=exc))