Revision 996061fa snf-astakos-client/astakosclient/__init__.py

b/snf-astakos-client/astakosclient/__init__.py
93 93
    """AstakosClient Class Implementation"""
94 94

  
95 95
    # ----------------------------------
96
    def __init__(self, astakos_url, use_pool=False, retry=0, logger=None):
96
    def __init__(self, astakos_url, retry=0,
97
                 use_pool=False, pool_size=8, logger=None):
97 98
        """Intialize AstakosClient Class
98 99

  
99 100
        Keyword arguments:
......
119 120

  
120 121
        # Check for supported scheme
121 122
        p = urlparse.urlparse(astakos_url)
122
        conn_class = _scheme_to_class(p.scheme, use_pool)
123
        conn_class = _scheme_to_class(p.scheme, use_pool, pool_size)
123 124
        if conn_class is None:
124 125
            m = "Unsupported scheme: %s" % p.scheme
125 126
            logger.error(m)
......
193 194
        try:
194 195
            (data, status) = _doRequest(conn, method, request_path, **kwargs)
195 196
        except Exception as err:
196
            self.logger.error("Failed to send request: %s" % err)
197
            self.logger.error("Failed to send request: %s" % repr(err))
197 198
            raise AstakosClientException(str(err))
198 199
        finally:
199 200
            conn.close()
......
332 333

  
333 334
# --------------------------------------------------------------------
334 335
# Private functions
335
def _scheme_to_class(scheme, use_pool):
336
def _scheme_to_class(scheme, use_pool, pool_size):
336 337
    """Return the appropriate conn class for given scheme"""
338
    def _objpool(netloc):
339
        return objpool.http.get_http_connection(
340
            netloc=netloc, scheme=scheme, pool_size=pool_size)
341

  
337 342
    if scheme == "http":
338 343
        if use_pool:
339
            return _objpoolHttpScheme
344
            return _objpool
340 345
        else:
341 346
            return httplib.HTTPConnection
342 347
    elif scheme == "https":
343 348
        if use_pool:
344
            return _objpoolHttpsScheme
349
            return _objpool
345 350
        else:
346 351
            return httplib.HTTPSConnection
347 352
    else:
348 353
        return None
349 354

  
350 355

  
351
def _objpoolHttpScheme(netloc):
352
    """Intialize the appropriate objpool.http class"""
353
    return objpool.http.get_http_connection(netloc, "http")
354

  
355

  
356
def _objpoolHttpsScheme(netloc):
357
    """Intialize the appropriate objpool.http class"""
358
    return objpool.http.get_http_connection(netloc, "https")
359

  
360

  
361 356
def _doRequest(conn, method, url, **kwargs):
362 357
    """The actual request. This function can easily be mocked"""
363 358
    conn.request(method, url, **kwargs)

Also available in: Unified diff