From 5a4296fa73905dbc1c8419d2dfbd7a45464aa61c Mon Sep 17 00:00:00 2001 From: Abhinav Sarkar Date: Wed, 25 Mar 2009 10:25:20 +0000 Subject: [PATCH] fixed bugs in authenticate and depaginate decorators --- lastfm/decorators.py | 17 ++++++++++------- lastfm/user.py | 6 +++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lastfm/decorators.py b/lastfm/decorators.py index 302451e..2997586 100644 --- a/lastfm/decorators.py +++ b/lastfm/decorators.py @@ -81,20 +81,20 @@ def authenticate(func, *args, **kwargs): if isinstance(self, User): username = self.name if self.authenticated: - return func(self, *args, **kwargs) + return func(*args, **kwargs) elif hasattr(self, 'user'): username = self.user.name if self.user.authenticated: - return func(self, *args, **kwargs) + return func(*args, **kwargs) elif hasattr(self, '_subject') and isinstance(self._subject, User): username = self._subject.name if self._subject.authenticated: - return func(self, *args, **kwargs) + return func(*args, **kwargs) elif hasattr(self, '_api') and isinstance(self._api, Api): try: user = self._api.get_authenticated_user() username = user.name - return func(self, *args, **kwargs) + return func(*args, **kwargs) except AuthenticationFailedError: pass raise AuthenticationFailedError( @@ -120,9 +120,12 @@ def depaginate(func, *args, **kwargs): for e in gen: yield e for page in xrange(2, total_pages+1): - kwargs['page'] = page - gen = func(*args, **kwargs) - gen.next() + new_args = list(args) + new_args[-1] = page + new_args = tuple(new_args) + gen = func(*new_args, **kwargs) + if gen.next() is None: + continue for e in gen: yield e return generator() diff --git a/lastfm/user.py b/lastfm/user.py index 55ee06d..f7e3488 100644 --- a/lastfm/user.py +++ b/lastfm/user.py @@ -758,7 +758,7 @@ class User(LastfmBase, Cacheable, Shoutable): ) ) except LastfmError: - return + yield None @cached_property def albums(self): @@ -811,7 +811,7 @@ class User(LastfmBase, Cacheable, Shoutable): image = dict([(i.get('size'), i.text) for i in a.findall('image')]), ) except LastfmError: - return + yield None @cached_property def artists(self): @@ -863,7 +863,7 @@ class User(LastfmBase, Cacheable, Shoutable): image = dict([(i.get('size'), i.text) for i in t.findall('image')]), ) except LastfmError: - return + yield None @cached_property def tracks(self):