コード例 #1
0
def validate_element(element, validator, schema=SCHEMA):
    if validator.validate(element, schema) is not True:
        field, errors = next(validator.errors.iteritems())
        message_string = "\nElement of type '{0}' has the following errors:\n{1}"
        error_strings = ("{0}: {1}".format(
            k, v if isinstance(v, str) else ", ".join(v))
                         for k, v in errors.iteritems())
        raise cerberus.ValidationError(
            message_string.format(field, "\n".join(error_strings)))
コード例 #2
0
def cerberus_validation(schema, kwargs):
    """
        Validates a cerberus schema
            Displays errors & raise exception if validation fails
    """
    schema.validate(kwargs)

    if not schema.validate(kwargs):
        msg = ''
        for key, value in schema.errors.items():
            msg += 'key: {} - {}'.format(key, value)
        raise cerberus.ValidationError(msg)
コード例 #3
0
def validate_element(element, validator, schema=SCHEMA):
    """
        Validates each element according to schema.
        Args:
            element: An element from the OpenStreetMap data
            validator: The cerberus validator
            schema: The desired format 'SCHEMA'
        
        Raises:
            Raise ValidationError if element does not match schema
    """
    if validator.validate(element, schema) is not True:
        field, errors = next(validator.errors.iteritems())
        message_string = "\nElement of type '{0}' has the following errors:\n{1}"
        error_strings = ("{0}: {1}".format(
            k, v if isinstance(v, str) else ", ".join(v))
                         for k, v in errors.iteritems())
        raise cerberus.ValidationError(
            message_string.format(field, "\n".join(error_strings)))
コード例 #4
0
ファイル: kvdb.py プロジェクト: MrKiven/PY-Snip
 def validate(self, value):
     v = cerberus.Validator(schema=self.schema, allow_unknown=True)
     if not v.validate(value):
         raise cerberus.ValidationError(v.errors)