renamed BaseError to LastfmError and removed Error class.

master
Abhinav Sarkar 2008-12-30 14:14:00 +00:00
parent 21f591a450
commit 237b32c6c1
6 changed files with 34 additions and 36 deletions

View File

@ -8,7 +8,7 @@ from album import Album
from api import Api
from artist import Artist
from base import LastfmBase
from error import Error
from error import LastfmError
from event import Event
from geo import Location, Country
from group import Group
@ -19,6 +19,6 @@ from tasteometer import Tasteometer
from track import Track
from user import User
__all__ = ['Error', 'Api', 'Album', 'Artist', 'Event',
__all__ = ['LastfmError', 'Api', 'Album', 'Artist', 'Event',
'Location', 'Country', 'Group', 'Playlist', 'Tag',
'Tasteometer', 'Track', 'User', 'Registry']

View File

@ -162,7 +162,7 @@ class Api(object):
try:
user = User(self, name = name)
user.friends
except Error, e:
except LastfmError, e:
raise e
return user
@ -364,7 +364,7 @@ class Api(object):
if code in error_map.keys():
raise error_map[code](message, code)
else:
raise Error(message, code)
raise LastfmError(message, code)
return data
def __repr__(self):
@ -380,7 +380,7 @@ import urlparse
from album import Album
from artist import Artist
from error import error_map, Error, OperationFailedError, AuthenticationFailedError
from error import error_map, LastfmError, OperationFailedError, AuthenticationFailedError
from event import Event
from filecache import FileCache
from geo import Location, Country
@ -400,4 +400,4 @@ else:
try:
import ElementTree
except ImportError:
raise Error("Install ElementTree package for using python-lastfm")
raise LastfmError("Install ElementTree package for using python-lastfm")

View File

@ -75,7 +75,7 @@ class LastfmBase(object):
try:
cp = copy.copy(cache_attribute)
return cp
except Error:
except LastfmError:
return cache_attribute
return property(fget = wrapper, doc = func.__doc__)
@ -93,4 +93,4 @@ class LastfmBase(object):
return not self.__gt__(other)
import copy
from error import Error
from error import LastfmError

View File

@ -4,12 +4,12 @@ __author__ = "Abhinav Sarkar <abhinav@abhinavsarkar.net>"
__version__ = "0.2"
__license__ = "GNU Lesser General Public License"
class BaseError(Exception):
class LastfmError(Exception):
"""Base class for Lastfm errors"""
def __init__(self,
message = None,
code = None):
super(BaseError, self).__init__()
super(LastfmError, self).__init__()
self._code = code
self._message = message
@ -23,50 +23,48 @@ class BaseError(Exception):
def __str__(self):
return "%s" % self.message
class Error(BaseError):
class InvalidServiceError(LastfmError):#2
pass
class InvalidServiceError(BaseError):#2
class InvalidMethodError(LastfmError):#3
pass
class InvalidMethodError(BaseError):#3
class AuthenticationFailedError(LastfmError):#4
pass
class AuthenticationFailedError(BaseError):#4
class InvalidFormatError(LastfmError):#5
pass
class InvalidFormatError(BaseError):#5
class InvalidParametersError(LastfmError):#6
pass
class InvalidParametersError(BaseError):#6
class InvalidResourceError(LastfmError):#7
pass
class InvalidResourceError(BaseError):#7
class OperationFailedError(LastfmError):#8
pass
class OperationFailedError(BaseError):#8
class InvalidSessionKeyError(LastfmError):#9
pass
class InvalidSessionKeyError(BaseError):#9
class InvalidApiKeyError(LastfmError):#10
pass
class InvalidApiKeyError(BaseError):#10
class ServiceOfflineError(LastfmError):#11
pass
class ServiceOfflineError(BaseError):#11
class SubscribersOnlyError(LastfmError):#12
pass
class SubscribersOnlyError(BaseError):#12
class TokenNotAuthorizedError(LastfmError):#14
pass
class TokenNotAuthorizedError(BaseError):#14
pass
class TokenExpiredError(BaseError):#15
class TokenExpiredError(LastfmError):#15
pass
error_map = {
1: Error,
1: LastfmError,
2: InvalidServiceError,
3: InvalidMethodError,
4: AuthenticationFailedError,

View File

@ -62,5 +62,5 @@ else:
try:
import ElementTree
except ImportError:
from error import Error
raise Error("Install ElementTree package for using python-lastfm")
from error import LastfmError
raise LastfmError("Install ElementTree package for using python-lastfm")

View File

@ -451,7 +451,7 @@ class User(LastfmBase):
for wc in wcl:
try:
yield self.get_weekly_album_chart(wc.start, wc.end)
except Error:
except LastfmError:
pass
return gen()
@ -476,7 +476,7 @@ class User(LastfmBase):
for wc in wcl:
try:
yield self.get_weekly_artist_chart(wc.start, wc.end)
except Error:
except LastfmError:
pass
return gen()
@ -501,7 +501,7 @@ class User(LastfmBase):
for wc in wcl:
try:
yield self.get_weekly_track_chart(wc.start, wc.end)
except Error:
except LastfmError:
pass
return gen()
@ -662,7 +662,7 @@ class User(LastfmBase):
params.update({'page': page})
try:
data = self._api._fetch_data(params).find('albums')
except Error:
except LastfmError:
continue
for a in gen2(data):
yield a
@ -708,7 +708,7 @@ class User(LastfmBase):
params.update({'page': page})
try:
data = self._api._fetch_data(params).find('artists')
except Error:
except LastfmError:
continue
for a in gen2(data):
yield a
@ -762,7 +762,7 @@ class User(LastfmBase):
data = None
try:
data = self._api._fetch_data(params).find('tracks')
except Error:
except LastfmError:
continue
for t in gen2(data):
yield t
@ -798,7 +798,7 @@ import time
from api import Api
from artist import Artist
from album import Album
from error import Error, InvalidParametersError
from error import LastfmError, InvalidParametersError
from event import Event
from geo import Country
from stats import Stats