Beispiel #1
0
 def __inner(input):
     if not isinstance(input, (tuple, list)):
         raise Invalid("expected sequence")
     errs = MultipleInvalid()
     result = []
     for ndx, elem in enumerate(input):
         try:
             result.append(validator(elem))
         except Invalid as exc:
             exc.path.append(ndx)
             errs.add(exc)
     if errs.errors:
         raise errs
     if isinstance(input, tuple):
         result = tuple(result)
     return result
Beispiel #2
0
 def __inner(dct):
     if not isinstance(dct, dict):
         raise DictInvalid("expected dict")
     errs = MultipleInvalid()
     result = {}
     for k, v in dct.items():
         key, key_err = __schema_validate(key_validator, k)
         val, val_err = __schema_validate(value_validator, v)
         if not (key_err or val_err):
             result[key_validator(key)] = value_validator(val)
         else:
             if key_err:
                 # wrap in KeyInvalid to aid distinction
                 # between key- and value errors
                 err = __wrap_err(KeyInvalid, key_err)
                 errs.add(err)
             if val_err:
                 val_err.path.append(k)
                 errs.add(val_err)
     if errs.errors:
         raise errs
     return result