本文整理汇总了Python中aiohttp.client.ClientResponse._loop方法的典型用法代码示例。如果您正苦于以下问题:Python ClientResponse._loop方法的具体用法?Python ClientResponse._loop怎么用?Python ClientResponse._loop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiohttp.client.ClientResponse
的用法示例。
在下文中一共展示了ClientResponse._loop方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_https_connect
# 需要导入模块: from aiohttp.client import ClientResponse [as 别名]
# 或者: from aiohttp.client.ClientResponse import _loop [as 别名]
def test_https_connect(self, ClientRequestMock):
loop_mock = unittest.mock.Mock()
proxy_req = ClientRequest('GET', 'http://proxy.example.com',
loop=loop_mock)
ClientRequestMock.return_value = proxy_req
proxy_resp = ClientResponse('get', 'http://proxy.example.com')
proxy_resp._loop = loop_mock
proxy_req.send = send_mock = unittest.mock.Mock()
send_mock.return_value = proxy_resp
proxy_resp.start = start_mock = unittest.mock.Mock()
self._fake_coroutine(start_mock, unittest.mock.Mock(status=200))
connector = aiohttp.ProxyConnector(
'http://proxy.example.com', loop=loop_mock)
tr, proto = unittest.mock.Mock(), unittest.mock.Mock()
self._fake_coroutine(loop_mock.create_connection, (tr, proto))
req = ClientRequest('GET', 'https://www.python.org', loop=self.loop)
self.loop.run_until_complete(connector._create_connection(req))
self.assertEqual(req.path, '/')
self.assertEqual(proxy_req.method, 'CONNECT')
self.assertEqual(proxy_req.path, 'www.python.org:443')
tr.pause_reading.assert_called_once_with()
tr.get_extra_info.assert_called_with('socket', default=None)
proxy_req.close()
proxy_resp.close()
req.close()
示例2: test_https_connect_runtime_error
# 需要导入模块: from aiohttp.client import ClientResponse [as 别名]
# 或者: from aiohttp.client.ClientResponse import _loop [as 别名]
def test_https_connect_runtime_error(self, ClientRequestMock):
loop_mock = unittest.mock.Mock()
proxy_req = ClientRequest('GET', 'http://proxy.example.com',
loop=loop_mock)
ClientRequestMock.return_value = proxy_req
proxy_resp = ClientResponse('get', 'http://proxy.example.com')
proxy_resp._loop = loop_mock
proxy_req.send = send_mock = unittest.mock.Mock()
send_mock.return_value = proxy_resp
proxy_resp.start = start_mock = unittest.mock.Mock()
self._fake_coroutine(start_mock, unittest.mock.Mock(status=200))
connector = aiohttp.ProxyConnector(
'http://proxy.example.com', loop=loop_mock)
tr, proto = unittest.mock.Mock(), unittest.mock.Mock()
tr.get_extra_info.return_value = None
self._fake_coroutine(loop_mock.create_connection, (tr, proto))
req = ClientRequest('GET', 'https://www.python.org', loop=self.loop)
with self.assertRaisesRegex(
RuntimeError, "Transport does not expose socket instance"):
self.loop.run_until_complete(connector._create_connection(req))
proxy_req.close()
proxy_resp.close()
req.close()
示例3: test_https_connect_http_proxy_error
# 需要导入模块: from aiohttp.client import ClientResponse [as 别名]
# 或者: from aiohttp.client.ClientResponse import _loop [as 别名]
def test_https_connect_http_proxy_error(self, ClientRequestMock):
loop_mock = unittest.mock.Mock()
proxy_req = ClientRequest('GET', 'http://proxy.example.com',
loop=loop_mock)
ClientRequestMock.return_value = proxy_req
proxy_resp = ClientResponse('get', 'http://proxy.example.com')
proxy_resp._loop = loop_mock
proxy_req.send = send_mock = unittest.mock.Mock()
send_mock.return_value = proxy_resp
proxy_resp.start = start_mock = unittest.mock.Mock()
self._fake_coroutine(
start_mock, unittest.mock.Mock(status=400, reason='bad request'))
connector = aiohttp.ProxyConnector(
'http://proxy.example.com', loop=loop_mock)
tr, proto = unittest.mock.Mock(), unittest.mock.Mock()
tr.get_extra_info.return_value = None
self._fake_coroutine(loop_mock.create_connection, (tr, proto))
req = ClientRequest('GET', 'https://www.python.org', loop=self.loop)
with self.assertRaisesRegex(
aiohttp.HttpProxyError, "400, message='bad request'"):
self.loop.run_until_complete(connector._create_connection(req))
proxy_req.close()
proxy_resp.close()
req.close()