Exemple #1
0
 def __init__(self, inner_type,
              pre_load=identity, post_load=identity,
              pre_dump=identity, post_dump=identity):
     super(Transform, self).__init__()
     self.inner_type = inner_type
     self.pre_load = make_context_aware(pre_load, 1)
     self.post_load = make_context_aware(post_load, 1)
     self.pre_dump = make_context_aware(pre_dump, 1)
     self.post_dump = make_context_aware(post_dump, 1)
Exemple #2
0
 def __init__(self, inner_type,
              load_default=None, dump_default=None,
              **kwargs):
     super(Optional, self).__init__(**kwargs)
     self.inner_type = inner_type
     if not callable(load_default):
         load_default = constant(load_default)
     if not callable(dump_default):
         dump_default = constant(dump_default)
     self.load_default = make_context_aware(load_default, 0)
     self.dump_default = make_context_aware(dump_default, 0)
Exemple #3
0
    def __init__(self, field_type, get=None, set=None, *args, **kwargs):
        super(FunctionField, self).__init__(field_type, *args, **kwargs)
        if get is not None and not callable(get):
            raise ValueError("Get function is not callable")
        if set is not None and not callable(set):
            raise ValueError("Set function is not callable")

        if get is not None:
            get = make_context_aware(get, 1)
        if set is not None:
            set = make_context_aware(set, 2)

        self.get_func = get
        self.set_func = set
Exemple #4
0
    def set_value(self, name, obj, value, context=None, *args, **kwargs):
        if not self.set_method:
            return MISSING

        method_name = self.set_method(name)
        if not hasattr(obj, method_name):
            raise ValueError('Object does not have method %s' % method_name)
        method = getattr(obj, method_name)
        if not callable(method):
            raise ValueError('Value of %s is not callable' % method_name)
        return make_context_aware(method, 1)(value, context)
Exemple #5
0
 def __init__(self, predicate, error=None, **kwargs):
     super(Predicate, self).__init__(**kwargs)
     self.predicate = make_context_aware(predicate, 1)
     if error is not None:
         self._error_messages['invalid'] = error
     self.error = error
Exemple #6
0
 def __init__(self, predicate, error=None, **kwargs):
     super(Predicate, self).__init__(**kwargs)
     self.predicate = make_context_aware(predicate, 1)
     if error is not None:
         self._error_messages['invalid'] = error
     self.error = error
Exemple #7
0
 def __setitem__(self, idx, validator):
     self._validators[idx] = make_context_aware(validator, 1)
Exemple #8
0
 def insert(self, idx, validator):
     self._validators.insert(idx, make_context_aware(validator, 1))
Exemple #9
0
 def append(self, validator):
     self._validators.append(make_context_aware(validator, 1))
Exemple #10
0
 def __init__(self, validators):
     self._validators = [make_context_aware(validator, 1)
                         for validator in validators]