Add support for parameter session and make use of requests sessions
@@ -26,6 +26,7 @@ class Base(object):
fieldnames = []
error = None
status_code = None
+ session = None
headers = {}
params = {}
@@ -68,9 +69,8 @@ class Base(object):
self.method.title()
)
- @staticmethod
- def rate_limited_get(url, **kwargs):
- return requests.get(url, **kwargs)
+ def rate_limited_get(self, url, **kwargs):
+ return self.session.get(url, **kwargs)
def _get_api_key(self, base_key, **kwargs):
key = kwargs.get('key')
@@ -121,7 +121,8 @@ class Base(object):
self.parse = self.tree()
self.content = None
self.encoding = kwargs.get('encoding', 'utf-8')
- self._connect(url=self.url, params=self.params, **kwargs)
+ self.session = kwargs.get('session', requests.Session())
+ self._connect(url=self.url, **kwargs)
###
try:
for result in self.next(): # Convert to iterator in each of the search tools
