Permalink
Browse files

Added deferred validators support to colander.All validator

  • Loading branch information...
1 parent 3ac4589 commit 8212f11ddb261c420c46fdf7d4f4ad2ba9b91c0e @igudym committed Oct 25, 2012
Showing with 13 additions and 1 deletion.
  1. +12 −0 colander/__init__.py
  2. +1 −1 colander/tests/test_colander.py
View
@@ -193,6 +193,16 @@ def __call__(self, node, value):
exc.children.extend(e.children)
raise exc
+ def _bind(self, node, kw):
+ bound = []
+ for validator in self.validators:
+ if isinstance(validator, deferred):
+ bound.append(validator(node, kw))
+ else:
+ bound.append(validator)
+ self.validators = bound
+
+
class Function(object):
""" Validator which accepts a function and an optional message;
the function is called with the ``value`` during validation.
@@ -1834,6 +1844,8 @@ def _bind(self, kw):
if isinstance(v, deferred):
v = v(self, kw)
setattr(self, k, v)
+ if isinstance(self.validator, All):
+ self.validator._bind(self, kw)
if getattr(self, 'after_bind', None):
self.after_bind(self, kw)
@@ -2157,7 +2157,7 @@ def test_deserialize_all_with_deferred_validator(self):
node = self._makeOne(typ, validator=All(DummyDeferredValidator))
node = node.bind(message='good')
e = invalid_exc(node.deserialize, 1)
- self.assertEqual(e.msg, 'good')
+ self.assertEqual(e.msg, ['good'])
def test_deserialize_value_is_null_no_missing(self):
from colander import null

0 comments on commit 8212f11

Please sign in to comment.