本文整理汇总了Python中urllib3.connection.HTTPConnection方法的典型用法代码示例。如果您正苦于以下问题:Python connection.HTTPConnection方法的具体用法?Python connection.HTTPConnection怎么用?Python connection.HTTPConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib3.connection
的用法示例。
在下文中一共展示了connection.HTTPConnection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: disable_network
# 需要导入模块: from urllib3 import connection [as 别名]
# 或者: from urllib3.connection import HTTPConnection [as 别名]
def disable_network():
""" Disable network """
class DisableNetwork:
def __init__(self, *args, **kwargs):
raise Exception("Network through socket is disabled!")
def __call__(self, *args, **kwargs):
raise Exception("Network through socket is disabled!")
real_socket = socket.socket
client.HTTPConnection = DisableNetwork
try:
from urllib3 import connection
connection.HTTPConnection = DisableNetwork
except ImportError:
pass
socket.socket = DisableNetwork
patcher = mock.patch("asyncio.selector_events.socket.socket", real_socket)
patcher.start()
return patcher
示例2: __init__
# 需要导入模块: from urllib3 import connection [as 别名]
# 或者: from urllib3.connection import HTTPConnection [as 别名]
def __init__(
self, host, port=None, key_file=None, cert_file=None,
key_password=None, strict=None,
timeout=socket._GLOBAL_DEFAULT_TIMEOUT, ssl_context=None,
server_hostname=None, **kw,
):
# Initialise the HTTPConnection subclass created above.
CeryxTestsHTTPConnection.__init__(
self, host, port, strict=strict, timeout=timeout, **kw,
)
self.key_file = key_file
self.cert_file = cert_file
self.key_password = key_password
self.ssl_context = ssl_context
self.server_hostname = server_hostname
# ------------------------------
# Original comment from upstream
# ------------------------------
#
# Required property for Google AppEngine 1.9.0 which otherwise causes
# HTTPS requests to go out as HTTP. (See Issue #356)
self._protocol = 'https'
示例3: _create_connection
# 需要导入模块: from urllib3 import connection [as 别名]
# 或者: from urllib3.connection import HTTPConnection [as 别名]
def _create_connection(self, url, method, cacerts=False,
ssl_thumbprint=None):
_urlparse = urlparse.urlparse(url)
scheme, netloc, path, params, query, fragment = _urlparse
if scheme == 'http':
conn = httplib.HTTPConnection(netloc)
elif scheme == 'https':
conn = httplib.HTTPSConnection(netloc)
cert_reqs = None
# cacerts can be either True or False or contain
# actual certificates. If it is a boolean, then
# we need to set cert_reqs and clear the cacerts
if isinstance(cacerts, bool):
if cacerts:
cert_reqs = ssl.CERT_REQUIRED
else:
cert_reqs = ssl.CERT_NONE
cacerts = requests.certs.where()
conn.set_cert(ca_certs=cacerts, cert_reqs=cert_reqs,
assert_fingerprint=ssl_thumbprint)
else:
excep_msg = _("Invalid scheme: %s.") % scheme
LOG.error(excep_msg)
raise ValueError(excep_msg)
if query:
path = path + '?' + query
conn.putrequest(method, path)
return conn