예제 #1
0
 def __call__(self, v):
     error = None
     for schema in self._schemas:
         try:
             return schema(v)
         except Invalid as e:
             if error is None or len(e.path) > len(error.path):
                 error = e
     else:
         if error:
             raise error if self.msg is None else AnyInvalid(self.msg)
         raise AnyInvalid(self.msg or 'no valid value found')
예제 #2
0
 def _exec(self, funcs, v, path=None):
     error = None
     for func in funcs:
         try:
             if path is None:
                 return func(v)
             else:
                 return func(path, v)
         except Invalid as e:
             if error is None or len(e.path) > len(error.path):
                 error = e
     else:
         if error:
             raise error if self.msg is None else AnyInvalid(self.msg)
         raise AnyInvalid(self.msg or 'no valid value found')