Fixes an issue with incompatibility with newer versions of the SimpleGeo OAuth2 library; also fixes an issue with bulkUserLookup fixes not being up on Pypi (issue #37, thanks jmalina327)

This commit is contained in:
Ryan McGrath 2011-08-09 18:01:17 -04:00
parent 7441a535ee
commit d6d8823dc2
2 changed files with 17 additions and 11 deletions

View file

@ -5,7 +5,7 @@ from setuptools import setup
from setuptools import find_packages from setuptools import find_packages
__author__ = 'Ryan McGrath <ryan@venodesigns.net>' __author__ = 'Ryan McGrath <ryan@venodesigns.net>'
__version__ = '1.4.2' __version__ = '1.4.3'
setup( setup(
# Basic package information. # Basic package information.

View file

@ -9,7 +9,7 @@
""" """
__author__ = "Ryan McGrath <ryan@venodesigns.net>" __author__ = "Ryan McGrath <ryan@venodesigns.net>"
__version__ = "1.4.2" __version__ = "1.4.3"
import cgi import cgi
import urllib import urllib
@ -48,13 +48,19 @@ except ImportError:
# Seriously wtf is wrong with you if you get this Exception. # 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/") raise Exception("Twython requires the simplejson library (or Python 2.6) to work. http://www.undefined.org/python/")
# Detect if oauth2 supports the callback_url argument to request # Try and gauge the old OAuth2 library spec. Versions 1.5 and greater no longer have the callback
OAUTH_CLIENT_INSPECTION = inspect.getargspec(oauth.Client.request) # url as part of the request object; older versions we need to patch for Python 2.5... ugh. ;P
try: OAUTH_CALLBACK_IN_URL = False
OAUTH_LIB_SUPPORTS_CALLBACK = 'callback_url' in OAUTH_CLIENT_INSPECTION.args OAUTH_LIB_SUPPORTS_CALLBACK = False
except AttributeError: if float(oauth._version.manual_verstr) <= 1.4:
# Python 2.5 doesn't return named tuples, so don't look for an args section specifically. OAUTH_CLIENT_INSPECTION = inspect.getargspec(oauth.Client.request)
OAUTH_LIB_SUPPORTS_CALLBACK = 'callback_url' in OAUTH_CLIENT_INSPECTION 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): class TwythonError(AttributeError):
""" """
@ -214,7 +220,7 @@ class Twython(object):
oauth_callback_confirmed = request_tokens.get('oauth_callback_confirmed')=='true' oauth_callback_confirmed = request_tokens.get('oauth_callback_confirmed')=='true'
if not OAUTH_LIB_SUPPORTS_CALLBACK and callback_url!='oob' and oauth_callback_confirmed: if not OAUTH_LIB_SUPPORTS_CALLBACK and callback_url != 'oob' and oauth_callback_confirmed:
import warnings import warnings
warnings.warn("oauth2 library doesn't support OAuth 1.0a type callback, but remote requires it") warnings.warn("oauth2 library doesn't support OAuth 1.0a type callback, but remote requires it")
oauth_callback_confirmed = False oauth_callback_confirmed = False
@ -224,7 +230,7 @@ class Twython(object):
} }
# Use old-style callback argument # Use old-style callback argument
if callback_url!='oob' and not oauth_callback_confirmed: if OAUTH_CALLBACK_IN_URL or (callback_url!='oob' and not oauth_callback_confirmed):
auth_url_params['oauth_callback'] = callback_url auth_url_params['oauth_callback'] = callback_url
request_tokens['auth_url'] = self.authenticate_url + '?' + urllib.urlencode(auth_url_params) request_tokens['auth_url'] = self.authenticate_url + '?' + urllib.urlencode(auth_url_params)