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


Python HTTPConnectionPool._get_conn方法代码示例

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


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

示例1: test_connect_timeout

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

        # Pool-global timeout
        pool = HTTPConnectionPool(TARPIT_HOST, self.port, timeout=timeout)
        conn = pool._get_conn()
        self.assertRaises(ConnectTimeoutError, pool._make_request, conn, 'GET', url)

        # Retries
        retries = Retry(connect=0)
        self.assertRaises(MaxRetryError, pool.request, 'GET', url,
                          retries=retries)

        # Request-specific connection timeouts
        big_timeout = Timeout(read=0.2, connect=0.2)
        pool = HTTPConnectionPool(TARPIT_HOST, self.port,
                                  timeout=big_timeout, retries=False)
        conn = pool._get_conn()
        self.assertRaises(ConnectTimeoutError, pool._make_request, conn, 'GET',
                          url, timeout=timeout)

        pool._put_conn(conn)
        self.assertRaises(ConnectTimeoutError, pool.request, 'GET', url,
                          timeout=timeout)
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:27,代码来源:test_connectionpool.py

示例2: test_total_timeout

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

        timeout = util.Timeout(connect=3, read=5, total=0.001)
        pool = HTTPConnectionPool(TARPIT_HOST, self.port, timeout=timeout)
        conn = pool._get_conn()
        self.assertRaises(ConnectTimeoutError, pool._make_request, conn, 'GET', url)

        # This will get the socket to raise an EAGAIN on the read
        timeout = util.Timeout(connect=3, read=0)
        pool = HTTPConnectionPool(self.host, self.port, timeout=timeout)
        conn = pool._get_conn()
        self.assertRaises(ReadTimeoutError, pool._make_request, conn, 'GET', url)

        # The connect should succeed and this should hit the read timeout
        timeout = util.Timeout(connect=3, read=5, total=0.002)
        pool = HTTPConnectionPool(self.host, self.port, timeout=timeout)
        conn = pool._get_conn()
        self.assertRaises(ReadTimeoutError, pool._make_request, conn, 'GET', url)

        timeout = util.Timeout(total=None, connect=0.001)
        pool = HTTPConnectionPool(TARPIT_HOST, self.port, timeout=timeout)
        conn = pool._get_conn()
        self.assertRaises(ConnectTimeoutError, pool._make_request, conn, 'GET',
                          url)
开发者ID:gruns,项目名称:urllib3,代码行数:27,代码来源:test_connectionpool.py

示例3: test_connect_timeout

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _get_conn [as 别名]
    def test_connect_timeout(self):
        def noop_handler(listener):
            return

        self._start_server(noop_handler)

        url = '/'
        host, port = self.host, self.port
        timeout = Timeout(connect=SHORT_TIMEOUT)

        # Pool-global timeout
        pool = HTTPConnectionPool(host, port, timeout=timeout)
        conn = pool._get_conn()
        self.assertRaises(ConnectTimeoutError, pool._make_request, conn, 'GET', url)

        # Retries
        retries = Retry(connect=0)
        self.assertRaises(MaxRetryError, pool.request, 'GET', url, retries=retries)

        # Request-specific connection timeouts
        big_timeout = Timeout(read=LONG_TIMEOUT, connect=LONG_TIMEOUT)
        pool = HTTPConnectionPool(host, port, timeout=big_timeout, retries=False)
        conn = pool._get_conn()
        self.assertRaises(ConnectTimeoutError, pool._make_request, conn, 'GET', url, timeout=timeout)

        pool._put_conn(conn)
        self.assertRaises(ConnectTimeoutError, pool.request, 'GET', url, timeout=timeout)
开发者ID:rubycarlin,项目名称:PythonAppEngine-YouPlay,代码行数:29,代码来源:test_connectionpool.py

