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


Python client.HttpClient类代码示例

本文整理汇总了Python中aiohttp.client.HttpClient的典型用法代码示例。如果您正苦于以下问题:Python HttpClient类的具体用法?Python HttpClient怎么用?Python HttpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_cleanup_resolved_hosts_on_500

    def test_cleanup_resolved_hosts_on_500(self, m_request):
        c = HttpClient(
            [('localhost', 56777), ('localhost', 56778)],
            conn_timeout=0.0001, loop=self.loop)

        called = False

        class M:

            def clear(self):
                nonlocal called
                called = True

            def __contains__(self, key):
                return True

            def __getitem__(self, key):
                return 'localhost'

        c._connector._resolved_hosts = M()

        resp = unittest.mock.Mock()
        resp.status = 500

        m_request.return_value = asyncio.Future(loop=self.loop)
        m_request.return_value.set_result(resp)

        self.loop.run_until_complete(c.request('get', path='/'))
        self.assertTrue(called)
开发者ID:bmdru0503,项目名称:aiohttp,代码行数:29,代码来源:test_client.py

示例2: test_failed_request_conn

    def test_failed_request_conn(self):
        c = HttpClient(
            [('localhost', 56777), ('localhost', 56778)], loop=self.loop)

        self.assertRaises(
            aiohttp.ConnectionError,
            self.loop.run_until_complete,
            c.request('get', path='/', conn_timeout=0.0001))
开发者ID:adevore,项目名称:aiohttp,代码行数:8,代码来源:http_client_test.py

示例3: test_cleanup_resolved_hosts

    def test_cleanup_resolved_hosts(self):
        loop = unittest.mock.Mock()
        c = HttpClient('localhost:8080', loop=loop, resolve=True)
        c._resolved_hosts[('localhost', 123)] = object()
        loop.call_later.assert_called_with(
            c._resolve_timeout, c._cleanup_resolved_host)
        loop.reset_mock()

        c._cleanup_resolved_host()
        self.assertFalse(bool(c._resolved_hosts))
        loop.call_later.assert_called_with(
            c._resolve_timeout, c._cleanup_resolved_host)
开发者ID:adevore,项目名称:aiohttp,代码行数:12,代码来源:http_client_test.py

示例4: test_failed_request_one_failed

    def test_failed_request_one_failed(self):
        now = int(time.time())

        c = HttpClient(
            [('localhost', 56777), ('localhost', 56778)], loop=self.loop)
        c._hosts = []
        c._failed.append((('localhost', 1000), now - 10))
        c._failed.append((('localhost', 1001), now - 10))

        self.assertRaises(
            aiohttp.ConnectionError,
            self.loop.run_until_complete,
            c.request('get', path='/', timeout=0.0001))
开发者ID:adevore,项目名称:aiohttp,代码行数:13,代码来源:http_client_test.py

示例5: test_resurrect_failed_all

    def test_resurrect_failed_all(self, asyncio):
        now = int(time.time())

        c = HttpClient(
            [('localhost', 1000), ('localhost', 1000)], resolve=False)
        c._hosts = []
        c._failed.append((('localhost', 1000), now - 10))
        c._failed.append((('localhost', 1001), now - 10))
        c._resurrect_failed()

        self.assertEqual(
            c._hosts, [('localhost', 1000), ('localhost', 1001)])
        self.assertFalse(
            asyncio.get_event_loop.return_value.call_later.called)
开发者ID:adevore,项目名称:aiohttp,代码行数:14,代码来源:http_client_test.py

示例6: test_resurrect_failed

    def test_resurrect_failed(self):
        now = int(time.time())
        loop = unittest.mock.Mock()

        c = HttpClient(
            [('localhost', 1000), ('localhost', 1000)], loop=loop)
        c._hosts = []
        c._failed.append((('localhost', 1000), now - 10))
        c._failed.append((('localhost', 1001), now - 10))
        c._failed.append((('localhost', 1002), now + 10))
        c._resurrect_failed()

        self.assertEqual(
            c._hosts, [('localhost', 1000), ('localhost', 1001)])
        self.assertTrue(loop.call_later.called)
开发者ID:bmdru0503,项目名称:aiohttp,代码行数:15,代码来源:test_client.py

示例7: test_failed_request_one_failed

    def test_failed_request_one_failed(self):
        now = int(time.time())

        c = HttpClient(
            [('localhost', 56777), ('localhost', 56778)], loop=self.loop)
        c._hosts = []

        has_http_server = True
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            sock.connect(('127.0.0.1', 80))
        except ConnectionError:
            has_http_server = False
        finally:
            sock.close()

        c._failed.append((('localhost', 1000, has_http_server), now - 10))
        c._failed.append((('localhost', 1001, True), now - 10))

        self.assertRaises(
            aiohttp.ClientConnectionError,
            self.loop.run_until_complete,
            c.request('get', path='/'))
开发者ID:bmdru0503,项目名称:aiohttp,代码行数:23,代码来源:test_client.py


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