本文整理汇总了Python中aiohttp.client.HttpRequest.send方法的典型用法代码示例。如果您正苦于以下问题:Python HttpRequest.send方法的具体用法?Python HttpRequest.send怎么用?Python HttpRequest.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiohttp.client.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_chunked_length
# 需要导入模块: from aiohttp.client import HttpRequest [as 别名]
# 或者: from aiohttp.client.HttpRequest import send [as 别名]
def test_chunked_length(self):
req = HttpRequest(
'get', 'http://python.org/',
headers={'Content-Length': '1000'}, chunked=1024)
req.send(self.transport)
self.assertEqual(req.headers['Transfer-Encoding'], 'chunked')
self.assertNotIn('Content-Length', req.headers)
示例2: test_data_stream_exc
# 需要导入模块: from aiohttp.client import HttpRequest [as 别名]
# 或者: from aiohttp.client.HttpRequest import send [as 别名]
def test_data_stream_exc(self):
fut = asyncio.Future(loop=self.loop)
def gen():
yield b'binary data'
yield from fut
return b' result'
req = HttpRequest(
'POST', 'http://python.org/', data=gen(), loop=self.loop)
self.assertTrue(req.chunked)
self.assertTrue(inspect.isgenerator(req.body))
self.assertEqual(req.headers['transfer-encoding'], 'chunked')
@asyncio.coroutine
def exc():
yield from asyncio.sleep(0.01, loop=self.loop)
fut.set_exception(ValueError)
asyncio.async(exc(), loop=self.loop)
req.send(self.transport)
self.assertRaises(
ValueError, self.loop.run_until_complete, req._writer)
self.assertRaises(self.transport.close.called)
示例3: test_content_encoding
# 需要导入模块: from aiohttp.client import HttpRequest [as 别名]
# 或者: from aiohttp.client.HttpRequest import send [as 别名]
def test_content_encoding(self, m_http):
req = HttpRequest('get', 'http://python.org/', compress='deflate')
req.send(self.transport)
self.assertEqual(req.headers['Transfer-encoding'], 'chunked')
self.assertEqual(req.headers['Content-encoding'], 'deflate')
m_http.Request.return_value\
.add_compression_filter.assert_called_with('deflate')
示例4: test_chunked_explicit_size
# 需要导入模块: from aiohttp.client import HttpRequest [as 别名]
# 或者: from aiohttp.client.HttpRequest import send [as 别名]
def test_chunked_explicit_size(self, m_http):
req = HttpRequest(
'get', 'http://python.org/', chunked=1024)
req.send(self.transport)
self.assertEqual('chunked', req.headers['Transfer-encoding'])
m_http.Request.return_value\
.add_chunking_filter.assert_called_with(1024)
示例5: test_chunked_explicit
# 需要导入模块: from aiohttp.client import HttpRequest [as 别名]
# 或者: from aiohttp.client.HttpRequest import send [as 别名]
def test_chunked_explicit(self, m_http):
req = HttpRequest(
'get', 'http://python.org/', chunked=True, loop=self.loop)
req.send(self.transport, self.protocol)
self.assertEqual('chunked', req.headers['Transfer-encoding'])
m_http.Request.return_value\
.add_chunking_filter.assert_called_with(8196)
示例6: test_bytes_data
# 需要导入模块: from aiohttp.client import HttpRequest [as 别名]
# 或者: from aiohttp.client.HttpRequest import send [as 别名]
def test_bytes_data(self):
for meth in HttpRequest.POST_METHODS:
req = HttpRequest(meth, 'http://python.org/', data=b'binary data')
req.send(self.transport)
self.assertEqual('/', req.path)
self.assertEqual((b'binary data',), req.body)
self.assertEqual('application/octet-stream',
req.headers['content-type'])
示例7: test_post_data
# 需要导入模块: from aiohttp.client import HttpRequest [as 别名]
# 或者: from aiohttp.client.HttpRequest import send [as 别名]
def test_post_data(self):
for meth in HttpRequest.POST_METHODS:
req = HttpRequest(meth, 'http://python.org/', data={'life': '42'})
req.send(self.transport)
self.assertEqual('/', req.path)
self.assertEqual(b'life=42', req.body[0])
self.assertEqual('application/x-www-form-urlencoded',
req.headers['content-type'])
示例8: test_no_content_length
# 需要导入模块: from aiohttp.client import HttpRequest [as 别名]
# 或者: from aiohttp.client.HttpRequest import send [as 别名]
def test_no_content_length(self):
req = HttpRequest('get', 'http://python.org')
req.send(self.transport)
self.assertEqual('0', req.headers.get('Content-Length'))
req = HttpRequest('head', 'http://python.org')
req.send(self.transport)
self.assertEqual('0', req.headers.get('Content-Length'))
示例9: test_data_stream_not_bytes
# 需要导入模块: from aiohttp.client import HttpRequest [as 别名]
# 或者: from aiohttp.client.HttpRequest import send [as 别名]
def test_data_stream_not_bytes(self):
@asyncio.coroutine
def gen():
yield object()
return b' result'
req = HttpRequest(
'POST', 'http://python.org/', data=gen(), loop=self.loop)
req.send(self.transport)
self.assertRaises(
ValueError, self.loop.run_until_complete, req._writer)
示例10: test_data_stream_not_bytes
# 需要导入模块: from aiohttp.client import HttpRequest [as 别名]
# 或者: from aiohttp.client.HttpRequest import send [as 别名]
def test_data_stream_not_bytes(self):
@asyncio.coroutine
def gen():
yield object()
return b' result'
req = HttpRequest(
'POST', 'http://python.org/', data=gen(), loop=self.loop)
req.send(self.transport, self.protocol)
self.loop.run_until_complete(req._writer)
self.assertTrue(self.protocol.set_exception.called)
示例11: test_expect100
# 需要导入模块: from aiohttp.client import HttpRequest [as 别名]
# 或者: from aiohttp.client.HttpRequest import send [as 别名]
def test_expect100(self):
req = HttpRequest('get', 'http://python.org/',
expect100=True, loop=self.loop)
req.send(self.transport)
self.assertEqual('100-continue', req.headers['expect'])
self.assertIsNotNone(req._continue)
req = HttpRequest('get', 'http://python.org/',
headers={'expect': '100-continue'}, loop=self.loop)
req.send(self.transport)
self.assertEqual('100-continue', req.headers['expect'])
self.assertIsNotNone(req._continue)
示例12: test_chunked
# 需要导入模块: from aiohttp.client import HttpRequest [as 别名]
# 或者: from aiohttp.client.HttpRequest import send [as 别名]
def test_chunked(self):
req = HttpRequest(
'get', 'http://python.org/',
headers={'Transfer-encoding': 'gzip'})
req.send(self.transport)
self.assertEqual('gzip', req.headers['Transfer-encoding'])
req = HttpRequest(
'get', 'http://python.org/',
headers={'Transfer-encoding': 'chunked'})
req.send(self.transport)
self.assertEqual('chunked', req.headers['Transfer-encoding'])
示例13: test_content_encoding_header
# 需要导入模块: from aiohttp.client import HttpRequest [as 别名]
# 或者: from aiohttp.client.HttpRequest import send [as 别名]
def test_content_encoding_header(self, m_http):
req = HttpRequest(
'get', 'http://python.org/',
headers={'Content-Encoding': 'deflate'}, loop=self.loop)
req.send(self.transport, self.protocol)
self.assertEqual(req.headers['Transfer-encoding'], 'chunked')
self.assertEqual(req.headers['Content-encoding'], 'deflate')
m_http.Request.return_value\
.add_compression_filter.assert_called_with('deflate')
m_http.Request.return_value\
.add_chunking_filter.assert_called_with(8196)
示例14: test_close
# 需要导入模块: from aiohttp.client import HttpRequest [as 别名]
# 或者: from aiohttp.client.HttpRequest import send [as 别名]
def test_close(self):
@asyncio.coroutine
def gen():
yield from asyncio.sleep(0.00001, loop=self.loop)
return b'result'
req = HttpRequest(
'POST', 'http://python.org/', data=gen(), loop=self.loop)
req.send(self.transport)
self.loop.run_until_complete(req.close())
self.assertEqual(
self.transport.write.mock_calls[-3:],
[unittest.mock.call(b'result'),
unittest.mock.call(b'\r\n'),
unittest.mock.call(b'0\r\n\r\n')])
示例15: test_data_continue
# 需要导入模块: from aiohttp.client import HttpRequest [as 别名]
# 或者: from aiohttp.client.HttpRequest import send [as 别名]
def test_data_continue(self):
req = HttpRequest(
'POST', 'http://python.org/', data=b'data',
expect100=True, loop=self.loop)
def coro():
yield from asyncio.sleep(0.0001, loop=self.loop)
req._continue.set_result(1)
asyncio.async(coro(), loop=self.loop)
req.send(self.transport)
self.assertEqual(1, len(self.transport.write.mock_calls))
self.loop.run_until_complete(req._writer)
self.assertEqual(
self.transport.write.mock_calls[-1],
unittest.mock.call(b'data'))