Skip to content

Commit

Permalink
Refactor Connection Adapter name (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
chattarajoy committed Mar 2, 2020
1 parent 168a2bc commit 8a95947
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions qds_sdk/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"""


class MyAdapter(HTTPAdapter):
class RequestAdapter(HTTPAdapter):
def __init__(self, *args, **kwargs):
super(MyAdapter, self).__init__(*args, **kwargs)
super(RequestAdapter, self).__init__(*args, **kwargs)

def init_poolmanager(self, connections, maxsize,block=False):
self.poolmanager = PoolManager(num_pools=connections,
Expand All @@ -49,11 +49,11 @@ def __init__(self, auth, rest_url, skip_ssl_cert_check,
self.base_retry_delay = base_retry_delay
if reuse:
self.session = requests.Session()
self.session.mount('https://', MyAdapter())
self.session.mount('https://', RequestAdapter())

# retries for get requests
self.session_with_retries = requests.Session()
self.session_with_retries.mount('https://', MyAdapter(max_retries=3))
self.session_with_retries.mount('https://', RequestAdapter(max_retries=3))

def retry(ExceptionToCheck, tries=5, delay=10, backoff=2):
def deco_retry(f):
Expand All @@ -78,7 +78,7 @@ def f_retry(self, *args, **kwargs):
return f_retry # true decorator
return deco_retry

@retry((RetryWithDelay, requests.Timeout, ServerError, ApiThrottledRetry))
@retry((RetryWithDelay, requests.Timeout, ServerError, ApiThrottledRetry, Error))
def get_raw(self, path, params=None):
return self._api_call_raw("GET", path, params=params)

Expand Down Expand Up @@ -107,7 +107,7 @@ def _api_call_raw(self, req_type, path, data=None, params=None):
else:
x = requests
x_with_retries = requests.Session()
x_with_retries.mount('https://', MyAdapter(max_retries=3))
x_with_retries.mount('https://', RequestAdapter(max_retries=3))

kwargs = {'headers': self._headers, 'auth': self.auth, 'verify': not self.skip_ssl_cert_check}

Expand All @@ -131,12 +131,12 @@ def _api_call_raw(self, req_type, path, data=None, params=None):
else:
raise NotImplemented

self._validate_json(r)
self._handle_error(r)
return r

def _api_call(self, req_type, path, data=None, params=None):
response = self._api_call_raw(req_type, path, data=data, params=params)
self._validate_json(response)
return response.json()

@staticmethod
Expand Down

0 comments on commit 8a95947

Please sign in to comment.