X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/3930cc7bae58f738b4984ef090c4384e50a42b1f..8df7be82b941c4b1c83bbfe9ed06a4026f3c08e2:/twitter/oauth.py diff --git a/twitter/oauth.py b/twitter/oauth.py index be47e96..d2df7c1 100644 --- a/twitter/oauth.py +++ b/twitter/oauth.py @@ -7,8 +7,12 @@ from random import getrandbits 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 @@ -80,20 +84,11 @@ class OAuth(Auth): # also in the request itself.) # So here is a specialized version which does exactly that. def urlencode_noplus(query): - if hasattr(query,"items"): - # mapping objects - query = list(query.items()) - - encoded_bits = [] - for n, v in query: - # and do unicode here while we are at it... - if isinstance(n, str): - n = n.encode('utf-8') - else: - n = str(n) - if isinstance(v, str): - v = v.encode('utf-8') - else: - v = str(v) - encoded_bits.append("%s=%s" % (urllib_parse.quote(n, ""), urllib_parse.quote(v, ""))) - return "&".join(encoded_bits) + if not PY3: + new_query = [] + for k,v in query: + if type(k) is unicode: k = k.encode('utf-8') + if type(v) is unicode: v = v.encode('utf-8') + new_query.append((k, v)) + query = new_query + return urlencode(query).replace("+", "%20")