From e77e0f9e35c04443d70045ff3bf3d42533b04525 Mon Sep 17 00:00:00 2001 From: Jace Browning Date: Sat, 5 Jan 2019 13:18:06 -0500 Subject: [PATCH 1/4] Extract username from session --- pylast/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index fd367ef1..0924e695 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -201,10 +201,11 @@ def __init__( self.last_call_time = 0 self.limit_rate = False - # Load session_key from authentication token if provided + # Load session_key and username from authentication token if provided if token and not self.session_key: sk_gen = SessionKeyGenerator(self) - self.session_key = sk_gen.get_web_auth_session_key(url=None, token=token) + self.session_key, self.username = \ + sk_gen.get_web_auth_session_key(url=None, token=token) # Generate a session_key if necessary if ( @@ -988,7 +989,7 @@ class SessionKeyGenerator: b. sg = SessionKeyGenerator(network) c. url = sg.get_web_auth_url() d. Ask the user to open the URL and authorize you, and wait for it. - e. session_key = sg.get_web_auth_session_key(url) + e. session_key, username = sg.get_web_auth_session_key(url) 2) Username and Password Authentication: a. network = get_*_network(API_KEY, API_SECRET) b. username = raw_input("Please enter your username: ") @@ -1062,7 +1063,9 @@ def get_web_auth_session_key(self, url, token=""): doc = request.execute() - return doc.getElementsByTagName("key")[0].firstChild.data + session_key = doc.getElementsByTagName("key")[0].firstChild.data + username = doc.getElementsByTagName("name")[0].firstChild.data + return session_key, username def get_session_key(self, username, password_hash): """ From aa8adfee4bd5e551db6763e6b926c10ca0cbd85e Mon Sep 17 00:00:00 2001 From: Jace Browning Date: Sat, 5 Jan 2019 16:00:46 -0500 Subject: [PATCH 2/4] Create a separate method for extracting username --- pylast/__init__.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index 0924e695..403f7ba4 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -204,8 +204,9 @@ def __init__( # Load session_key and username from authentication token if provided if token and not self.session_key: sk_gen = SessionKeyGenerator(self) - self.session_key, self.username = \ - sk_gen.get_web_auth_session_key(url=None, token=token) + self.session_key, self.username = sk_gen.get_web_auth_session_key_and_username( + url=None, token=token + ) # Generate a session_key if necessary if ( @@ -989,7 +990,7 @@ class SessionKeyGenerator: b. sg = SessionKeyGenerator(network) c. url = sg.get_web_auth_url() d. Ask the user to open the URL and authorize you, and wait for it. - e. session_key, username = sg.get_web_auth_session_key(url) + e. session_key = sg.get_web_auth_session_key(url) 2) Username and Password Authentication: a. network = get_*_network(API_KEY, API_SECRET) b. username = raw_input("Please enter your username: ") @@ -1044,9 +1045,9 @@ def get_web_auth_url(self): return url - def get_web_auth_session_key(self, url, token=""): + def get_web_auth_session_key_and_username(self, url, token=""): """ - Retrieves the session key of a web authorization process by its URL. + Retrieves the session key and username of a web authorization process by its URL. """ if url in self.web_auth_tokens.keys(): @@ -1067,6 +1068,13 @@ def get_web_auth_session_key(self, url, token=""): username = doc.getElementsByTagName("name")[0].firstChild.data return session_key, username + def get_web_auth_session_key(self, url, token=""): + """ + Retrieves the session key of a web authorization process by its URL. + """ + session_key, _username = self.get_web_auth_session_key_and_username(url, token) + return session_key + def get_session_key(self, username, password_hash): """ Retrieve a session key with a username and a md5 hash of the user's From 0a38ac801d0983f5abf8d3aa1c9f9cccaafe0bba Mon Sep 17 00:00:00 2001 From: Jace Browning Date: Sat, 5 Jan 2019 16:23:03 -0500 Subject: [PATCH 3/4] Ignore line length rules in favor of black formatting --- setup.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 9adb3ce3..257ddaf3 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,10 +2,10 @@ universal = 1 [flake8] -max_line_length = 88 +ignore = E501,W503 [metadata] license_file = COPYING [pycodestyle] -max_line_length = 88 +ignore = E501 From fffc64781153d67412b1c658784448a0d2ae3ee7 Mon Sep 17 00:00:00 2001 From: Jace Browning Date: Sat, 5 Jan 2019 20:10:51 -0500 Subject: [PATCH 4/4] Shorten line length --- pylast/__init__.py | 8 ++++---- setup.cfg | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pylast/__init__.py b/pylast/__init__.py index 403f7ba4..5b839c99 100644 --- a/pylast/__init__.py +++ b/pylast/__init__.py @@ -204,7 +204,7 @@ def __init__( # Load session_key and username from authentication token if provided if token and not self.session_key: sk_gen = SessionKeyGenerator(self) - self.session_key, self.username = sk_gen.get_web_auth_session_key_and_username( + self.session_key, self.username = sk_gen.get_web_auth_session_key_username( url=None, token=token ) @@ -1045,9 +1045,9 @@ def get_web_auth_url(self): return url - def get_web_auth_session_key_and_username(self, url, token=""): + def get_web_auth_session_key_username(self, url, token=""): """ - Retrieves the session key and username of a web authorization process by its URL. + Retrieves the session key/username of a web authorization process by its URL. """ if url in self.web_auth_tokens.keys(): @@ -1072,7 +1072,7 @@ def get_web_auth_session_key(self, url, token=""): """ Retrieves the session key of a web authorization process by its URL. """ - session_key, _username = self.get_web_auth_session_key_and_username(url, token) + session_key, _username = self.get_web_auth_session_key_username(url, token) return session_key def get_session_key(self, username, password_hash): diff --git a/setup.cfg b/setup.cfg index 257ddaf3..0fa133ba 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,10 +2,11 @@ universal = 1 [flake8] -ignore = E501,W503 +ignore = W503 +max_line_length = 88 [metadata] license_file = COPYING [pycodestyle] -ignore = E501 +max_line_length = 88