示例4: test_connect_timeout

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _get_conn [as 别名]
    def test_connect_timeout(self):
        url = '/'
        host, port = TARPIT_HOST, 80
        timeout = Timeout(connect=SHORT_TIMEOUT)

        # Pool-global timeout
        pool = HTTPConnectionPool(host, port, timeout=timeout)
        self.addCleanup(pool.close)
        conn = pool._get_conn()
        self.assertRaises(ConnectTimeoutError, pool._make_request, conn, 'GET', url)

        # Retries
        retries = Retry(connect=0)
        self.assertRaises(MaxRetryError, pool.request, 'GET', url, retries=retries)

        # Request-specific connection timeouts
        big_timeout = Timeout(read=LONG_TIMEOUT, connect=LONG_TIMEOUT)
        pool = HTTPConnectionPool(host, port, timeout=big_timeout, retries=False)
        self.addCleanup(pool.close)
        conn = pool._get_conn()
        self.assertRaises(ConnectTimeoutError,
                          pool._make_request,
                          conn, 'GET', url,
                          timeout=timeout)

        pool._put_conn(conn)
        self.assertRaises(ConnectTimeoutError, pool.request, 'GET', url, timeout=timeout)
开发者ID:Lukasa,项目名称:urllib3,代码行数:29,代码来源:test_connectionpool.py

