From 3abb1900bbcafc78a7ec0b61a9f2e3134951d0ab Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 16 Aug 2010 20:30:52 +0000 Subject: [PATCH] add __iter__ method to schemas --- colander/__init__.py | 4 ++++ colander/tests.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/colander/__init__.py b/colander/__init__.py index c420e99..2cadd6b 100644 --- a/colander/__init__.py +++ b/colander/__init__.py @@ -1179,6 +1179,10 @@ class SchemaNode(object): raise TypeError('Unknown keyword arguments: %s' % repr(kw)) self.children = list(children) + def __iter__(self): + """ Iterate over the children nodes of this schema node """ + return iter(self.children) + def __repr__(self): return '<%s.%s object at %d (named %s)>' % ( self.__module__, diff --git a/colander/tests.py b/colander/tests.py index 562bf80..b5c8323 100644 --- a/colander/tests.py +++ b/colander/tests.py @@ -1395,6 +1395,12 @@ class TestSchemaNode(unittest.TestCase): node = self._makeOne(None) self.assertRaises(KeyError, node.__getitem__, 'another') + def test___iter__(self): + node = self._makeOne(None) + node.children = ['a', 'b', 'c'] + it = node.__iter__() + self.assertEqual(list(it), ['a', 'b', 'c']) + def test_clone(self): inner_typ = DummyType() outer_typ = DummyType()