예제 #1
0
    def validate(self, value):
        verrors = ValidationErrors()

        for attr in self.attrs.values():
            if attr.name in value:
                try:
                    attr.validate(value[attr.name])
                except ValidationErrors as e:
                    verrors.add_child(self.name, e)

        for v in value:
            if v not in Cron.FIELDS:
                verrors.add(self.name, f'Unexpected {v} value')

        if verrors:
            raise verrors

        cron_expression = ''
        for field in Cron.FIELDS:
            cron_expression += value.get(field) + ' ' if value.get(field) else '* '

        try:
            croniter(cron_expression)
        except Exception as e:
            verrors.add(self.name, 'Please ensure fields match cron syntax - ' + str(e))

        if verrors:
            raise verrors
예제 #2
0
    def validate(self, value):
        verrors = ValidationErrors()

        for attr in self.attrs.values():
            if attr.name in value:
                try:
                    attr.validate(value[attr.name])
                except ValidationErrors as e:
                    verrors.add_child(self.name, e)

        for v in value:
            if v not in Cron.FIELDS:
                verrors.add(self.name, f'Unexpected {v} value')

        if verrors:
            raise verrors

        cron_expression = ''
        for field in Cron.FIELDS:
            cron_expression += value.get(field) + ' ' if value.get(
                field) else '* '

        try:
            croniter(cron_expression)
        except Exception as e:
            verrors.add(self.name,
                        'Please ensure fields match cron syntax - ' + str(e))

        if verrors:
            raise verrors
예제 #3
0
    def validate(self, value):
        if value is None:
            return

        verrors = ValidationErrors()

        s = set()
        for i, v in enumerate(value):
            if self.unique:
                if isinstance(v, dict):
                    v = tuple(sorted(list(v.items())))
                if v in s:
                    verrors.add(f"{self.name}.{i}", "This value is not unique.")
                s.add(v)
            attr_verrors = ValidationErrors()
            for attr in self.items:
                try:
                    attr.validate(v)
                except ValidationErrors as e:
                    attr_verrors.add_child(f"{self.name}.{i}", e)
                else:
                    break
            else:
                verrors.extend(attr_verrors)

        if verrors:
            raise verrors

        super().validate(value)
예제 #4
0
def construct_schema(
    item_version_details: dict, new_values: dict, update: bool, old_values: Union[dict, object] = NOT_PROVIDED
) -> dict:
    schema_name = f'chart_release_{"update" if update else "create"}'
    attrs = list(itertools.chain.from_iterable(
        get_schema(q, update, old_values) for q in item_version_details['schema']['questions']
    ))
    dict_obj = update_conditional_defaults(
        Dict(schema_name, *attrs, update=update, additional_attrs=True), {
            'schema': {'attrs': item_version_details['schema']['questions']}
        }
    )

    verrors = ValidationErrors()
    verrors.add_child('values', validate_schema(
        attrs, new_values, True, dict_kwargs={
            'conditional_defaults': dict_obj.conditional_defaults, 'update': update,
        }
    ))
    return {
        'verrors': verrors,
        'new_values': new_values,
        'dict_obj': dict_obj,
        'schema_name': schema_name,
    }
예제 #5
0
    def validate(self, value):
        if value is None:
            return

        verrors = ValidationErrors()

        for attr in self.attrs.values():
            if attr.name in value:
                try:
                    attr.validate(value[attr.name])
                except ValidationErrors as e:
                    verrors.add_child(self.name, e)

        for v in value:
            if self.begin_end and v in ['begin', 'end']:
                continue
            if v not in Cron.FIELDS:
                verrors.add(self.name, f'Unexpected {v} value')

        if verrors:
            raise verrors

        cron_expression = ''
        for field in Cron.FIELDS:
            cron_expression += value.get(field) + ' ' if value.get(
                field) else '* '

        try:
            iter = croniter(cron_expression)
        except Exception as e:
            iter = None
            verrors.add(self.name,
                        'Please ensure fields match cron syntax - ' + str(e))

        if value.get('begin') and value.get('end') and not (
                value.get('begin') <= value.get('end')):
            verrors.add(self.name,
                        'Begin time should be less or equal than end time')

        if iter is not None and (value.get('begin') or value.get('end')):
            begin = value.get('begin') or time(0, 0)
            end = value.get('end') or time(23, 59)
            for i in range(24 * 60):
                d = iter.get_next(datetime)
                if begin <= d.time() <= end:
                    break
            else:
                verrors.add(
                    self.name,
                    'Specified schedule does not match specified time interval'
                )

        if verrors:
            raise verrors
