moved caching attributes related code to LastfmBase.cachedProperty decorator

master
Abhinav Sarkar 2008-08-25 13:18:17 +00:00
parent 439674558a
commit 3bb7aca74f
7 changed files with 309 additions and 371 deletions

View File

@ -90,25 +90,23 @@ class Album(LastfmBase):
self._fillInfo()
return self.__stats
@property
@LastfmBase.cachedProperty
def topTags(self):
"""top tags for the album"""
if self.__topTags is None:
params = {'method': 'album.getinfo'}
if self.artist and self.name:
params.update({'artist': self.artist.name, 'album': self.name})
elif self.mbid:
params.update({'mbid': self.mbid})
data = self.__api._fetchData(params).find('album')
self.__topTags = [
Tag(
self.__api,
name = t.findtext('name'),
url = t.findtext('url')
)
for t in data.findall('toptags/tag')
]
return self.__topTags
params = {'method': 'album.getinfo'}
if self.artist and self.name:
params.update({'artist': self.artist.name, 'album': self.name})
elif self.mbid:
params.update({'mbid': self.mbid})
data = self.__api._fetchData(params).find('album')
return [
Tag(
self.__api,
name = t.findtext('name'),
url = t.findtext('url')
)
for t in data.findall('toptags/tag')
]
@LastfmBase.topProperty("topTags")
def topTag(self):

View File

