当前位置: 首页>>代码示例>>Python>>正文


Python HTTPConnectionPool._make_request方法代码示例

本文整理汇总了Python中urllib3.HTTPConnectionPool._make_request方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPConnectionPool._make_request方法的具体用法?Python HTTPConnectionPool._make_request怎么用?Python HTTPConnectionPool._make_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib3.HTTPConnectionPool的用法示例。


在下文中一共展示了HTTPConnectionPool._make_request方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_timeout

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _make_request [as 别名]
    def test_timeout(self):
        url = '/sleep?seconds=0.005'
        timeout = 0.001

        # Pool-global timeout
        pool = HTTPConnectionPool(self.host, self.port, timeout=timeout)

        conn = pool._get_conn()
        with self.assertRaises(SocketTimeout):
            pool._make_request(conn, 'GET', url)
        pool._put_conn(conn)

        with self.assertRaises(TimeoutError):
            pool.request('GET', url)

        # Request-specific timeout
        pool = HTTPConnectionPool(self.host, self.port, timeout=0.5)

        conn = pool._get_conn()
        with self.assertRaises(SocketTimeout):
            pool._make_request(conn, 'GET', url, timeout=timeout)
        pool._put_conn(conn)

        with self.assertRaises(TimeoutError):
            pool.request('GET', url, timeout=timeout)
开发者ID:PeterScott,项目名称:urllib3,代码行数:27,代码来源:test_connectionpool.py

示例2: test_tunnel

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _make_request [as 别名]
    def test_tunnel(self):
        # note the actual httplib.py has no tests for this functionality
        timeout = Timeout(total=None)
        pool = HTTPConnectionPool(self.host, self.port, timeout=timeout)
        self.addCleanup(pool.close)
        conn = pool._get_conn()
        self.addCleanup(conn.close)
        try:
            conn.set_tunnel(self.host, self.port)
        except AttributeError:  # python 2.6
            conn._set_tunnel(self.host, self.port)

        conn._tunnel = mock.Mock(return_value=None)
        pool._make_request(conn, 'GET', '/')
        conn._tunnel.assert_called_once_with()

        # test that it's not called when tunnel is not set
        timeout = Timeout(total=None)
        pool = HTTPConnectionPool(self.host, self.port, timeout=timeout)
        self.addCleanup(pool.close)
        conn = pool._get_conn()
        self.addCleanup(conn.close)

        conn._tunnel = mock.Mock(return_value=None)
        pool._make_request(conn, 'GET', '/')
        self.assertEqual(conn._tunnel.called, False)
开发者ID:erlichmen,项目名称:urllib3,代码行数:28,代码来源:test_connectionpool.py

示例3: test_nagle

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _make_request [as 别名]
 def test_nagle(self):
     """ Test that connections have TCP_NODELAY turned on """
     # This test needs to be here in order to be run. socket.create_connection actually tries to
     # connect to the host provided so we need a dummyserver to be running.
     pool = HTTPConnectionPool(self.host, self.port)
     conn = pool._get_conn()
     pool._make_request(conn, 'GET', '/')
     tcp_nodelay_setting = conn.sock.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY)
     self.assertTrue(tcp_nodelay_setting)
开发者ID:Altynai,项目名称:urllib3,代码行数:11,代码来源:test_connectionpool.py

示例4: test_timeout_reset

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _make_request [as 别名]
 def test_timeout_reset(self):
     """ If the read timeout isn't set, socket timeout should reset """
     url = '/sleep?seconds=0.005'
     timeout = util.Timeout(connect=0.001)
     pool = HTTPConnectionPool(self.host, self.port, timeout=timeout)
     conn = pool._get_conn()
     try:
         pool._make_request(conn, 'GET', url)
     except ReadTimeoutError:
         self.fail("This request shouldn't trigger a read timeout.")
开发者ID:gruns,项目名称:urllib3,代码行数:12,代码来源:test_connectionpool.py

示例5: test_nagle

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _make_request [as 别名]
 def test_nagle(self):
     """ Test that connections have TCP_NODELAY turned on """
     pool = HTTPConnectionPool(self.host, self.port)
     conn = pool._get_conn()
     pool._make_request(conn, 'GET', '/')
     tcp_nodelay_setting = conn.sock.getsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY)
     assert tcp_nodelay_setting > 0, ("Expected TCP_NODELAY to be set on the "
                                      "socket (with value greater than 0) "
                                      "but instead was %s" %
                                      tcp_nodelay_setting)
开发者ID:gruns,项目名称:urllib3,代码行数:12,代码来源:test_connectionpool.py


注:本文中的urllib3.HTTPConnectionPool._make_request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。