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


Python client.HttpRequest类代码示例

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


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

示例1: test_data_stream_exc

    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)
开发者ID:adevore,项目名称:aiohttp,代码行数:25,代码来源:http_client_test.py

示例2: test_chunked_length

 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)
开发者ID:adevore,项目名称:aiohttp,代码行数:7,代码来源:http_client_test.py

示例3: test_content_encoding

 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')
开发者ID:adevore,项目名称:aiohttp,代码行数:7,代码来源:http_client_test.py

示例4: test_chunked_explicit_size

 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)
开发者ID:adevore,项目名称:aiohttp,代码行数:7,代码来源:http_client_test.py

示例5: test_chunked_explicit

    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)
开发者ID:atwong,项目名称:aiohttp,代码行数:8,代码来源:test_client.py

示例6: test_bytes_data

 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'])
开发者ID:adevore,项目名称:aiohttp,代码行数:8,代码来源:http_client_test.py

示例7: test_post_data

 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'])
开发者ID:adevore,项目名称:aiohttp,代码行数:8,代码来源:http_client_test.py

示例8: test_data_stream_not_bytes

    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)
开发者ID:adevore,项目名称:aiohttp,代码行数:11,代码来源:http_client_test.py

示例9: test_data_stream_not_bytes

    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)
开发者ID:atwong,项目名称:aiohttp,代码行数:11,代码来源:test_client.py

示例10: test_content_encoding_header

    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)
开发者ID:atwong,项目名称:aiohttp,代码行数:12,代码来源:test_client.py

示例11: test_close

    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')])
开发者ID:adevore,项目名称:aiohttp,代码行数:15,代码来源:http_client_test.py

示例12: test_data_continue

    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'))
开发者ID:adevore,项目名称:aiohttp,代码行数:18,代码来源:http_client_test.py

示例13: test_data_stream

    def test_data_stream(self):
        def gen():
            yield b'binary data'
            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')

        resp = req.send(self.transport)
        self.assertIsInstance(req._writer, asyncio.Future)
        self.loop.run_until_complete(resp.wait_for_close())
        self.assertIsNone(req._writer)
        self.assertEqual(
            self.transport.write.mock_calls[-3:],
            [unittest.mock.call(b'binary data result'),
             unittest.mock.call(b'\r\n'),
             unittest.mock.call(b'0\r\n\r\n')])
开发者ID:adevore,项目名称:aiohttp,代码行数:20,代码来源:http_client_test.py

示例14: test_no_content_length

    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'))
开发者ID:adevore,项目名称:aiohttp,代码行数:8,代码来源:http_client_test.py

示例15: test_data_stream_continue

    def test_data_stream_continue(self):
        def gen():
            yield b'binary data'
            return b' result'

        req = HttpRequest(
            'POST', 'http://python.org/', data=gen(),
            expect100=True, loop=self.loop)
        self.assertTrue(req.chunked)
        self.assertTrue(inspect.isgenerator(req.body))

        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.loop.run_until_complete(req._writer)
        self.assertEqual(
            self.transport.write.mock_calls[-3:],
            [unittest.mock.call(b'binary data result'),
             unittest.mock.call(b'\r\n'),
             unittest.mock.call(b'0\r\n\r\n')])
开发者ID:adevore,项目名称:aiohttp,代码行数:24,代码来源:http_client_test.py


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