Beispiel #1
0
 def __init__(self, field_type, get=None, set=None, *args, **kwargs):
     super(MethodField, self).__init__(field_type, *args, **kwargs)
     if get is not None:
         if not callable(get):
             get = constant(get)
     if set is not None:
         if not callable(set):
             set = constant(set)
     self.get_method = get
     self.set_method = set
Beispiel #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)
Beispiel #3
0
 def test_constant_returns_function_that_takes_any_arguments_and_always_returns_given_value(
         self):
     f = constant(123)
     assert f() == 123
     assert f(456) == 123
     assert f(1, 3, 5) == 123
     assert f(1, foo='bar') == 123
Beispiel #4
0
 def __init__(self, field_type, attribute=None, *args, **kwargs):
     super(AttributeField, self).__init__(field_type, *args, **kwargs)
     if attribute is None:
         attribute = identity
     elif not callable(attribute):
         attribute = constant(attribute)
     self.name_to_attribute = attribute