X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/dd48ea532f2a0d71d3a97d779b4e5c06d1b0762e..c0c66ba0ebe25c1ddc446111dc29a1e6fc07b367:/twitter/oauth.py diff --git a/twitter/oauth.py b/twitter/oauth.py index 5fd995e..dcc062c 100644 --- a/twitter/oauth.py +++ b/twitter/oauth.py @@ -22,6 +22,8 @@ strings in the file. Not terribly exciting. Finally, you can use the OAuth authenticator to connect to Twitter. In code it all goes like this:: + from twitter import * + MY_TWITTER_CREDS = os.path.expanduser('~/.my_app_credentials') if not os.path.exists(MY_TWITTER_CREDS): oauth_dance("My App Name", CONSUMER_KEY, CONSUMER_SECRET, @@ -121,14 +123,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("+", "%20") + return urlencode(query).replace(TILDE, "~").replace("+", "%20") - return urlencode(query, safe='~').replace("+", "%20") \ No newline at end of file + return urlencode(query, safe='~').replace("+", "%20")