Commit 7aa4f62f authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis

astakosclient: Use objpool version 0.2

parent 6061997d
......@@ -141,17 +141,15 @@ class AstakosClient():
kwargs['headers'].setdefault('content-length',
len(body) if body else 0)
# Get the connection object
conn = self.conn_class(self.netloc)
# Send request
try:
(data, status) = _do_request(conn, method, request_path, **kwargs)
# Get the connection object
with self.conn_class(self.netloc) as conn:
# Send request
(data, status) = \
_do_request(conn, method, request_path, **kwargs)
except Exception as err:
self.logger.error("Failed to send request: %s" % repr(err))
raise AstakosClientException(str(err))
finally:
conn.close()
# Return
self.logger.debug("Request returned with status %s" % status)
......
......@@ -31,9 +31,10 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
import httplib
from httplib import HTTPConnection, HTTPSConnection
from contextlib import closing
import objpool.http
from objpool.http import PooledHTTPConnection
from astakosclient.errors import AstakosClientException
......@@ -59,18 +60,24 @@ def retry(func):
def scheme_to_class(scheme, use_pool, pool_size):
"""Return the appropriate conn class for given scheme"""
def _objpool(netloc):
return objpool.http.get_http_connection(
return PooledHTTPConnection(
netloc=netloc, scheme=scheme, pool_size=pool_size)
def _http_connection(netloc):
return closing(HTTPConnection(netloc))
def _https_connection(netloc):
return closing(HTTPSConnection(netloc))
if scheme == "http":
if use_pool:
return _objpool
else:
return httplib.HTTPConnection
return _http_connection
elif scheme == "https":
if use_pool:
return _objpool
else:
return httplib.HTTPSConnection
return _https_connection
else:
return None
......@@ -59,7 +59,7 @@ CLASSIFIERS = []
# Package requirements
INSTALL_REQUIRES = [
"objpool",
"objpool >= 0.2",
"simplejson"
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment