X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/abe67abb76fea0a5a3aab4d839f6c6730982d654..3f6ca83dfc697b71974d2fa3b10b4e68c4d4c621:/twitter/oauth.py diff --git a/twitter/oauth.py b/twitter/oauth.py index 6c1b68f..f13ef22 100644 --- a/twitter/oauth.py +++ b/twitter/oauth.py @@ -33,7 +33,7 @@ code it all goes like this:: oauth_token, oauth_token_secret, CONSUMER_KEY, CONSUMER_SECRET)) # Now work with Twitter - twitter.statuses.update('Hello, world!') + twitter.statuses.update(status='Hello, world!') """ @@ -121,12 +121,18 @@ class OAuth(Auth): # %20 rather than '+' when constructing an OAuth signature (and therefore # also in the request itself.) # So here is a specialized version which does exactly that. +# In Python2, since there is no safe option for urlencode, we force it by hand def urlencode_noplus(query): if not PY3: new_query = [] + TILDE = '____TILDE-PYTHON-TWITTER____' for k,v in query: if type(k) is unicode: k = k.encode('utf-8') + k = str(k).replace("~", TILDE) if type(v) is unicode: v = v.encode('utf-8') + v = str(v).replace("~", TILDE) new_query.append((k, v)) query = new_query + return urlencode(query).replace(TILDE, "~").replace("+", "%20") + return urlencode(query, safe='~').replace("+", "%20")