コード例 #1
0
ファイル: iterables.py プロジェクト: alfredodeza/notario
 def safe_type(self, data, tree):
     """
     Make sure that the incoming data complies with the class type we
     are expecting it to be. In this case, classes that inherit from this
     base class expect data to be of type ``list``.
     """
     if not isinstance(data, list):
         name = self.__class__.__name__
         msg = "did not pass validation against callable: %s" % name
         reason = 'expected a list but got %s' % safe_repr(data)
         raise Invalid(self.schema, tree, reason=reason, pair='value', msg=msg)
コード例 #2
0
 def safe_type(self, data, tree):
     """
     Make sure that the incoming data complies with the class type we
     are expecting it to be. In this case, classes that inherit from this
     base class expect data to be of type ``list``.
     """
     if not isinstance(data, list):
         name = self.__class__.__name__
         msg = "did not pass validation against callable: %s" % name
         reason = 'expected a list but got %s' % safe_repr(data)
         raise Invalid(self.schema,
                       tree,
                       reason=reason,
                       pair='value',
                       msg=msg)
コード例 #3
0
ファイル: decorators.py プロジェクト: ktdreyer/notario
def not_empty(_object):
    """
    Validates the given input (has to be a valid data structure) is empty.
    Input *has* to be one of: `list`, `dict`, or `string`.

    It is specially useful when most of the validators being created are
    dealing with data structures that should not be empty.
    """
    if is_callable(_object):
        _validator = _object

        @wraps(_validator)
        @instance_of()
        def decorated(value):
            ensure(value, "%s is empty" % safe_repr(value))
            return _validator(value)
        return decorated
    try:
        ensure(len(_object), "%s is empty" % safe_repr(_object))
    except TypeError:
        raise AssertionError("not of any valid types: [list, dict, str]")
コード例 #4
0
ファイル: decorators.py プロジェクト: STEI-ITB/roseph
def not_empty(_object):
    """
    Validates the given input (has to be a valid data structure) is empty.
    Input *has* to be one of: `list`, `dict`, or `string`.

    It is specially useful when most of the validators being created are
    dealing with data structures that should not be empty.
    """
    if is_callable(_object):
        _validator = _object

        @wraps(_validator)
        @instance_of()
        def decorated(value):
            ensure(value, "%s is empty" % safe_repr(value))
            return _validator(value)

        return decorated
    try:
        ensure(len(_object), "%s is empty" % safe_repr(_object))
    except TypeError:
        raise AssertionError("not of any valid types: [list, dict, str]")
コード例 #5
0
ファイル: decorators.py プロジェクト: STEI-ITB/roseph
 def decorated(value):
     ensure(value, "%s is empty" % safe_repr(value))
     return _validator(value)
コード例 #6
0
ファイル: decorators.py プロジェクト: STEI-ITB/roseph
 def valid_names(self):
     return [safe_repr(obj) for obj in self.valid_types]
コード例 #7
0
ファイル: engine.py プロジェクト: shaunduncan/notario
 def data_sanity(self, data, tree=None):
     if not isinstance(data, list):
         name = self.name or 'IterableValidator'
         reason = 'expected a list but got %s' % safe_repr(data)
         msg = 'did not pass validation against callable: %s' % name
         raise Invalid('', tree or [], msg=msg, reason=reason, pair='value')
コード例 #8
0
ファイル: decorators.py プロジェクト: ktdreyer/notario
 def decorated(value):
     ensure(value, "%s is empty" % safe_repr(value))
     return _validator(value)
コード例 #9
0
ファイル: decorators.py プロジェクト: ktdreyer/notario
 def valid_names(self):
     return [safe_repr(obj)
             for obj in self.valid_types]
コード例 #10
0
 def data_sanity(self, data, tree=None):
     if not isinstance(data, list):
         name = self.name or 'IterableValidator'
         reason = 'expected a list but got %s' % safe_repr(data)
         msg = 'did not pass validation against callable: %s' % name
         raise Invalid('', tree or [], msg=msg, reason=reason, pair='value')
コード例 #11
0
 def __init__(self, *schemas):
     for schema in schemas:
         if not is_schema(schema):
             raise TypeError("got a non schema argument: %s" % safe_repr(schema))
     self.schemas = schemas