From 9105ddc447a4713020f5301f7c5985bc24d6c025 Mon Sep 17 00:00:00 2001 From: Abhinav Sarkar Date: Wed, 18 Mar 2009 03:19:57 +0000 Subject: [PATCH] changed the default value of extra_params argument in the _default_params methods to None from {} --- lastfm/api.py | 3 ++- lastfm/artist.py | 5 +++-- lastfm/base.py | 8 +++++++- lastfm/event.py | 5 +++-- lastfm/group.py | 5 +++-- lastfm/mixins/cacheable.py | 4 ++++ lastfm/mixins/sharable.py | 7 +++++-- lastfm/mixins/shoutable.py | 7 +++++-- lastfm/mixins/taggable.py | 7 +++++-- lastfm/tag.py | 5 +++-- lastfm/track.py | 5 +++-- lastfm/user.py | 10 ++++++---- 12 files changed, 49 insertions(+), 22 deletions(-) diff --git a/lastfm/api.py b/lastfm/api.py index b44b64e..d10e8ec 100644 --- a/lastfm/api.py +++ b/lastfm/api.py @@ -686,7 +686,8 @@ import urlparse from lastfm.album import Album 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.filecache import FileCache from lastfm.geo import Location, Country diff --git a/lastfm/artist.py b/lastfm/artist.py index 39ebda2..b48cda7 100644 --- a/lastfm/artist.py +++ b/lastfm/artist.py @@ -369,11 +369,12 @@ class Artist(LastfmBase, Cacheable, Sharable, Shoutable, Searchable, Taggable): a._fill_info() return a - def _default_params(self, extra_params = {}): + def _default_params(self, extra_params = None): if not self.name: raise InvalidParametersError("artist has to be provided.") params = {'artist': self.name} - params.update(extra_params) + if extra_params is not None: + params.update(extra_params) return params @staticmethod diff --git a/lastfm/base.py b/lastfm/base.py index bac1da4..3bbe7b9 100644 --- a/lastfm/base.py +++ b/lastfm/base.py @@ -8,9 +8,15 @@ __package__ = "lastfm" class LastfmBase(object): """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): - return not (self.__lt__(other) or self.__eq(other)) + return not (self.__lt__(other) or self.__eq__(other)) def __ne__(self, other): return not self.__eq__(other) diff --git a/lastfm/event.py b/lastfm/event.py index fc31f3a..e99b858 100644 --- a/lastfm/event.py +++ b/lastfm/event.py @@ -287,11 +287,12 @@ class Event(LastfmBase, Cacheable, Sharable, Shoutable): tag = data.findtext('tag') ) - def _default_params(self, extra_params = []): + def _default_params(self, extra_params = None): if not self.id: raise InvalidParametersError("id has to be provided.") params = {'event': self.id} - params.update(extra_params) + if extra_params is not None: + params.update(extra_params) return params @staticmethod diff --git a/lastfm/group.py b/lastfm/group.py index cce82ca..5ff47a0 100644 --- a/lastfm/group.py +++ b/lastfm/group.py @@ -215,11 +215,12 @@ class Group(LastfmBase, Cacheable): url = u.findtext('url') ) - def _default_params(self, extra_params = {}): + def _default_params(self, extra_params = None): if not self.name: raise InvalidParametersError("group has to be provided.") params = {'group': self.name} - params.update(extra_params) + if extra_params is not None: + params.update(extra_params) return params @staticmethod diff --git a/lastfm/mixins/cacheable.py b/lastfm/mixins/cacheable.py index 3af7233..d9ff828 100644 --- a/lastfm/mixins/cacheable.py +++ b/lastfm/mixins/cacheable.py @@ -51,3 +51,7 @@ class Cacheable(object): #print "not already registered: %s" % ob.__class__ Cacheable.registry[ob.__class__][key] = ob return (ob, False) + + @staticmethod + def _hash_func(*args, **kwds): + raise NotImplementedError("The subclass must override this method") diff --git a/lastfm/mixins/sharable.py b/lastfm/mixins/sharable.py index 5f56627..3b8aa93 100644 --- a/lastfm/mixins/sharable.py +++ b/lastfm/mixins/sharable.py @@ -26,5 +26,8 @@ class Sharable(object): params['recipient'] = ",".join(recipient) self._api._post_data(params) - def _default_params(self, extra_params = {}): - return extra_params \ No newline at end of file + def _default_params(self, extra_params = None): + if extra_params is not None: + return extra_params + else: + return {} \ No newline at end of file diff --git a/lastfm/mixins/shoutable.py b/lastfm/mixins/shoutable.py index 1ef03b3..0cda591 100644 --- a/lastfm/mixins/shoutable.py +++ b/lastfm/mixins/shoutable.py @@ -34,8 +34,11 @@ class Shoutable(object): """recent shout for this subject""" pass - def _default_params(self, extra_params = {}): - return extra_params + def _default_params(self, extra_params = None): + if extra_params is not None: + return extra_params + else: + return {} from datetime import datetime import time \ No newline at end of file diff --git a/lastfm/mixins/taggable.py b/lastfm/mixins/taggable.py index ee5f2c3..67e9824 100644 --- a/lastfm/mixins/taggable.py +++ b/lastfm/mixins/taggable.py @@ -66,5 +66,8 @@ class Taggable(object): self._api._post_data(params) self._tags = None - def _default_params(self, extra_params = {}): - return extra_params \ No newline at end of file + def _default_params(self, extra_params = None): + if extra_params is not None: + return extra_params + else: + return {} \ No newline at end of file diff --git a/lastfm/tag.py b/lastfm/tag.py index 7b7e1e9..f37457a 100644 --- a/lastfm/tag.py +++ b/lastfm/tag.py @@ -227,11 +227,12 @@ class Tag(LastfmBase, Cacheable, Searchable): for t in data.findall('tag') ] - def _default_params(self, extra_params = {}): + def _default_params(self, extra_params = None): if not self.name: raise InvalidParametersError("tag has to be provided.") params = {'tag': self.name} - params.update(extra_params) + if extra_params is not None: + params.update(extra_params) return params @staticmethod diff --git a/lastfm/track.py b/lastfm/track.py index 399975d..a7b9566 100644 --- a/lastfm/track.py +++ b/lastfm/track.py @@ -272,11 +272,12 @@ class Track(LastfmBase, Cacheable, Sharable, Searchable, Taggable): t._fill_info() return t - def _default_params(self, extra_params = {}): + def _default_params(self, extra_params = None): if not (self.artist and self.name): raise InvalidParametersError("artist and track have to be provided.") params = {'artist': self.artist.name, 'track': self.name} - params.update(extra_params) + if extra_params is not None: + params.update(extra_params) return params @staticmethod diff --git a/lastfm/user.py b/lastfm/user.py index 85a3a35..f940363 100644 --- a/lastfm/user.py +++ b/lastfm/user.py @@ -621,11 +621,12 @@ class User(LastfmBase, Cacheable, Shoutable): user._stats = Stats(subject = user, playcount = data.findtext('playcount')) return user - def _default_params(self, extra_params = {}): + def _default_params(self, extra_params = None): if not self.name: raise InvalidParametersError("user has to be provided.") params = {'user': self.name} - params.update(extra_params) + if extra_params is not None: + params.update(extra_params) return params @staticmethod @@ -883,11 +884,12 @@ class User(LastfmBase, Cacheable, Shoutable): self._api._post_data(params) self._tracks = None - def _default_params(self, extra_params = {}): + def _default_params(self, extra_params = None): if not self.user.name: raise InvalidParametersError("user has to be provided.") params = {'user': self.user.name} - params.update(extra_params) + if extra_params is not None: + params.update(extra_params) return params @staticmethod