From 4073437dcfb65d0a23696d92688cb00fcadcb37d Mon Sep 17 00:00:00 2001 From: Ben Sturmfels Date: Sun, 30 Nov 2014 10:52:11 +1100 Subject: [PATCH] Use Six's method to determine when running under Python 3. oauth.py guesses whether it is running under Python 3 by the existance of urllib.parse.urllib_parse and urllib.parse.urlencode. The code then uses urlencode's safe parameter if it believes it's running under Python 3. Unfortunately the guess fails when using Future, a library for writing clean Python 3 code that is backwards compatible with Python 2, since Future manipulates some builtins. This change applies the version test that isn't confused by the use of Futures. It's the same test used by the Six library. --- twitter/oauth.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/twitter/oauth.py b/twitter/oauth.py index dcc062c7..d43f753d 100644 --- a/twitter/oauth.py +++ b/twitter/oauth.py @@ -41,17 +41,18 @@ from __future__ import print_function -from time import time from random import getrandbits +import sys +from time import time + +PY3 = sys.version_info[0] == 3 try: import urllib.parse as urllib_parse from urllib.parse import urlencode - PY3 = True except ImportError: import urllib2 as urllib_parse from urllib import urlencode - PY3 = False import hashlib import hmac