本文整理汇总了Python中urllib3.poolmanager.PoolManager.connection_from_host方法的典型用法代码示例。如果您正苦于以下问题:Python PoolManager.connection_from_host方法的具体用法?Python PoolManager.connection_from_host怎么用?Python PoolManager.connection_from_host使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib3.poolmanager.PoolManager
的用法示例。
在下文中一共展示了PoolManager.connection_from_host方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pools_keyed_with_from_host
# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_host [as 别名]
def test_pools_keyed_with_from_host(self):
"""Assert pools are still keyed correctly with connection_from_host."""
ssl_kw = {
'key_file': '/root/totally_legit.key',
'cert_file': '/root/totally_legit.crt',
'cert_reqs': 'CERT_REQUIRED',
'ca_certs': '/root/path_to_pem',
'ssl_version': 'SSLv23_METHOD',
}
p = PoolManager(5, **ssl_kw)
conns = []
conns.append(
p.connection_from_host('example.com', 443, scheme='https')
)
for k in ssl_kw:
p.connection_pool_kw[k] = 'newval'
conns.append(
p.connection_from_host('example.com', 443, scheme='https')
)
assert all(
x is not y
for i, x in enumerate(conns)
for j, y in enumerate(conns)
if i != j
)
示例2: test_http_connection_from_host_case_insensitive
# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_host [as 别名]
def test_http_connection_from_host_case_insensitive(self):
"""Assert scheme case is ignored when getting the https key class."""
p = PoolManager()
pool = p.connection_from_host('example.com', scheme='http')
other_pool = p.connection_from_host('EXAMPLE.COM', scheme='HTTP')
assert 1 == len(p.pools)
assert pool is other_pool
assert all(isinstance(key, PoolKey) for key in p.pools.keys())
示例3: test_http_connection_from_host_case_insensitive
# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_host [as 别名]
def test_http_connection_from_host_case_insensitive(self):
"""Assert scheme case is ignored when getting the https key class."""
p = PoolManager()
self.addCleanup(p.clear)
pool = p.connection_from_host('example.com', scheme='http')
other_pool = p.connection_from_host('EXAMPLE.COM', scheme='HTTP')
self.assertEqual(1, len(p.pools))
self.assertTrue(pool is other_pool)
self.assertTrue(all(isinstance(key, PoolKey) for key in p.pools.keys()))
示例4: test_pool_kwargs_socket_options
# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_host [as 别名]
def test_pool_kwargs_socket_options(self):
"""Assert passing socket options works with connection_from_host"""
p = PoolManager(socket_options=[])
override_opts = [
(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1),
(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
]
pool_kwargs = {'socket_options': override_opts}
default_pool = p.connection_from_host('example.com', scheme='http')
override_pool = p.connection_from_host(
'example.com', scheme='http', pool_kwargs=pool_kwargs
)
assert default_pool.conn_kw['socket_options'] == []
assert override_pool.conn_kw['socket_options'] == override_opts
示例5: test_override_pool_kwargs_host
# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_host [as 别名]
def test_override_pool_kwargs_host(self):
"""Assert overriding pool kwargs works with connection_from_host"""
p = PoolManager(strict=True)
pool_kwargs = {'strict': False, 'retries': 100, 'block': True}
default_pool = p.connection_from_host('example.com', scheme='http')
override_pool = p.connection_from_host('example.com', scheme='http',
pool_kwargs=pool_kwargs)
assert default_pool.strict
assert retry.Retry.DEFAULT == default_pool.retries
assert not default_pool.block
assert not override_pool.strict
assert 100 == override_pool.retries
assert override_pool.block
示例6: test_override_pool_kwargs_host
# 需要导入模块: from urllib3.poolmanager import PoolManager [as 别名]
# 或者: from urllib3.poolmanager.PoolManager import connection_from_host [as 别名]
def test_override_pool_kwargs_host(self):
"""Assert overriding pool kwargs works with connection_from_host"""
p = PoolManager(strict=True)
pool_kwargs = {'strict': False, 'retries': 100, 'block': True}
default_pool = p.connection_from_host('example.com', scheme='http')
override_pool = p.connection_from_host('example.com', scheme='http',
pool_kwargs=pool_kwargs)
self.assertTrue(default_pool.strict)
self.assertEqual(retry.Retry.DEFAULT, default_pool.retries)
self.assertFalse(default_pool.block)
self.assertFalse(override_pool.strict)
self.assertEqual(100, override_pool.retries)
self.assertTrue(override_pool.block)