Xmlparser module: getNodes is now a generator

This commit is contained in:
nemunaire 2014-10-02 07:03:27 +02:00
parent ada19a221c
commit ce9dec7ed4
2 changed files with 2 additions and 6 deletions

View File

@ -66,8 +66,7 @@ def cmd_books(msg):
res = Response(channel=msg.channel, res = Response(channel=msg.channel,
title="%s" % (title), count=" (%d more books)") title="%s" % (title), count=" (%d more books)")
books = search_books(title) for book in search_books(title):
for book in books:
res.append_message("%s, writed by %s" % (book.getNode("best_book").getNode("title").getContent(), book.getNode("best_book").getNode("author").getNode("name").getContent())) res.append_message("%s, writed by %s" % (book.getNode("best_book").getNode("title").getContent(), book.getNode("best_book").getNode("author").getNode("name").getContent()))
return res return res

View File

@ -152,15 +152,12 @@ class ModuleState:
def getNodes(self, tagname): def getNodes(self, tagname):
"""Get all direct childs that have the given tagname""" """Get all direct childs that have the given tagname"""
ret = list()
for child in self.childs: for child in self.childs:
if tagname is None or tagname == child.name: if tagname is None or tagname == child.name:
ret.append(child) yield child
return ret
def hasNode(self, tagname): def hasNode(self, tagname):
"""Return True if at least one node with the given tagname exists""" """Return True if at least one node with the given tagname exists"""
ret = list()
for child in self.childs: for child in self.childs:
if tagname is None or tagname == child.name: if tagname is None or tagname == child.name:
return True return True