當前位置: 首頁>>代碼示例>>Python>>正文


Python connection.HTTPConnection方法代碼示例

本文整理匯總了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 
開發者ID:zaihui,項目名稱:hutils,代碼行數:26,代碼來源:unittest.py

示例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' 
開發者ID:sourcelair,項目名稱:ceryx,代碼行數:27,代碼來源:connection.py

示例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 
開發者ID:openstack,項目名稱:oslo.vmware,代碼行數:32,代碼來源:rw_handles.py


注:本文中的urllib3.connection.HTTPConnection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。