[Python-modules-commits] [python-social-auth] 164/322: PEP8 and simplify code
Wolfgang Borgert
debacle at moszumanska.debian.org
Sat Dec 24 15:13:04 UTC 2016
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to tag v0.2.10
in repository python-social-auth.
commit c768998b987688fe0e5673580ef93b2d47440491
Author: Matías Aguirre <matiasaguirre at gmail.com>
Date: Thu Mar 5 13:57:11 2015 -0200
PEP8 and simplify code
---
social/backends/weibo.py | 40 +++++++++++++++++-----------------------
1 file changed, 17 insertions(+), 23 deletions(-)
diff --git a/social/backends/weibo.py b/social/backends/weibo.py
index ddf884e..25b60a9 100644
--- a/social/backends/weibo.py
+++ b/social/backends/weibo.py
@@ -14,7 +14,6 @@ class WeiboOAuth2(BaseOAuth2):
AUTHORIZATION_URL = 'https://api.weibo.com/oauth2/authorize'
REQUEST_TOKEN_URL = 'https://api.weibo.com/oauth2/request_token'
ACCESS_TOKEN_URL = 'https://api.weibo.com/oauth2/access_token'
- ACCESS_TOKEN_INFO_URL = 'https://api.weibo.com/oauth2/get_token_info'
ACCESS_TOKEN_METHOD = 'POST'
REDIRECT_STATE = False
EXTRA_DATA = [
@@ -41,27 +40,22 @@ class WeiboOAuth2(BaseOAuth2):
'last_name': last_name}
def get_uid(self, access_token):
- """ return uid by access_token"""
-
- response = self.request(self.ACCESS_TOKEN_INFO_URL,
- method='POST',
- params={'access_token':access_token})
-
- data = response.json()
+ """Return uid by access_token"""
+ data = self.get_json(
+ 'https://api.weibo.com/oauth2/get_token_info',
+ method='POST',
+ params={'access_token': access_token}
+ )
return data['uid']
- def user_data(self, access_token, *args, **kwargs):
- """ if use access_token for ajax auth, then would raise KeyError
- because there is no uid in response, so must get uid.
- """
- if 'response' not in kwargs or 'uid' not in kwargs['response']:
- uid = self.get_uid(access_token)
- response = kwargs.setdefault('response', {})
- response['uid'] = uid
-
- response = self.get_json('https://api.weibo.com/2/users/show.json',
- params={'access_token': access_token,
- 'uid': kwargs['response']['uid']})
-
- response['uid'] = kwargs['response']['uid']
- return response
\ No newline at end of file
+ def user_data(self, access_token, response=None, *args, **kwargs):
+ """Return user data"""
+ # If user id was not retrieved in the response, then get it directly
+ # from weibo get_token_info endpoint
+ uid = response and response.get('uid') or self.get_uid(access_token)
+ user_data = self.get_json(
+ 'https://api.weibo.com/2/users/show.json',
+ params={'access_token': access_token, 'uid': uid}
+ )
+ user_data['uid'] = uid
+ return user_data
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-social-auth.git
More information about the Python-modules-commits
mailing list