X-Git-Url: https://jfr.im/git/z_archive/twitter.git/blobdiff_plain/d4f3123e5401d0d8f466b2306d953158e59ffe4b..17b9ff10207340026b876eb623660f2c79bfe85d:/twitter/oauth.py diff --git a/twitter/oauth.py b/twitter/oauth.py index dcc062c..b0d7f41 100644 --- a/twitter/oauth.py +++ b/twitter/oauth.py @@ -41,23 +41,23 @@ code it all goes like this:: from __future__ import print_function -from time import time from random import getrandbits +from time import time + +from .util import PY_3_OR_HIGHER 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 import base64 -from .auth import Auth +from .auth import Auth, MissingCredentialsError def write_token_file(filename, oauth_token, oauth_token_secret): @@ -92,6 +92,10 @@ class OAuth(Auth): self.consumer_key = consumer_key self.consumer_secret = consumer_secret + if token_secret is None or consumer_secret is None: + raise MissingCredentialsError( + 'You must supply strings for token_secret and consumer_secret, not None.') + def encode_params(self, base_url, method, params): params = params.copy() @@ -125,7 +129,7 @@ class OAuth(Auth): # 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: + if not PY_3_OR_HIGHER: new_query = [] TILDE = '____TILDE-PYTHON-TWITTER____' for k,v in query: