Esempio n. 1
0
    def _default_validation(self, context):

        for error in Member._default_validation(self, context):
            yield error

        for error in self._range_validation(context):
            yield error
Esempio n. 2
0
    def _default_validation(self, context):
        """Validation rule for string values. Checks the L{min}, L{max} and
        L{format} constraints."""

        for error in Member._default_validation(self, context):
            yield error

        if context.value is not None:

            # Min length
            min = self.resolve_constraint(self.min, context)

            if min is not None and len(context.value) < min:
                yield MinLengthError(context, min)

            # Max length
            else:
                max = self.resolve_constraint(self.max, context)

                if max is not None and len(context.value) > max:
                    yield MaxLengthError(context, max)

            # Format
            format = self.resolve_constraint(self.format, context)

            if format is not None and not format.search(context.value):
                yield FormatError(context, format)
Esempio n. 3
0
    def _default_validation(self, context):
        """Validation rule for schemas. Applies the validation rules defined by
        all members in the schema, propagating their errors."""

        for error in Member._default_validation(self, context):
            yield error

        accessor = (self.accessor or context.get("accessor", None)
                    or get_accessor(context.value))
        languages = context.get("languages")

        for member in self.ordered_members():
            key = member.name

            if member.translated:
                for language in (languages
                                 or accessor.languages(context.value, key)):
                    value = accessor.get(context.value, key, language=language)
                    for error in member.get_errors(value,
                                                   parent_context=context,
                                                   language=language):
                        yield error
            else:
                value = accessor.get(context.value, key, default=None)

                for error in member.get_errors(value, parent_context=context):
                    yield error
Esempio n. 4
0
    def _default_validation(self, context):

        for error in Member._default_validation(self, context):
            yield error

        if context.value is not None:

            value_length = len(context.value)
            expected_length = len(self.items)

            if value_length < expected_length:
                yield MinItemsError(context, expected_length)

            elif value_length > expected_length:
                yield MaxItemsError(context, expected_length)

            for item_member, item in zip(self.items, context.value):
                for error in item_member.get_errors(item,
                                                    parent_context=context):
                    yield error