From e17b3ed87782d5ff2c5b197a3ffdf326da703172 Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 6 Apr 2012 11:02:11 +0200 Subject: [PATCH 1/4] Removed OAuth library callback_url detection code, as callback_url passing does not depend on that anymore. --- twython/twython.py | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/twython/twython.py b/twython/twython.py index 4bd2fa7..ea7d195 100644 --- a/twython/twython.py +++ b/twython/twython.py @@ -49,21 +49,6 @@ except ImportError: # Seriously wtf is wrong with you if you get this Exception. raise Exception("Twython requires the simplejson library (or Python 2.6) to work. http://www.undefined.org/python/") -# Try and gauge the old OAuth2 library spec. Versions 1.5 and greater no longer have the callback -# url as part of the request object; older versions we need to patch for Python 2.5... ugh. ;P -OAUTH_CALLBACK_IN_URL = False -OAUTH_LIB_SUPPORTS_CALLBACK = False -if not hasattr(oauth, '_version') or float(oauth._version.manual_verstr) <= 1.4: - OAUTH_CLIENT_INSPECTION = inspect.getargspec(oauth.Client.request) - try: - OAUTH_LIB_SUPPORTS_CALLBACK = 'callback_url' in OAUTH_CLIENT_INSPECTION.args - except AttributeError: - # Python 2.5 doesn't return named tuples, so don't look for an args section specifically. - OAUTH_LIB_SUPPORTS_CALLBACK = 'callback_url' in OAUTH_CLIENT_INSPECTION -else: - OAUTH_CALLBACK_IN_URL = True - - class TwythonError(AttributeError): """ Generic error class, catch-all for most Twython issues. @@ -256,17 +241,12 @@ class Twython(object): oauth_callback_confirmed = request_tokens.get('oauth_callback_confirmed') == 'true' - if not OAUTH_LIB_SUPPORTS_CALLBACK and callback_url != 'oob' and oauth_callback_confirmed: - import warnings - warnings.warn("oauth2 library doesn't support OAuth 1.0a type callback, but remote requires it") - oauth_callback_confirmed = False - auth_url_params = { 'oauth_token': request_tokens['oauth_token'], } - # Use old-style callback argument - if OAUTH_CALLBACK_IN_URL or (callback_url != 'oob' and not oauth_callback_confirmed): + # Use old-style callback argument if server didn't accept new-style + if callback_url != 'oob' and not oauth_callback_confirmed: auth_url_params['oauth_callback'] = callback_url request_tokens['auth_url'] = self.authenticate_url + '?' + urllib.urlencode(auth_url_params) -- 2.39.5 From f4c00ff996374ea4306ca0c352aef8f00015676a Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 6 Apr 2012 11:08:12 +0200 Subject: [PATCH 2/4] If callback_url is not set, don't force it to 'oob' --- twython/twython.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/twython/twython.py b/twython/twython.py index ea7d195..155f936 100644 --- a/twython/twython.py +++ b/twython/twython.py @@ -223,10 +223,12 @@ class Twython(object): Returns an authorization URL for a user to hit. """ - callback_url = self.callback_url or 'oob' + callback_url = self.callback_url request_args = {} - request_args['oauth_callback'] = callback_url + if callback_url: + request_args['oauth_callback'] = callback_url + method = 'get' func = getattr(self.client, method) -- 2.39.5 From ffb768d24deaeb1a26c0e3d3324df88ec9c81914 Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 6 Apr 2012 11:09:43 +0200 Subject: [PATCH 3/4] Fix adding callback_url for old style servers --- twython/twython.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/twython/twython.py b/twython/twython.py index 155f936..7f09e27 100644 --- a/twython/twython.py +++ b/twython/twython.py @@ -248,7 +248,7 @@ class Twython(object): } # Use old-style callback argument if server didn't accept new-style - if callback_url != 'oob' and not oauth_callback_confirmed: + if callback_url and not oauth_callback_confirmed: auth_url_params['oauth_callback'] = callback_url request_tokens['auth_url'] = self.authenticate_url + '?' + urllib.urlencode(auth_url_params) -- 2.39.5 From e353125ef123a51a61518789b4e38697995daad5 Mon Sep 17 00:00:00 2001 From: Erik Date: Fri, 6 Apr 2012 18:48:26 +0200 Subject: [PATCH 4/4] Removed 'import inspect' as it is no longer needed. --- twython/twython.py | 1 - 1 file changed, 1 deletion(-) diff --git a/twython/twython.py b/twython/twython.py index 7f09e27..bc2904d 100644 --- a/twython/twython.py +++ b/twython/twython.py @@ -13,7 +13,6 @@ __version__ = "1.5.2" import urllib import re -import inspect import time import requests -- 2.39.5