fixed bugs in authenticate and depaginate decorators
parent
bbdbfcebb6
commit
5a4296fa73
|
@ -81,20 +81,20 @@ def authenticate(func, *args, **kwargs):
|
||||||
if isinstance(self, User):
|
if isinstance(self, User):
|
||||||
username = self.name
|
username = self.name
|
||||||
if self.authenticated:
|
if self.authenticated:
|
||||||
return func(self, *args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
elif hasattr(self, 'user'):
|
elif hasattr(self, 'user'):
|
||||||
username = self.user.name
|
username = self.user.name
|
||||||
if self.user.authenticated:
|
if self.user.authenticated:
|
||||||
return func(self, *args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
elif hasattr(self, '_subject') and isinstance(self._subject, User):
|
elif hasattr(self, '_subject') and isinstance(self._subject, User):
|
||||||
username = self._subject.name
|
username = self._subject.name
|
||||||
if self._subject.authenticated:
|
if self._subject.authenticated:
|
||||||
return func(self, *args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
elif hasattr(self, '_api') and isinstance(self._api, Api):
|
elif hasattr(self, '_api') and isinstance(self._api, Api):
|
||||||
try:
|
try:
|
||||||
user = self._api.get_authenticated_user()
|
user = self._api.get_authenticated_user()
|
||||||
username = user.name
|
username = user.name
|
||||||
return func(self, *args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
except AuthenticationFailedError:
|
except AuthenticationFailedError:
|
||||||
pass
|
pass
|
||||||
raise AuthenticationFailedError(
|
raise AuthenticationFailedError(
|
||||||
|
@ -120,9 +120,12 @@ def depaginate(func, *args, **kwargs):
|
||||||
for e in gen:
|
for e in gen:
|
||||||
yield e
|
yield e
|
||||||
for page in xrange(2, total_pages+1):
|
for page in xrange(2, total_pages+1):
|
||||||
kwargs['page'] = page
|
new_args = list(args)
|
||||||
gen = func(*args, **kwargs)
|
new_args[-1] = page
|
||||||
gen.next()
|
new_args = tuple(new_args)
|
||||||
|
gen = func(*new_args, **kwargs)
|
||||||
|
if gen.next() is None:
|
||||||
|
continue
|
||||||
for e in gen:
|
for e in gen:
|
||||||
yield e
|
yield e
|
||||||
return generator()
|
return generator()
|
||||||
|
|
|
@ -758,7 +758,7 @@ class User(LastfmBase, Cacheable, Shoutable):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except LastfmError:
|
except LastfmError:
|
||||||
return
|
yield None
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def albums(self):
|
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')]),
|
image = dict([(i.get('size'), i.text) for i in a.findall('image')]),
|
||||||
)
|
)
|
||||||
except LastfmError:
|
except LastfmError:
|
||||||
return
|
yield None
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def artists(self):
|
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')]),
|
image = dict([(i.get('size'), i.text) for i in t.findall('image')]),
|
||||||
)
|
)
|
||||||
except LastfmError:
|
except LastfmError:
|
||||||
return
|
yield None
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def tracks(self):
|
def tracks(self):
|
||||||
|
|
Loading…
Reference in New Issue