예제 #6
0
파일: schema.py 프로젝트: qimingnan/freenas
    def validate(self, value):
        verrors = ValidationErrors()

        for attr in self.attrs.values():
            if attr.name in value:
                try:
                    attr.validate(value[attr.name])
                except ValidationErrors as e:
                    verrors.add_child(self.name, e)

        if verrors:
            raise verrors
예제 #7
0
파일: schema.py 프로젝트: qimingnan/freenas
    def validate(self, value):
        verrors = ValidationErrors()

        for i, v in enumerate(value):
            for attr in self.items:
                try:
                    attr.validate(v)
                except ValidationErrors as e:
                    verrors.add_child(f"{self.name}.{i}", e)

        if verrors:
            raise verrors
예제 #8
0
    def validate(self, value):
        verrors = ValidationErrors()

        for attr in self.attrs.values():
            if attr.name in value:
                try:
                    attr.validate(value[attr.name])
                except ValidationErrors as e:
                    verrors.add_child(self.name, e)

        if verrors:
            raise verrors
예제 #9
0
    def validate(self, value):
        verrors = ValidationErrors()

        for i, v in enumerate(value):
            for attr in self.items:
                try:
                    attr.validate(v)
                except ValidationErrors as e:
                    verrors.add_child(f"{self.name}.{i}", e)

        if verrors:
            raise verrors
예제 #10
0
    def validate(self, value):
        if value is None:
            return

        verrors = ValidationErrors()

        for attr in self.attrs.values():
            if attr.name in value:
                try:
                    attr.validate(value[attr.name])
                except ValidationErrors as e:
                    verrors.add_child(self.name, e)

        for v in value:
            if self.begin_end and v in ['begin', 'end']:
                continue
            if v not in Cron.FIELDS:
                verrors.add(self.name, f'Unexpected {v} value')

        if verrors:
            raise verrors

        cron_expression = ''
        for field in Cron.FIELDS:
            cron_expression += value.get(field) + ' ' if value.get(
                field) else '* '

        try:
            croniter(cron_expression)
        except Exception as e:
            verrors.add(self.name,
                        'Please ensure fields match cron syntax - ' + str(e))

        if value.get('begin') and value.get('end') and not (
                value.get('begin') <= value.get('end')):
            verrors.add(self.name,
                        'Begin time should be less or equal than end time')

        if verrors:
            raise verrors
예제 #11
0
    def validate(self, value):
        if value is None:
            return

        verrors = ValidationErrors()

        s = set()
        for i, v in enumerate(value):
            if self.unique:
                if v in s:
                    verrors.add(f"{self.name}.{i}",
                                "This value is not unique.")
                s.add(v)
            for attr in self.items:
                try:
                    attr.validate(v)
                except ValidationErrors as e:
                    verrors.add_child(f"{self.name}.{i}", e)

        if verrors:
            raise verrors

        super().validate(value)
예제 #12
0
파일: schema.py 프로젝트: freenas/freenas
    def validate(self, value):
        if value is None:
            return

        verrors = ValidationErrors()

        for attr in self.attrs.values():
            if attr.name in value:
                try:
                    attr.validate(value[attr.name])
                except ValidationErrors as e:
                    verrors.add_child(self.name, e)

        for v in value:
            if self.begin_end and v in ['begin', 'end']:
                continue
            if v not in Cron.FIELDS:
                verrors.add(self.name, f'Unexpected {v} value')

        if verrors:
            raise verrors

        cron_expression = ''
        for field in Cron.FIELDS:
            cron_expression += value.get(field) + ' ' if value.get(field) else '* '

        try:
            croniter(cron_expression)
        except Exception as e:
            verrors.add(self.name, 'Please ensure fields match cron syntax - ' + str(e))

        if value.get('begin') and value.get('end') and not (value.get('begin') <= value.get('end')):
            verrors.add(self.name, 'Begin time should be less or equal than end time')

        if verrors:
            raise verrors
예제 #13
0
파일: schema.py 프로젝트: freenas/freenas
    def validate(self, value):
        if value is None:
            return

        verrors = ValidationErrors()

        s = set()
        for i, v in enumerate(value):
            if self.unique:
                if isinstance(v, dict):
                    v = tuple(sorted(list(v.items())))
                if v in s:
                    verrors.add(f"{self.name}.{i}", "This value is not unique.")
                s.add(v)
            for attr in self.items:
                try:
                    attr.validate(v)
                except ValidationErrors as e:
                    verrors.add_child(f"{self.name}.{i}", e)

        if verrors:
            raise verrors

        super().validate(value)