-from sima.utils.utils import getws
-getws(LFM)
-
-# Some definitions
-WAIT_BETWEEN_REQUESTS = timedelta(0, 0.4)
-LFM_ERRORS = dict({'2': 'Invalid service -This service does not exist',
- '3': 'Invalid Method - No method with that name in this package',
- '4': 'Authentication Failed - You do not have permissions to access the service',
- '5': "'Invalid format - This service doesn't exist in that format",
- '6': 'Invalid parameters - Your request is missing a required parameter',
- '7': 'Invalid resource specified',
- '9': 'Invalid session key - Please re-authenticate',
- '10': 'Invalid API key - You must be granted a valid key by last.fm',
- '11': 'Service Offline - This service is temporarily offline. Try again later.',
- '12': 'Subscription Error - The user needs to be subscribed in order to do that',
- '13': 'Invalid method signature supplied',
- '26': 'Suspended API key - Access for your account has been suspended, please contact Last.fm',
- })
-
-
-class XmlFMError(Exception): # Errors
- """
- Exception raised for errors in the input.
- """
-
- def __init__(self, expression):
- self.expression = expression
-
- def __str__(self):
- return repr(self.expression)
-
-
-class EncodingError(XmlFMError):
- """Raised when string is not unicode"""
- pass
-
-
-class XmlFMHTTPError(XmlFMError):
- """Raised when failed to connect server"""
-
- def __init__(self, expression):
- if hasattr(expression, 'code'):
- self.expression = 'error %d: %s' % (expression.code,
- expression.msg)
- else:
- self.expression = 'error: %s' % expression
-
-
-class XmlFMNotFound(XmlFMError):
- """Raised when no artist is found"""
-
- def __init__(self, message=None):
- if not message:
- message = 'Artist probably not found (http error 400)'
- self.expression = (message)
-
-
-class XmlFMMissingArtist(XmlFMError):
- """Raised when no artist name provided"""
-
- def __init__(self, message=None):
- if not message:
- message = 'Missing artist name.'
- self.expression = (message)
-
-
-class XmlFMTimeOut(XmlFMError):
- """Raised when urlopen times out"""
-
- def __init__(self, message=None):
- if not message:
- message = 'Connection to last.fm web services times out!'
- self.expression = (message)
-
-
-class Throttle():
- def __init__(self, wait):
- self.wait = wait
- self.last_called = datetime.now()
-
- def __call__(self, func):
- def wrapper(*args, **kwargs):
- while self.last_called + self.wait > datetime.now():
- #print('waiting…')
- sleep(0.1)
- result = func(*args, **kwargs)
- self.last_called = datetime.now()
- return result
- return wrapper
-
-
-class AudioScrobblerCache():
- def __init__(self, elem, last):
- self.elemtree = elem
- self.requestdate = last
-
- def created(self):
- return self.requestdate