From 82a9d5e19422b233461fb035473c21c42da8ded2 Mon Sep 17 00:00:00 2001 From: jortel Date: Thu, 1 Apr 2010 15:53:57 +0000 Subject: Add proper iterator for Element. --- suds/sax/element.py | 35 +++++++++++++++++++++++++++++++++++ suds/umx/core.py | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/suds/sax/element.py b/suds/sax/element.py index ca44801..0a015f1 100644 --- a/suds/sax/element.py +++ b/suds/sax/element.py @@ -923,6 +923,41 @@ class Element: def __unicode__(self): return self.str() + + def __iter__(self): + return NodeIterator(self) + + +class NodeIterator: + """ + The L{Element} child node iterator. + @ivar pos: The current position + @type pos: int + @ivar children: A list of a child nodes. + @type children: [L{Element},..] + """ + + def __init__(self, parent): + """ + @param parent: An element to iterate. + @type parent: L{Element} + """ + self.pos = 0 + self.children = parent.children + + def next(self): + """ + Get the next child. + @return: The next child. + @rtype: L{Element} + @raise StopIterator: At the end. + """ + try: + child = self.children[self.pos] + self.pos += 1 + return child + except: + raise StopIteration() class PrefixNormalizer: diff --git a/suds/umx/core.py b/suds/umx/core.py index 7fb4ac4..07d33c4 100644 --- a/suds/umx/core.py +++ b/suds/umx/core.py @@ -135,7 +135,7 @@ class Core: @param content: The current content being unmarshalled. @type content: L{Content} """ - for child in content.node.children: + for child in content.node: cont = Content(child) cval = self.append(cont) key = reserved.get(child.name, child.name) -- cgit v1.2.1