From 3be36894399ecc3bdb9d39dd8bb4480bfcde79f2 Mon Sep 17 00:00:00 2001 From: Romain Bignon Date: Sat, 10 Nov 2012 13:15:01 +0100 Subject: [PATCH] correctly use iterators --- modules/cragr/backend.py | 7 ++----- modules/cragr/pages/accounts_list.py | 5 ++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/modules/cragr/backend.py b/modules/cragr/backend.py index ab4053ab..ff2e70d2 100644 --- a/modules/cragr/backend.py +++ b/modules/cragr/backend.py @@ -84,8 +84,7 @@ class CragrBackend(BaseBackend, ICapBank): self.config['password'].get()) def iter_accounts(self): - for account in self.browser.get_accounts_list(): - yield account + return self.browser.get_accounts_list() def get_account(self, _id): if not _id.isdigit(): @@ -97,9 +96,7 @@ class CragrBackend(BaseBackend, ICapBank): raise AccountNotFound() def iter_history(self, account): - for history in self.browser.get_history(account): - yield history - + return self.browser.get_history(account) def transfer(self, account, to, amount, reason=None): return self.browser.do_transfer(account, to, amount, reason) diff --git a/modules/cragr/pages/accounts_list.py b/modules/cragr/pages/accounts_list.py index 477bf409..1d13ba17 100644 --- a/modules/cragr/pages/accounts_list.py +++ b/modules/cragr/pages/accounts_list.py @@ -87,7 +87,6 @@ class AccountsList(CragrBasePage): """ Returns the list of available bank accounts """ - l = [] for div in self.document.getiterator('div'): if div.attrib.get('class', '') in ('dv', 'headline') and div.getchildren()[0].tag in ('a', 'br'): self.logger.debug("Analyzing div %s" % div) @@ -128,8 +127,8 @@ class AccountsList(CragrBasePage): self.logger.debug(' the history link appears to be %s' % account._link_id) else: account._link_id = None - l.append(account) - return l + + yield account def get_history(self, start_index=0, start_offset=0): """