def __init__(
self,
host='localhost',
port=9200,
http_auth=None,
use_ssl=False,
ssl_context=None,
verify_certs=False,
maxsize=10,
headers=None,
*,
loop,
**kwargs
):
super().__init__(host=host, port=port, use_ssl=use_ssl, **kwargs)
if headers is None:
headers = {}
self.headers = headers
self.headers.setdefault('Content-Type', 'application/json')
self.loop = loop
if http_auth is not None:
if isinstance(http_auth, aiohttp.BasicAuth):
pass
elif isinstance(http_auth, str):
http_auth = aiohttp.BasicAuth(*http_auth.split(':', 1))
elif isinstance(http_auth, (tuple, list)):
http_auth = aiohttp.BasicAuth(*http_auth)
else:
raise TypeError("Expected str, list, tuple or "
"aiohttp.BasicAuth as http_auth parameter,"
"got {!r}".format(http_auth))
self.http_auth = http_auth
self.verify_certs = verify_certs
self.base_url = URL.build(scheme='https' if self.use_ssl else 'http',
host=host,
port=port,
path=self.url_prefix)
self.session = kwargs.get('session')
if self.session is None:
self.session = aiohttp.ClientSession(
auth=self.http_auth,
connector=aiohttp.TCPConnector(
limit=maxsize,
use_dns_cache=kwargs.get('use_dns_cache', False),
ssl_context=ssl_context,
verify_ssl=self.verify_certs,
loop=self.loop,
),
)
评论列表
文章目录