fixed and issue with authenticating through Network's constructor
This commit is contained in:
parent
7f74cbd7bd
commit
83bbe31b66
50
pylast.py
50
pylast.py
|
@ -299,6 +299,11 @@ class Network(object):
|
||||||
self.logging_enabled = False
|
self.logging_enabled = False
|
||||||
self.logger = logging.getLogger(__name__ + ":" + self.name.lower())
|
self.logger = logging.getLogger(__name__ + ":" + self.name.lower())
|
||||||
|
|
||||||
|
#generate a session_key if necessary
|
||||||
|
if not self.session_key and (self.username and self.password_hash):
|
||||||
|
sk_gen = SessionKeyGenerator(self)
|
||||||
|
self.session_key = sk_gen.get_session_key(self.username, self.password_hash)
|
||||||
|
|
||||||
def _debug(self, message):
|
def _debug(self, message):
|
||||||
if self.logging_enabled:
|
if self.logging_enabled:
|
||||||
self.logger.debug(message)
|
self.logger.debug(message)
|
||||||
|
@ -420,17 +425,10 @@ class Network(object):
|
||||||
def _get_url(self, domain, type):
|
def _get_url(self, domain, type):
|
||||||
return "http://%s/%s" %(self._get_language_domain(domain), self.urls[type])
|
return "http://%s/%s" %(self._get_language_domain(domain), self.urls[type])
|
||||||
|
|
||||||
def _get_ws_auth(self, generate_session_key_if_can=True):
|
def _get_ws_auth(self):
|
||||||
"""
|
"""
|
||||||
Returns a (API_KEY, API_SECRET, SESSION_KEY) tuple.
|
Returns a (API_KEY, API_SECRET, SESSION_KEY) tuple.
|
||||||
If SESSION_KEY == None and username and password_hash were provided, a SESSION_KEY will be
|
|
||||||
generated and stored
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if generate_session_key_if_can and (not self.session_key) and (self.username and self.password_hash):
|
|
||||||
sk_gen = SessionKeyGenerator(self)
|
|
||||||
self.session_key = sk_gen.get_session_key(self.username, self.password_hash)
|
|
||||||
|
|
||||||
return (self.api_key, self.api_secret, self.session_key)
|
return (self.api_key, self.api_secret, self.session_key)
|
||||||
|
|
||||||
def _delay_call():
|
def _delay_call():
|
||||||
|
@ -774,7 +772,7 @@ class _Request(object):
|
||||||
self.params = params
|
self.params = params
|
||||||
self.network = network
|
self.network = network
|
||||||
|
|
||||||
(self.api_key, self.api_secret, self.session_key) = network._get_ws_auth(False)
|
(self.api_key, self.api_secret, self.session_key) = network._get_ws_auth()
|
||||||
|
|
||||||
self.params["api_key"] = self.api_key
|
self.params["api_key"] = self.api_key
|
||||||
self.params["method"] = method_name
|
self.params["method"] = method_name
|
||||||
|
@ -1012,6 +1010,8 @@ def _string_output(funct):
|
||||||
class _BaseObject(object):
|
class _BaseObject(object):
|
||||||
"""An abstract webservices object."""
|
"""An abstract webservices object."""
|
||||||
|
|
||||||
|
network = None
|
||||||
|
|
||||||
def __init__(self, network):
|
def __init__(self, network):
|
||||||
self.network = network
|
self.network = network
|
||||||
|
|
||||||
|
@ -1151,10 +1151,9 @@ class WSError(Exception):
|
||||||
def __init__(self, network, status, details):
|
def __init__(self, network, status, details):
|
||||||
self.status = status
|
self.status = status
|
||||||
self.details = details
|
self.details = details
|
||||||
self.message = repr(self)
|
|
||||||
|
|
||||||
@_string_output
|
@_string_output
|
||||||
def __repr__(self):
|
def __str__(self):
|
||||||
return self.details
|
return self.details
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
|
@ -1179,6 +1178,9 @@ class WSError(Exception):
|
||||||
class Album(_BaseObject, _Taggable):
|
class Album(_BaseObject, _Taggable):
|
||||||
"""An album."""
|
"""An album."""
|
||||||
|
|
||||||
|
title = None
|
||||||
|
artist = None
|
||||||
|
|
||||||
def __init__(self, artist, title, network):
|
def __init__(self, artist, title, network):
|
||||||
"""
|
"""
|
||||||
Create an album instance.
|
Create an album instance.
|
||||||
|
@ -1344,6 +1346,8 @@ class Album(_BaseObject, _Taggable):
|
||||||
class Artist(_BaseObject, _Taggable):
|
class Artist(_BaseObject, _Taggable):
|
||||||
"""An artist."""
|
"""An artist."""
|
||||||
|
|
||||||
|
name = None
|
||||||
|
|
||||||
def __init__(self, name, network):
|
def __init__(self, name, network):
|
||||||
"""Create an artist object.
|
"""Create an artist object.
|
||||||
# Parameters:
|
# Parameters:
|
||||||
|
@ -1617,6 +1621,8 @@ class Artist(_BaseObject, _Taggable):
|
||||||
class Event(_BaseObject):
|
class Event(_BaseObject):
|
||||||
"""An event."""
|
"""An event."""
|
||||||
|
|
||||||
|
id = None
|
||||||
|
|
||||||
def __init__(self, event_id, network):
|
def __init__(self, event_id, network):
|
||||||
_BaseObject.__init__(self, network)
|
_BaseObject.__init__(self, network)
|
||||||
|
|
||||||
|
@ -1820,6 +1826,8 @@ class Event(_BaseObject):
|
||||||
class Country(_BaseObject):
|
class Country(_BaseObject):
|
||||||
"""A country at Last.fm."""
|
"""A country at Last.fm."""
|
||||||
|
|
||||||
|
name = None
|
||||||
|
|
||||||
def __init__(self, name, network):
|
def __init__(self, name, network):
|
||||||
_BaseObject.__init__(self, network)
|
_BaseObject.__init__(self, network)
|
||||||
|
|
||||||
|
@ -1904,6 +1912,8 @@ class Country(_BaseObject):
|
||||||
class Library(_BaseObject):
|
class Library(_BaseObject):
|
||||||
"""A user's Last.fm library."""
|
"""A user's Last.fm library."""
|
||||||
|
|
||||||
|
user = None
|
||||||
|
|
||||||
def __init__(self, user, network):
|
def __init__(self, user, network):
|
||||||
_BaseObject.__init__(self, network)
|
_BaseObject.__init__(self, network)
|
||||||
|
|
||||||
|
@ -2011,6 +2021,9 @@ class Library(_BaseObject):
|
||||||
class Playlist(_BaseObject):
|
class Playlist(_BaseObject):
|
||||||
"""A Last.fm user playlist."""
|
"""A Last.fm user playlist."""
|
||||||
|
|
||||||
|
id = None
|
||||||
|
user = None
|
||||||
|
|
||||||
def __init__(self, user, id, network):
|
def __init__(self, user, id, network):
|
||||||
_BaseObject.__init__(self, network)
|
_BaseObject.__init__(self, network)
|
||||||
|
|
||||||
|
@ -2147,6 +2160,8 @@ class Tag(_BaseObject):
|
||||||
|
|
||||||
# TODO: getWeeklyArtistChart (too lazy, i'll wait for when someone requests it)
|
# TODO: getWeeklyArtistChart (too lazy, i'll wait for when someone requests it)
|
||||||
|
|
||||||
|
name = None
|
||||||
|
|
||||||
def __init__(self, name, network):
|
def __init__(self, name, network):
|
||||||
_BaseObject.__init__(self, network)
|
_BaseObject.__init__(self, network)
|
||||||
|
|
||||||
|
@ -2281,6 +2296,9 @@ class Tag(_BaseObject):
|
||||||
class Track(_BaseObject, _Taggable):
|
class Track(_BaseObject, _Taggable):
|
||||||
"""A Last.fm track."""
|
"""A Last.fm track."""
|
||||||
|
|
||||||
|
artist = None
|
||||||
|
title = None
|
||||||
|
|
||||||
def __init__(self, artist, title, network):
|
def __init__(self, artist, title, network):
|
||||||
_BaseObject.__init__(self, network)
|
_BaseObject.__init__(self, network)
|
||||||
_Taggable.__init__(self, 'track')
|
_Taggable.__init__(self, 'track')
|
||||||
|
@ -2536,6 +2554,8 @@ class Track(_BaseObject, _Taggable):
|
||||||
class Group(_BaseObject):
|
class Group(_BaseObject):
|
||||||
"""A Last.fm group."""
|
"""A Last.fm group."""
|
||||||
|
|
||||||
|
name = None
|
||||||
|
|
||||||
def __init__(self, group_name, network):
|
def __init__(self, group_name, network):
|
||||||
_BaseObject.__init__(self, network)
|
_BaseObject.__init__(self, network)
|
||||||
|
|
||||||
|
@ -2662,6 +2682,8 @@ class Group(_BaseObject):
|
||||||
class XSPF(_BaseObject):
|
class XSPF(_BaseObject):
|
||||||
"A Last.fm XSPF playlist."""
|
"A Last.fm XSPF playlist."""
|
||||||
|
|
||||||
|
uri = None
|
||||||
|
|
||||||
def __init__(self, uri, network):
|
def __init__(self, uri, network):
|
||||||
_BaseObject.__init__(self, network)
|
_BaseObject.__init__(self, network)
|
||||||
|
|
||||||
|
@ -2702,6 +2724,8 @@ class XSPF(_BaseObject):
|
||||||
class User(_BaseObject):
|
class User(_BaseObject):
|
||||||
"""A Last.fm user."""
|
"""A Last.fm user."""
|
||||||
|
|
||||||
|
name = None
|
||||||
|
|
||||||
def __init__(self, user_name, network):
|
def __init__(self, user_name, network):
|
||||||
_BaseObject.__init__(self, network)
|
_BaseObject.__init__(self, network)
|
||||||
|
|
||||||
|
@ -3341,6 +3365,8 @@ class Venue(_BaseObject):
|
||||||
|
|
||||||
# TODO: waiting for a venue.getInfo web service to use.
|
# TODO: waiting for a venue.getInfo web service to use.
|
||||||
|
|
||||||
|
id = None
|
||||||
|
|
||||||
def __init__(self, id, network):
|
def __init__(self, id, network):
|
||||||
_BaseObject.__init__(self, network)
|
_BaseObject.__init__(self, network)
|
||||||
|
|
||||||
|
@ -3530,7 +3556,7 @@ class ScrobblingError(Exception):
|
||||||
self.message = message
|
self.message = message
|
||||||
|
|
||||||
@_string_output
|
@_string_output
|
||||||
def __repr__(self):
|
def __str__(self):
|
||||||
return self.message
|
return self.message
|
||||||
|
|
||||||
class BannedClientError(ScrobblingError):
|
class BannedClientError(ScrobblingError):
|
||||||
|
|
Loading…
Reference in a new issue