Example #1
0
    def __init__(self, property_name, property_type, constraint):
        super(InRange, self).__init__(property_name, property_type, constraint)
        if(not isinstance(self.constraint_value, collections.Sequence) or
           (len(constraint[self.IN_RANGE]) != 2)):
            raise InvalidSchemaError(message=_('in_range must be a list.'))

        for value in self.constraint_value:
            if not isinstance(value, self.valid_types):
                raise InvalidSchemaError(_('in_range value must '
                                           'be comparable.'))

        self.min = self.constraint_value[0]
        self.max = self.constraint_value[1]
Example #2
0
    def __init__(self, name, schema_dict):
        self.name = name
        if not isinstance(schema_dict, collections.Mapping):
            msg = _("Schema %(pname)s must be a dict.") % dict(pname=name)
            raise InvalidSchemaError(message=msg)

        try:
            schema_dict['type']
        except KeyError:
            msg = _("Schema %(pname)s must have type.") % dict(pname=name)
            raise InvalidSchemaError(message=msg)

        self.schema = schema_dict
        self._len = None
        self.constraints_list = []
Example #3
0
    def __new__(cls, property_name, property_type, constraint):
        if cls is not Constraint:
            return super(Constraint, cls).__new__(cls)

        if(not isinstance(constraint, collections.Mapping) or
           len(constraint) != 1):
            raise InvalidSchemaError(message=_('Invalid constraint schema.'))

        for type in constraint.keys():
            ConstraintClass = get_constraint_class(type)
            if not ConstraintClass:
                msg = _('Invalid constraint type "%s".') % type
                raise InvalidSchemaError(message=msg)

        return ConstraintClass(property_name, property_type, constraint)
Example #4
0
    def __init__(self, name, value=None, schema=None):
        self.name = name
        self.value = value
        self.schema = schema

        try:
            self.schema['type']
        except KeyError:
            msg = (_("Property definition of %(pname)s must have type.") %
                   dict(pname=self.name))
            raise InvalidSchemaError(message=msg)
Example #5
0
 def __init__(self, property_name, property_type, constraint):
     self.property_name = property_name
     self.property_type = property_type
     self.constraint_value = constraint[self.constraint_key]
     self.constraint_value_msg = self.constraint_value
     if self.property_type == Schema.SCALAR_UNIT_SIZE:
         if isinstance(self.constraint_value, list):
             self.constraint_value = [Constraint.
                                      get_num_from_scalar_unit_size(v)
                                      for v in self.constraint_value]
         else:
             self.constraint_value = (Constraint.
                                      get_num_from_scalar_unit_size
                                      (self.constraint_value))
     # check if constraint is valid for property type
     if property_type not in self.valid_prop_types:
         msg = _('Constraint type "%(ctype)s" is not valid '
                 'for data type "%(dtype)s".') % dict(
                     ctype=self.constraint_key,
                     dtype=property_type)
         raise InvalidSchemaError(message=msg)
Example #6
0
 def __init__(self, property_name, property_type, constraint):
     super(Pattern, self).__init__(property_name, property_type, constraint)
     if not isinstance(self.constraint_value, self.valid_types):
         raise InvalidSchemaError(message=_('pattern must be string.'))
     self.match = re.compile(self.constraint_value).match
Example #7
0
 def __init__(self, property_name, property_type, constraint):
     super(MaxLength, self).__init__(property_name, property_type,
                                     constraint)
     if not isinstance(self.constraint_value, self.valid_types):
         raise InvalidSchemaError(message=_('max_length must be integer.'))
Example #8
0
 def __init__(self, property_name, property_type, constraint):
     super(ValidValues, self).__init__(property_name, property_type,
                                       constraint)
     if not isinstance(self.constraint_value, collections.Sequence):
         raise InvalidSchemaError(message=_('valid_values must be a list.'))
Example #9
0
 def __init__(self, property_name, property_type, constraint):
     super(LessOrEqual, self).__init__(property_name, property_type,
                                       constraint)
     if not isinstance(self.constraint_value, self.valid_types):
         raise InvalidSchemaError(message=_('less_or_equal must '
                                            'be comparable.'))
Example #10
0
 def __init__(self, property_name, property_type, constraint):
     super(GreaterThan, self).__init__(property_name, property_type,
                                       constraint)
     if not isinstance(constraint[self.GREATER_THAN], self.valid_types):
         raise InvalidSchemaError(message=_('greater_than must '
                                            'be comparable.'))