示例5: test_timeout

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _get_conn [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

示例6: test_timeout

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

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

        conn = pool._get_conn()
        self.assertRaises(ReadTimeoutError, pool._make_request, conn, "GET", url)
        pool._put_conn(conn)

        self.assertRaises(ReadTimeoutError, pool.request, "GET", url)

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

        conn = pool._get_conn()
        self.assertRaises(ReadTimeoutError, pool._make_request, conn, "GET", url, timeout=timeout)
        pool._put_conn(conn)

        self.assertRaises(ReadTimeoutError, pool.request, "GET", url, timeout=timeout)

        # Timeout int/float passed directly to request and _make_request should
        # raise a request timeout
        self.assertRaises(ReadTimeoutError, pool.request, "GET", url, timeout=0.001)
        conn = pool._new_conn()
        self.assertRaises(ReadTimeoutError, pool._make_request, conn, "GET", url, timeout=0.001)
        pool._put_conn(conn)

        # Timeout int/float passed directly to _make_request should not raise a
        # request timeout if it's a high value
        pool.request("GET", url, timeout=5)
开发者ID:github3py,项目名称:urllib3,代码行数:34,代码来源:test_connectionpool.py

示例7: test_tunnel

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _get_conn [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

示例8: test_timeout

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _get_conn [as 别名]
    def test_timeout(self):
        # Requests should time out when expected
        block_event = Event()
        ready_event = self.start_basic_handler(block_send=block_event, num=6)

        # Pool-global timeout
        timeout = Timeout(read=SHORT_TIMEOUT)
        pool = HTTPConnectionPool(self.host, self.port, timeout=timeout, retries=False)
        self.addCleanup(pool.close)

        wait_for_socket(ready_event)
        conn = pool._get_conn()
        self.assertRaises(ReadTimeoutError, pool._make_request, conn, 'GET', '/')
        pool._put_conn(conn)
        block_event.set()  # Release request

        wait_for_socket(ready_event)
        block_event.clear()
        self.assertRaises(ReadTimeoutError, pool.request, 'GET', '/')
        block_event.set()  # Release request

        # Request-specific timeouts should raise errors
        pool = HTTPConnectionPool(self.host, self.port, timeout=LONG_TIMEOUT, retries=False)
        self.addCleanup(pool.close)

        conn = pool._get_conn()
        wait_for_socket(ready_event)
        now = time.time()
        self.assertRaises(ReadTimeoutError, pool._make_request, conn, 'GET', '/', timeout=timeout)
        delta = time.time() - now
        block_event.set()  # Release request

        message = "timeout was pool-level LONG_TIMEOUT rather than request-level SHORT_TIMEOUT"
        self.assertTrue(delta < LONG_TIMEOUT, message)
        pool._put_conn(conn)

        wait_for_socket(ready_event)
        now = time.time()
        self.assertRaises(ReadTimeoutError, pool.request, 'GET', '/', timeout=timeout)
        delta = time.time() - now

        message = "timeout was pool-level LONG_TIMEOUT rather than request-level SHORT_TIMEOUT"
        self.assertTrue(delta < LONG_TIMEOUT, message)
        block_event.set()  # Release request

        # Timeout int/float passed directly to request and _make_request should
        # raise a request timeout
        wait_for_socket(ready_event)
        self.assertRaises(ReadTimeoutError, pool.request, 'GET', '/', timeout=SHORT_TIMEOUT)
        block_event.set()  # Release request

        wait_for_socket(ready_event)
        conn = pool._new_conn()
        # FIXME: This assert flakes sometimes. Not sure why.
        self.assertRaises(ReadTimeoutError,
                          pool._make_request,
                          conn, 'GET', '/',
                          timeout=SHORT_TIMEOUT)
        block_event.set()  # Release request
开发者ID:Lukasa,项目名称:urllib3,代码行数:61,代码来源:test_connectionpool.py

示例9: test_total_applies_connect

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _get_conn [as 别名]
    def test_total_applies_connect(self):
        host, port = TARPIT_HOST, 80

        timeout = Timeout(total=None, connect=SHORT_TIMEOUT)
        pool = HTTPConnectionPool(host, port, timeout=timeout)
        conn = pool._get_conn()
        self.assertRaises(ConnectTimeoutError, pool._make_request, conn, 'GET', '/')

        timeout = Timeout(connect=3, read=5, total=SHORT_TIMEOUT)
        pool = HTTPConnectionPool(host, port, timeout=timeout)
        conn = pool._get_conn()
        self.assertRaises(ConnectTimeoutError, pool._make_request, conn, 'GET', '/')
开发者ID:Altynai,项目名称:urllib3,代码行数:14,代码来源:test_connectionpool.py

示例10: test_total_applies_connect

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _get_conn [as 别名]
    def test_total_applies_connect(self):
        def noop_handler(listener):
            return

        self._start_server(noop_handler)

        timeout = Timeout(total=None, connect=SHORT_TIMEOUT)
        pool = HTTPConnectionPool(self.host, self.port, timeout=timeout)
        conn = pool._get_conn()
        self.assertRaises(ConnectTimeoutError, pool._make_request, conn, 'GET', '/')

        timeout = Timeout(connect=3, read=5, total=SHORT_TIMEOUT)
        pool = HTTPConnectionPool(self.host, self.port, timeout=timeout)
        conn = pool._get_conn()
        self.assertRaises(ConnectTimeoutError, pool._make_request, conn, 'GET', '/')
开发者ID:rubycarlin,项目名称:PythonAppEngine-YouPlay,代码行数:17,代码来源:test_connectionpool.py

示例11: test_none_total_applies_connect

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _get_conn [as 别名]
 def test_none_total_applies_connect(self):
     url = '/sleep?seconds=0.005'
     timeout = Timeout(total=None, connect=0.001)
     pool = HTTPConnectionPool(TARPIT_HOST, self.port, timeout=timeout)
     conn = pool._get_conn()
     self.assertRaises(ConnectTimeoutError, pool._make_request, conn, 'GET',
                       url)
开发者ID:balagopalraj,项目名称:clearlinux,代码行数:9,代码来源:test_connectionpool.py

示例12: test_nagle

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _get_conn [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

示例13: test_connect_timeout

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _get_conn [as 别名]
    def test_connect_timeout(self):
        url = "/sleep"
        timeout = util.Timeout(connect=0.001)

        # Pool-global timeout
        pool = HTTPConnectionPool(TARPIT_HOST, self.port, timeout=timeout)
        conn = pool._get_conn()
        self.assertRaises(ConnectTimeoutError, pool._make_request, conn, "GET", url)
        pool._put_conn(conn)
        self.assertRaises(ConnectTimeoutError, pool.request, "GET", url)

        # Request-specific connection timeouts
        big_timeout = util.Timeout(read=0.5, connect=0.5)
        pool = HTTPConnectionPool(TARPIT_HOST, self.port, timeout=big_timeout)
        conn = pool._get_conn()
        self.assertRaises(ConnectTimeoutError, pool._make_request, conn, "GET", url, timeout=timeout)

        pool._put_conn(conn)
        self.assertRaises(ConnectTimeoutError, pool.request, "GET", url, timeout=timeout)
开发者ID:github3py,项目名称:urllib3,代码行数:21,代码来源:test_connectionpool.py

示例14: test_timeout_reset

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _get_conn [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

示例15: test_nagle

# 需要导入模块: from urllib3 import HTTPConnectionPool [as 别名]
# 或者: from urllib3.HTTPConnectionPool import _get_conn [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._get_conn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。