changed the default value of extra_params argument in the _default_params methods to None from {}

master
Abhinav Sarkar 2009-03-18 03:19:57 +00:00
parent 394310c60f
commit 9105ddc447
12 changed files with 49 additions and 22 deletions

View File

@ -686,7 +686,8 @@ import urlparse
from lastfm.album import Album from lastfm.album import Album
from lastfm.artist import Artist from lastfm.artist import Artist
from lastfm.error import error_map, LastfmError, OperationFailedError, AuthenticationFailedError from lastfm.error import error_map, LastfmError, OperationFailedError, AuthenticationFailedError,\
InvalidParametersError
from lastfm.event import Event from lastfm.event import Event
from lastfm.filecache import FileCache from lastfm.filecache import FileCache
from lastfm.geo import Location, Country from lastfm.geo import Location, Country

View File

@ -369,11 +369,12 @@ class Artist(LastfmBase, Cacheable, Sharable, Shoutable, Searchable, Taggable):
a._fill_info() a._fill_info()
return a return a
def _default_params(self, extra_params = {}): def _default_params(self, extra_params = None):
if not self.name: if not self.name:
raise InvalidParametersError("artist has to be provided.") raise InvalidParametersError("artist has to be provided.")
params = {'artist': self.name} params = {'artist': self.name}
params.update(extra_params) if extra_params is not None:
params.update(extra_params)
return params return params
@staticmethod @staticmethod

View File

@ -8,9 +8,15 @@ __package__ = "lastfm"
class LastfmBase(object): class LastfmBase(object):
"""Base class for all the classes in this package""" """Base class for all the classes in this package"""
def __eq__(self, other):
raise NotImplementedError("The subclass must override this method")
def __lt__(self, other):
raise NotImplementedError("The subclass must override this method")
def __gt__(self, other): def __gt__(self, other):
return not (self.__lt__(other) or self.__eq(other)) return not (self.__lt__(other) or self.__eq__(other))
def __ne__(self, other): def __ne__(self, other):
return not self.__eq__(other) return not self.__eq__(other)

View File

@ -287,11 +287,12 @@ class Event(LastfmBase, Cacheable, Sharable, Shoutable):
tag = data.findtext('tag') tag = data.findtext('tag')
) )
def _default_params(self, extra_params = []): def _default_params(self, extra_params = None):
if not self.id: if not self.id:
raise InvalidParametersError("id has to be provided.") raise InvalidParametersError("id has to be provided.")
params = {'event': self.id} params = {'event': self.id}
params.update(extra_params) if extra_params is not None:
params.update(extra_params)
return params return params
@staticmethod @staticmethod

View File

@ -215,11 +215,12 @@ class Group(LastfmBase, Cacheable):
url = u.findtext('url') url = u.findtext('url')
) )
def _default_params(self, extra_params = {}): def _default_params(self, extra_params = None):
if not self.name: if not self.name:
raise InvalidParametersError("group has to be provided.") raise InvalidParametersError("group has to be provided.")
params = {'group': self.name} params = {'group': self.name}
params.update(extra_params) if extra_params is not None:
params.update(extra_params)
return params return params
@staticmethod @staticmethod

View File

@ -51,3 +51,7 @@ class Cacheable(object):
#print "not already registered: %s" % ob.__class__ #print "not already registered: %s" % ob.__class__
Cacheable.registry[ob.__class__][key] = ob Cacheable.registry[ob.__class__][key] = ob
return (ob, False) return (ob, False)
@staticmethod
def _hash_func(*args, **kwds):
raise NotImplementedError("The subclass must override this method")

View File

@ -26,5 +26,8 @@ class Sharable(object):
params['recipient'] = ",".join(recipient) params['recipient'] = ",".join(recipient)
self._api._post_data(params) self._api._post_data(params)
def _default_params(self, extra_params = {}): def _default_params(self, extra_params = None):
return extra_params if extra_params is not None:
return extra_params
else:
return {}

View File

@ -34,8 +34,11 @@ class Shoutable(object):
"""recent shout for this subject""" """recent shout for this subject"""
pass pass
def _default_params(self, extra_params = {}): def _default_params(self, extra_params = None):
return extra_params if extra_params is not None:
return extra_params
else:
return {}
from datetime import datetime from datetime import datetime
import time import time

View File

@ -66,5 +66,8 @@ class Taggable(object):
self._api._post_data(params) self._api._post_data(params)
self._tags = None self._tags = None
def _default_params(self, extra_params = {}): def _default_params(self, extra_params = None):
return extra_params if extra_params is not None:
return extra_params
else:
return {}

View File

@ -227,11 +227,12 @@ class Tag(LastfmBase, Cacheable, Searchable):
for t in data.findall('tag') for t in data.findall('tag')
] ]
def _default_params(self, extra_params = {}): def _default_params(self, extra_params = None):
if not self.name: if not self.name:
raise InvalidParametersError("tag has to be provided.") raise InvalidParametersError("tag has to be provided.")
params = {'tag': self.name} params = {'tag': self.name}
params.update(extra_params) if extra_params is not None:
params.update(extra_params)
return params return params
@staticmethod @staticmethod

View File

@ -272,11 +272,12 @@ class Track(LastfmBase, Cacheable, Sharable, Searchable, Taggable):
t._fill_info() t._fill_info()
return t return t
def _default_params(self, extra_params = {}): def _default_params(self, extra_params = None):
if not (self.artist and self.name): if not (self.artist and self.name):
raise InvalidParametersError("artist and track have to be provided.") raise InvalidParametersError("artist and track have to be provided.")
params = {'artist': self.artist.name, 'track': self.name} params = {'artist': self.artist.name, 'track': self.name}
params.update(extra_params) if extra_params is not None:
params.update(extra_params)
return params return params
@staticmethod @staticmethod

View File

@ -621,11 +621,12 @@ class User(LastfmBase, Cacheable, Shoutable):
user._stats = Stats(subject = user, playcount = data.findtext('playcount')) user._stats = Stats(subject = user, playcount = data.findtext('playcount'))
return user return user
def _default_params(self, extra_params = {}): def _default_params(self, extra_params = None):
if not self.name: if not self.name:
raise InvalidParametersError("user has to be provided.") raise InvalidParametersError("user has to be provided.")
params = {'user': self.name} params = {'user': self.name}
params.update(extra_params) if extra_params is not None:
params.update(extra_params)
return params return params
@staticmethod @staticmethod
@ -883,11 +884,12 @@ class User(LastfmBase, Cacheable, Shoutable):
self._api._post_data(params) self._api._post_data(params)
self._tracks = None self._tracks = None
def _default_params(self, extra_params = {}): def _default_params(self, extra_params = None):
if not self.user.name: if not self.user.name:
raise InvalidParametersError("user has to be provided.") raise InvalidParametersError("user has to be provided.")
params = {'user': self.user.name} params = {'user': self.user.name}
params.update(extra_params) if extra_params is not None:
params.update(extra_params)
return params return params
@staticmethod @staticmethod