@ -42,10 +42,6 @@ class Artist(LastfmBase):
summary = bio.summary,
content = bio.content
)
self.__events = None
self.__topAlbums = None
self.__topTracks = None
self.__topFans = None
@property
def name(self):
@ -151,100 +147,92 @@ class Artist(LastfmBase):
self._fillInfo()
return self.__bio
@property
@LastfmBase.cachedProperty
def events(self):
"""events for the artist"""
if self.__events is None:
params = {'method': 'artist.getevents', 'artist': self.name}
data = self.__api._fetchData(params).find('events')
params = {'method': 'artist.getevents', 'artist': self.name}
data = self.__api._fetchData(params).find('events')
self.__events = [
return [
Event.createFromData(self.__api, e)
for e in data.findall('event')
]
return self.__events
@property
@LastfmBase.cachedProperty
def topAlbums(self):
"""top albums of the artist"""
if self.__topAlbums is None:
params = {'method': 'artist.gettopalbums', 'artist': self.name}
data = self.__api._fetchData(params).find('topalbums')
params = {'method': 'artist.gettopalbums', 'artist': self.name}
data = self.__api._fetchData(params).find('topalbums')
self.__topAlbums = [
Album(
self.__api,
name = a.findtext('name'),
artist = self,
mbid = a.findtext('mbid'),
url = a.findtext('url'),
image = dict([(i.get('size'), i.text) for i in a.findall('image')]),
stats = Stats(
subject = a.findtext('name'),
playcount = int(a.findtext('playcount')),
rank = int(a.attrib['rank'])
)
)
for a in data.findall('album')
]
return self.__topAlbums
return [
Album(
self.__api,
name = a.findtext('name'),
artist = self,
mbid = a.findtext('mbid'),
url = a.findtext('url'),
image = dict([(i.get('size'), i.text) for i in a.findall('image')]),
stats = Stats(
subject = a.findtext('name'),
playcount = int(a.findtext('playcount')),
rank = int(a.attrib['rank'])
)
)
for a in data.findall('album')
]
@LastfmBase.topProperty("topAlbums")
def topAlbum(self):
"""top album of the artist"""
pass
@property
@LastfmBase.cachedProperty
def topFans(self):
"""top fans of the artist"""
if self.__topFans is None:
params = {'method': 'artist.gettopfans', 'artist': self.name}
data = self.__api._fetchData(params).find('topfans')
self.__topFans = [
User(
self.__api,
name = u.findtext('name'),
url = u.findtext('url'),
image = dict([(i.get('size'), i.text) for i in u.findall('image')]),
stats = Stats(
subject = u.findtext('name'),
weight = int(u.findtext('weight'))
)
)
for u in data.findall('user')
]
return self.__topFans
params = {'method': 'artist.gettopfans', 'artist': self.name}
data = self.__api._fetchData(params).find('topfans')
return [
User(
self.__api,
name = u.findtext('name'),
url = u.findtext('url'),
image = dict([(i.get('size'), i.text) for i in u.findall('image')]),
stats = Stats(
subject = u.findtext('name'),
weight = int(u.findtext('weight'))
)
)
for u in data.findall('user')
]
@LastfmBase.topProperty("topFans")
def topFan(self):
"""top fan of the artist"""
pass
@property
@LastfmBase.cachedProperty
def topTracks(self):
"""top tracks of the artist"""
if self.__topTracks is None:
params = {'method': 'artist.gettoptracks', 'artist': self.name}
data = self.__api._fetchData(params).find('toptracks')
self.__topTracks = [
Track(
self.__api,
name = t.findtext('name'),
artist = self,
mbid = t.findtext('mbid'),
stats = Stats(
subject = t.findtext('name'),
playcount = int(t.findtext('playcount')),
rank = int(t.attrib['rank'])
),
streamable = (t.findtext('streamable') == '1'),
fullTrack = (t.find('streamable').attrib['fulltrack'] == '1'),
image = dict([(i.get('size'), i.text) for i in t.findall('image')]),
)
for t in data.findall('track')
]
return self.__topTracks
params = {'method': 'artist.gettoptracks', 'artist': self.name}
data = self.__api._fetchData(params).find('toptracks')
return [
Track(
self.__api,
name = t.findtext('name'),
artist = self,
mbid = t.findtext('mbid'),
stats = Stats(
subject = t.findtext('name'),
playcount = int(t.findtext('playcount')),
rank = int(t.attrib['rank'])
),
streamable = (t.findtext('streamable') == '1'),
fullTrack = (t.find('streamable').attrib['fulltrack'] == '1'),
image = dict([(i.get('size'), i.text) for i in t.findall('image')]),
)
for t in data.findall('track')
]
@LastfmBase.topProperty("topTracks")
def topTrack(self):
"""topmost fan of the artist"""

View File

@ -54,6 +54,20 @@ class LastfmBase(object):
return property(fget = wrapper, doc = func.__doc__)
return decorator
@staticmethod
def cachedProperty(func):
frame = sys._getframe(1)
classname = frame.f_code.co_name
funcName = func.func_code.co_name
attributeName = "_%s__%s" % (classname, funcName)
def wrapper(ob):
cacheAttribute = getattr(ob, attributeName, None)
if cacheAttribute is None:
setattr(ob, attributeName, func(ob))
return cacheAttribute
return property(fget = wrapper, doc = func.__doc__)
def __gt__(self, other):
return not (self.__lt__(other) or self.__eq(other))
@ -66,3 +80,5 @@ class LastfmBase(object):
def __le__(self, other):
return not self.__gt__(other)
import sys

View File

@ -151,7 +151,6 @@ class Location(LastfmBase):
self.__latitude = latitude
self.__longitude = longitude
self.__timezone = timezone
self.__events = None
@property
def name(self):
@ -198,13 +197,11 @@ class Location(LastfmBase):
page = None):
return Geo.getEvents(self.__api, self.name, distance, page).matches
@property
@LastfmBase.cachedProperty
def events(self):
"""events taking place at/around the location"""
if self.__events is None:
self.__events = self.getEvents()
return self.__events
return self.getEvents()
@staticmethod
def hashFunc(*args, **kwds):
try:
@ -247,33 +244,27 @@ class Country(LastfmBase):
raise LastfmError("api reference must be supplied as an argument")
self.__api = api
self.__name = name
self.__topArtists = None
self.__topTracks = None
@property
def name(self):
"""name of the country"""
return self.__name
@property
@LastfmBase.cachedProperty
def topArtists(self):
"""top artists of the country"""
if self.__topArtists is None:
self.__topArtists = Geo.getTopArtists(self.__api, self.name)
return self.__topArtists
return Geo.getTopArtists(self.__api, self.name)
@LastfmBase.topProperty("topArtists")
def topArtist(self):
"""top artist of the country"""
pass
@property
@LastfmBase.cachedProperty
def topTracks(self):
"""top tracks of the country"""
if self.__topTracks is None:
self.__topTracks = Geo.getTopTracks(self.__api, self.name)
return self.__topTracks
return Geo.getTopTracks(self.__api, self.name)
@LastfmBase.topProperty("topTracks")
def topTrack(self):
"""top track of the country"""

View File

@ -24,11 +24,7 @@ class Tag(LastfmBase):
subject = self,
count = stats.count
)
self.__similar = None
self.__topAlbums = None
self.__topArtists = None
self.__topTracks = None
@property
def name(self):
"""name of the tag"""
@ -48,121 +44,113 @@ class Tag(LastfmBase):
def stats(self):
return self.__stats
@property
@LastfmBase.cachedProperty
def similar(self):
"""tags similar to this tag"""
if self.__similar is None:
params = {'method': 'tag.getsimilar', 'tag': self.name}
data = self.__api._fetchData(params).find('similartags')
self.__similar = [
Tag(
self.__api,
name = t.findtext('name'),
url = t.findtext('url'),
streamable = (t.findtext('streamable') == "1"),
)
for t in data.findall('tag')
]
return self.__similar
params = {'method': 'tag.getsimilar', 'tag': self.name}
data = self.__api._fetchData(params).find('similartags')
return [
Tag(
self.__api,
name = t.findtext('name'),
url = t.findtext('url'),
streamable = (t.findtext('streamable') == "1"),
)
for t in data.findall('tag')
]
@LastfmBase.topProperty("similar")
def mostSimilar(self):
"""most similar tag to this tag"""
pass
@property
@LastfmBase.cachedProperty
def topAlbums(self):
"""top albums for the tag"""
if self.__topAlbums is None:
params = {'method': 'tag.gettopalbums', 'tag': self.name}
data = self.__api._fetchData(params).find('topalbums')
self.__topAlbums = [
Album(
params = {'method': 'tag.gettopalbums', 'tag': self.name}
data = self.__api._fetchData(params).find('topalbums')
return [
Album(
self.__api,
name = a.findtext('name'),
artist = Artist(
self.__api,
name = a.findtext('name'),
artist = Artist(
self.__api,
name = a.findtext('artist/name'),
mbid = a.findtext('artist/mbid'),
url = a.findtext('artist/url'),
),
mbid = a.findtext('mbid'),
url = a.findtext('url'),
image = dict([(i.get('size'), i.text) for i in a.findall('image')]),
stats = Stats(
subject = a.findtext('name'),
tagcount = a.findtext('tagcount') and int(a.findtext('tagcount')) or None,
rank = a.attrib['rank'].strip() and int(a.attrib['rank']) or None
)
)
for a in data.findall('album')
]
return self.__topAlbums
name = a.findtext('artist/name'),
mbid = a.findtext('artist/mbid'),
url = a.findtext('artist/url'),
),
mbid = a.findtext('mbid'),
url = a.findtext('url'),
image = dict([(i.get('size'), i.text) for i in a.findall('image')]),
stats = Stats(
subject = a.findtext('name'),
tagcount = a.findtext('tagcount') and int(a.findtext('tagcount')) or None,
rank = a.attrib['rank'].strip() and int(a.attrib['rank']) or None
)
)
for a in data.findall('album')
]
@LastfmBase.topProperty("topAlbums")
def topAlbum(self):
"""top album for the tag"""
pass
@property
@LastfmBase.cachedProperty
def topArtists(self):
"""top artists for the tag"""
if self.__topArtists is None:
params = {'method': 'tag.gettopartists', 'tag': self.name}
data = self.__api._fetchData(params).find('topartists')
self.__topArtists = [
Artist(
self.__api,
name = a.findtext('name'),
mbid = a.findtext('mbid'),
stats = Stats(
subject = a.findtext('name'),
rank = a.attrib['rank'].strip() and int(a.attrib['rank']) or None,
tagcount = a.findtext('tagcount') and int(a.findtext('tagcount')) or None
),
url = a.findtext('url'),
streamable = (a.findtext('streamable') == "1"),
image = dict([(i.get('size'), i.text) for i in a.findall('image')]),
)
for a in data.findall('artist')
]
return self.__topArtists
params = {'method': 'tag.gettopartists', 'tag': self.name}
data = self.__api._fetchData(params).find('topartists')
return [
Artist(
self.__api,
name = a.findtext('name'),
mbid = a.findtext('mbid'),
stats = Stats(
subject = a.findtext('name'),
rank = a.attrib['rank'].strip() and int(a.attrib['rank']) or None,
tagcount = a.findtext('tagcount') and int(a.findtext('tagcount')) or None
),
url = a.findtext('url'),
streamable = (a.findtext('streamable') == "1"),
image = dict([(i.get('size'), i.text) for i in a.findall('image')]),
)
for a in data.findall('artist')
]
@LastfmBase.topProperty("topArtists")
def topArtist(self):
"""top artist for the tag"""
pass
@property
@LastfmBase.cachedProperty
def topTracks(self):
"""top tracks for the tag"""
if self.__topTracks is None:
params = {'method': 'tag.gettoptracks', 'tag': self.name}
data = self.__api._fetchData(params).find('toptracks')
self.__topTracks = [
Track(
params = {'method': 'tag.gettoptracks', 'tag': self.name}
data = self.__api._fetchData(params).find('toptracks')
return [
Track(
self.__api,
name = t.findtext('name'),
artist = Artist(
self.__api,
name = t.findtext('name'),
artist = Artist(
self.__api,
name = t.findtext('artist/name'),
mbid = t.findtext('artist/mbid'),
url = t.findtext('artist/url'),
),
mbid = t.findtext('mbid'),
stats = Stats(
subject = t.findtext('name'),
rank = t.attrib['rank'].strip() and int(t.attrib['rank']) or None,
tagcount = t.findtext('tagcount') and int(t.findtext('tagcount')) or None
),
streamable = (t.findtext('streamable') == '1'),
fullTrack = (t.find('streamable').attrib['fulltrack'] == '1'),
image = dict([(i.get('size'), i.text) for i in t.findall('image')]),
)
for t in data.findall('track')
]
return self.__topTracks
name = t.findtext('artist/name'),
mbid = t.findtext('artist/mbid'),
url = t.findtext('artist/url'),
),
mbid = t.findtext('mbid'),
stats = Stats(
subject = t.findtext('name'),
rank = t.attrib['rank'].strip() and int(t.attrib['rank']) or None,
tagcount = t.findtext('tagcount') and int(t.findtext('tagcount')) or None
),
streamable = (t.findtext('streamable') == '1'),
fullTrack = (t.find('streamable').attrib['fulltrack'] == '1'),
image = dict([(i.get('size'), i.text) for i in t.findall('image')]),
)
for t in data.findall('track')
]
@LastfmBase.topProperty("topTracks")
def topTrack(self):
"""top track for the tag"""

