From 4de7333c78bf422a1b0c66511536aaf3aa8cb652 Mon Sep 17 00:00:00 2001 From: Joshua Roesslein Date: Sat, 26 Apr 2014 22:45:27 -0700 Subject: [PATCH] Remove all uses of HTTP. --- docs/api.rst | 3 +-- tweepy/api.py | 3 +-- tweepy/auth.py | 25 +++++++------------------ tweepy/binder.py | 7 +------ tweepy/streaming.py | 6 +----- 5 files changed, 11 insertions(+), 33 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index 5eeb787..0dab297 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -11,7 +11,7 @@ This page contains some basic documentation for the Tweepy module. :mod:`tweepy.api` --- Twitter API wrapper ========================================= -.. class:: API([auth_handler=None], [host='api.twitter.com'], [search_host='search.twitter.com'], [cache=None], [secure=False], [api_root='/1'], [search_root=''], [retry_count=0], [retry_delay=0], [retry_errors=None], [model_factory]) +.. class:: API([auth_handler=None], [host='api.twitter.com'], [search_host='search.twitter.com'], [cache=None], [api_root='/1'], [search_root=''], [retry_count=0], [retry_delay=0], [retry_errors=None], [model_factory]) This class provides a wrapper for the API as provided by Twitter. The functions provided in this class are listed below. @@ -20,7 +20,6 @@ This page contains some basic documentation for the Tweepy module. :param host: general API host :param search_host: search API host :param cache: cache backend to use - :param secure: if True use https :param api_root: general API path root :param search_root: search API path root :param retry_count: default number of retries to attempt when error occurs diff --git a/tweepy/api.py b/tweepy/api.py index a44676c..0e606ec 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -16,7 +16,7 @@ class API(object): def __init__(self, auth_handler=None, host='api.twitter.com', search_host='search.twitter.com', - cache=None, secure=True, api_root='/1.1', search_root='', + cache=None, api_root='/1.1', search_root='', retry_count=0, retry_delay=0, retry_errors=None, timeout=60, parser=None, compression=False, wait_on_rate_limit=False, wait_on_rate_limit_notify=False): @@ -26,7 +26,6 @@ class API(object): self.api_root = api_root self.search_root = search_root self.cache = cache - self.secure = secure self.compression = compression self.retry_count = retry_count self.retry_delay = retry_delay diff --git a/tweepy/auth.py b/tweepy/auth.py index b304139..7ed7e26 100644 --- a/tweepy/auth.py +++ b/tweepy/auth.py @@ -26,7 +26,7 @@ class OAuthHandler(AuthHandler): OAUTH_HOST = 'api.twitter.com' OAUTH_ROOT = '/oauth/' - def __init__(self, consumer_key, consumer_secret, callback=None, secure=True): + def __init__(self, consumer_key, consumer_secret, callback=None): if type(consumer_key) == unicode: consumer_key = bytes(consumer_key) @@ -39,15 +39,10 @@ class OAuthHandler(AuthHandler): self.access_token_secret = None self.callback = callback self.username = None - self.secure = secure self.oauth = OAuth1Session(consumer_key, client_secret=consumer_secret, callback_uri=self.callback) - def _get_oauth_url(self, endpoint, secure=True): - if self.secure or secure: - prefix = 'https://' - else: - prefix = 'http://' - return prefix + self.OAUTH_HOST + self.OAUTH_ROOT + endpoint + def _get_oauth_url(self, endpoint): + return 'https://' + self.OAUTH_HOST + self.OAUTH_ROOT + endpoint def apply_auth(self): return OAuth1(self.consumer_key, client_secret=self.consumer_secret, resource_owner_key=self.access_token, resource_owner_secret=self.access_token_secret) @@ -98,7 +93,7 @@ class OAuthHandler(AuthHandler): and request activation of xAuth for it. """ try: - url = self._get_oauth_url('access_token', secure=True) + url = self._get_oauth_url('access_token') oauth = OAuth1(self.consumer_key, client_secret=self.consumer_secret) r = requests.post(url=url, auth=oauth, headers={'x_auth_mode': 'client_auth', 'x_auth_username': username, 'x_auth_password': @@ -136,9 +131,8 @@ class AppAuthHandler(AuthHandler): OAUTH_HOST = 'api.twitter.com' OAUTH_ROOT = '/oauth2/' - def __init__(self, consumer_key, consumer_secret, callback=None, secure=True): + def __init__(self, consumer_key, consumer_secret, callback=None): self.callback = callback - self.secure = secure self._bearer_token = '' resp = requests.post(self.url, auth=(self.consumer_key, self.consumer_secret), @@ -152,13 +146,8 @@ class AppAuthHandler(AuthHandler): self._bearer_token = json_response['access_token'] - def _get_oauth_url(self, endpoint, secure=True): - if self.secure or secure: - prefix = 'https://' - else: - prefix = 'http://' - - return prefix + self.OAUTH_HOST + self.OAUTH_ROOT + endpoint + def _get_oauth_url(self, endpoint): + return 'https://' + self.OAUTH_HOST + self.OAUTH_ROOT + endpoint def apply_auth(self): diff --git a/tweepy/binder.py b/tweepy/binder.py index a15c492..c1c58ea 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -56,11 +56,6 @@ def bind_api(**config): # Perform any path variable substitution self.build_path() - if api.secure: - self.scheme = 'https://' - else: - self.scheme = 'http://' - if self.search_api: self.host = api.search_host else: @@ -115,7 +110,7 @@ def bind_api(**config): # Build the request URL url = self.api_root + self.path - full_url = self.scheme + self.host + url + full_url = 'https://' + self.host + url # Query the cache if one is available # and this request uses a GET method. diff --git a/tweepy/streaming.py b/tweepy/streaming.py index 89d81e1..dab8ec3 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -124,10 +124,6 @@ class Stream(object): self.snooze_time_step = options.get("snooze_time", 0.25) self.snooze_time_cap = options.get("snooze_time_cap", 16) self.buffer_size = options.get("buffer_size", 1500) - if options.get("secure", True): - self.scheme = "https" - else: - self.scheme = "http" self.api = API() self.session = requests.Session() @@ -139,7 +135,7 @@ class Stream(object): def _run(self): # Authenticate - url = "%s://%s%s" % (self.scheme, self.host, self.url) + url = "https://%s%s" % (self.host, self.url) # Connect and process the stream error_counter = 0 -- 2.25.1