View File

@ -41,10 +41,7 @@ class Track(LastfmBase):
self.__fullTrack = fullTrack
self.__playedOn = playedOn
self.__lovedOn = lovedOn
self.__similar = None
self.__topFans = None
self.__topTags = None
@property
def name(self):
"""name of the track"""
@ -114,100 +111,94 @@ class Track(LastfmBase):
params.update({'mbid': mbid})
return params
@property
@LastfmBase.cachedProperty
def similar(self):
"""tracks similar to this track"""
if self.__similar is None:
params = self.__checkParams(
{'method': 'track.getsimilar'},
self.artist.name,
self.name,
self.mbid
)
data = self.__api._fetchData(params).find('similartracks')
self.__similar = [
Track(
self.__api,
name = t.findtext('name'),
artist = Artist(
self.__api,
name = t.findtext('artist/name'),
mbid = t.findtext('artist/mbid'),
url = t.findtext('artist/url')
),
mbid = t.findtext('mbid'),
stats = Stats(
subject = t.findtext('name'),
match = float(t.findtext('match'))
),
streamable = (t.findtext('streamable') == '1'),
fullTrack = (t.find('streamable').attrib['fulltrack'] == '1'),
image = dict([(i.get('size'), i.text) for i in t.findall('image')]),
)
for t in data.findall('track')
]
return self.__similar
params = self.__checkParams(
{'method': 'track.getsimilar'},
self.artist.name,
self.name,
self.mbid
)
data = self.__api._fetchData(params).find('similartracks')
return [
Track(
self.__api,
name = t.findtext('name'),
artist = Artist(
self.__api,
name = t.findtext('artist/name'),
mbid = t.findtext('artist/mbid'),
url = t.findtext('artist/url')
),
mbid = t.findtext('mbid'),
stats = Stats(
subject = t.findtext('name'),
match = float(t.findtext('match'))
),
streamable = (t.findtext('streamable') == '1'),
fullTrack = (t.find('streamable').attrib['fulltrack'] == '1'),
image = dict([(i.get('size'), i.text) for i in t.findall('image')]),
)
for t in data.findall('track')
]
@LastfmBase.topProperty("similar")
def mostSimilar(self):
"""track most similar to this track"""
pass
@property
@LastfmBase.cachedProperty
def topFans(self):
"""top fans of the track"""
if self.__topFans is None:
params = self.__checkParams(
{'method': 'track.gettopfans'},
self.artist.name,
self.name,
self.mbid
)
data = self.__api._fetchData(params).find('topfans')
self.__topFans = [
User(
self.__api,
name = u.findtext('name'),
url = u.findtext('url'),
image = dict([(i.get('size'), i.text) for i in u.findall('image')]),
stats = Stats(
subject = u.findtext('name'),
weight = int(u.findtext('weight'))
)
params = self.__checkParams(
{'method': 'track.gettopfans'},
self.artist.name,
self.name,
self.mbid
)
data = self.__api._fetchData(params).find('topfans')
return [
User(
self.__api,
name = u.findtext('name'),
url = u.findtext('url'),
image = dict([(i.get('size'), i.text) for i in u.findall('image')]),
stats = Stats(
subject = u.findtext('name'),
weight = int(u.findtext('weight'))
)
for u in data.findall('user')
]
return self.__topFans
)
for u in data.findall('user')
]
@LastfmBase.topProperty("topFans")
def topFan(self):
"""topmost fan of the track"""
pass
@property
@LastfmBase.cachedProperty
def topTags(self):
"""top tags for the track"""
if self.__topTags is None:
params = self.__checkParams(
{'method': 'track.gettoptags'},
self.artist.name,
self.name,
self.mbid
)
data = self.__api._fetchData(params).find('toptags')
self.__topTags = [
Tag(
self.__api,
name = t.findtext('name'),
url = t.findtext('url'),
stats = Stats(
subject = t.findtext('name'),
count = int(t.findtext('count')),
)
params = self.__checkParams(
{'method': 'track.gettoptags'},
self.artist.name,
self.name,
self.mbid
)
data = self.__api._fetchData(params).find('toptags')
return [
Tag(
self.__api,
name = t.findtext('name'),
url = t.findtext('url'),
stats = Stats(
subject = t.findtext('name'),
count = int(t.findtext('count')),
)
for t in data.findall('tag')
]
return self.__topTags
)
for t in data.findall('tag')
]
@LastfmBase.topProperty("topTags")
def topTag(self):

View File

@ -25,15 +25,6 @@ class User(LastfmBase):
match = stats.match,
weight = stats.weight
)
self.__events = None
self.__pastEvents = None
self.__friends = None
self.__neighbours = None
self.__lovedTracks = None
self.__topAlbums = None
self.__topArtists = None
self.__topTracks = None
self.__topTags = None
self.__lirary = User.Library(api, self)
@property
@ -56,18 +47,16 @@ class User(LastfmBase):
"""stats for the user"""
return self.__stats
@property
@LastfmBase.cachedProperty
def events(self):
if self.__events is None:
params = {'method': 'user.getevents', 'user': self.name}
data = self.__api._fetchData(params).find('events')
params = {'method': 'user.getevents', 'user': self.name}
data = self.__api._fetchData(params).find('events')
self.__events = [
return [
Event.createFromData(self.__api, e)
for e in data.findall('event')
]
return self.__events
def getPastEvents(self,
page = None,
limit = None):
@ -83,11 +72,9 @@ class User(LastfmBase):
for e in data.findall('event')
]
@property
@LastfmBase.cachedProperty
def pastEvents(self):
if self.__pastEvents is None:
self.__pastEvents = self.getPastEvents()
return self.__pastEvents
return self.getPastEvents()
def getFriends(self,
limit = None):
@ -106,13 +93,11 @@ class User(LastfmBase):
]
@property
@LastfmBase.cachedProperty
def friends(self):
"""friends of the user"""
if self.__friends is None:
self.__friends = self.getFriends()
return self.__friends
return self.getFriends()
def getNeighbours(self, limit = None):
params = {'method': 'user.getneighbours', 'user': self.name}
if limit is not None:
@ -132,12 +117,10 @@ class User(LastfmBase):
for u in data.findall('user')
]
@property
@LastfmBase.cachedProperty
def neighbours(self):
"""neighbours of the user"""
if self.__neighbours is None:
self.__neighbours = self.getNeighbours()
return self.__neighbours
return self.getNeighbours()
@LastfmBase.topProperty("neighbours")
def nearestNeighbour(self):
@ -149,34 +132,32 @@ class User(LastfmBase):
"""playlists of the user"""
pass
@property
@LastfmBase.cachedProperty
def lovedTracks(self):
if self.__lovedTracks is None:
params = {'method': 'user.getlovedtracks', 'user': self.name}
data = self.__api._fetchData(params).find('lovedtracks')
self.__lovedTracks = [
Track(
params = {'method': 'user.getlovedtracks', 'user': self.name}
data = self.__api._fetchData(params).find('lovedtracks')
return [
Track(
self.__api,
name = t.findtext('name'),
artist = Artist(
self.__api,
name = t.findtext('name'),
artist = Artist(
self.__api,
name = t.findtext('artist/name'),
mbid = t.findtext('artist/mbid'),
url = t.findtext('artist/url'),
),
mbid = t.findtext('mbid'),
image = dict([(i.get('size'), i.text) for i in t.findall('image')]),
lovedOn = datetime(*(
time.strptime(
t.findtext('date').strip(),
'%d %b %Y, %H:%M'
)[0:6])
)
name = t.findtext('artist/name'),
mbid = t.findtext('artist/mbid'),
url = t.findtext('artist/url'),
),
mbid = t.findtext('mbid'),
image = dict([(i.get('size'), i.text) for i in t.findall('image')]),
lovedOn = datetime(*(
time.strptime(
t.findtext('date').strip(),
'%d %b %Y, %H:%M'
)[0:6])
)
for t in data.findall('track')
]
return self.__lovedTracks
)
for t in data.findall('track')
]
def getRecentTracks(self, limit = None):
params = {'method': 'user.getrecenttracks', 'user': self.name}
data = self.__api._fetchData(params, no_cache = True).find('recenttracks')
@ -251,13 +232,11 @@ class User(LastfmBase):
for a in data.findall('album')
]
@property
@LastfmBase.cachedProperty
def topAlbums(self):
"""overall top albums of the user"""
if self.__topAlbums is None:
self.__topAlbums = self.getTopAlbums()
return self.__topAlbums
return self.getTopAlbums()
@LastfmBase.topProperty("topAlbums")
def topAlbum(self):
"""overall top most album of the user"""
@ -286,13 +265,11 @@ class User(LastfmBase):
for a in data.findall('artist')
]
@property
@LastfmBase.cachedProperty
def topArtists(self):
"""top artists of the user"""
if self.__topArtists is None:
self.__topArtists = self.getTopArtists()
return self.__topArtists
return self.getTopArtists()
@LastfmBase.topProperty("topArtists")
def topArtist(self):
"""top artist of the user"""
@ -326,13 +303,11 @@ class User(LastfmBase):
for t in data.findall('track')
]
@property
@LastfmBase.cachedProperty
def topTracks(self):
"""top tracks of the user"""
if self.__topTracks is None:
self.__topTracks = self.getTopTracks()
return self.__topTracks
return self.getTopTracks()
@LastfmBase.topProperty("topTracks")
def topTrack(self):
"""top track of the user"""
@ -356,13 +331,11 @@ class User(LastfmBase):
for t in data.findall('tag')
]
@property
@LastfmBase.cachedProperty
def topTags(self):
"""top tags of the user"""
if self.__topTags is None:
self.__topTags = self.getTopTags()
return self.__topTags
return self.getTopTags()
@LastfmBase.topProperty("topTags")
def topTag(self):
"""top tag of the user"""
@ -423,12 +396,10 @@ class User(LastfmBase):
return "<lastfm.User: %s>" % self.name
class Library(object):
"""A class representing the music library of the user."""
def __init__(self, api, user):
self.__api = api
self.__user = user
self.__albums = None
self.__artists = None
self.__tracks = None
@property
def user(self):
@ -465,12 +436,10 @@ class User(LastfmBase):
]
}
@property
@LastfmBase.cachedProperty
def albums(self):
if self.__albums is None:
self.__albums = self.getAlbums()['albums']
return self.__albums
return self.getAlbums()['albums']
def getArtists(self,
limit = None,
page = None):
@ -498,11 +467,9 @@ class User(LastfmBase):
]
}
@property
@LastfmBase.cachedProperty
def artists(self):
if self.__artists is None:
self.__artists = self.getArtists()['artists']
return self.__artists
return self.getArtists()['artists']
def getTracks(self,
limit = None,
@ -537,12 +504,10 @@ class User(LastfmBase):
]
}
@property
@LastfmBase.cachedProperty
def tracks(self):
if self.__tracks is None:
self.__tracks = self.getTracks()['tracks']
return self.__tracks
return self.getTracks()['tracks']
def _fetchData(self, params, limit, page):
params .update({'user': self.user.name})
if limit is not None:
@ -571,3 +536,4 @@ from track import Track
#extract self.__* property as decorator
#write depaginations
#write exceptions
#argument type checking