本文整理汇总了Python中aiohttp.client.ClientResponse._get_encoding方法的典型用法代码示例。如果您正苦于以下问题:Python ClientResponse._get_encoding方法的具体用法?Python ClientResponse._get_encoding怎么用?Python ClientResponse._get_encoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiohttp.client.ClientResponse
的用法示例。
在下文中一共展示了ClientResponse._get_encoding方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ClientResponseTests
# 需要导入模块: from aiohttp.client import ClientResponse [as 别名]
# 或者: from aiohttp.client.ClientResponse import _get_encoding [as 别名]
#.........这里部分代码省略.........
self.response.json.return_value = asyncio.Future(loop=self.loop)
self.response.json.return_value.set_result('json')
with self.assertWarns(DeprecationWarning):
res = self.loop.run_until_complete(self.response.read(decode=True))
self.assertEqual(res, 'json')
self.assertTrue(self.response.json.called)
def test_text(self):
def side_effect(*args, **kwargs):
fut = asyncio.Future(loop=self.loop)
fut.set_result('{"тест": "пройден"}'.encode('cp1251'))
return fut
self.response.headers = {
'CONTENT-TYPE': 'application/json;charset=cp1251'}
content = self.response.content = unittest.mock.Mock()
content.read.side_effect = side_effect
self.response.close = unittest.mock.Mock()
res = self.loop.run_until_complete(self.response.text())
self.assertEqual(res, '{"тест": "пройден"}')
self.assertTrue(self.response.close.called)
def test_text_custom_encoding(self):
def side_effect(*args, **kwargs):
fut = asyncio.Future(loop=self.loop)
fut.set_result('{"тест": "пройден"}'.encode('cp1251'))
return fut
self.response.headers = {
'CONTENT-TYPE': 'application/json'}
content = self.response.content = unittest.mock.Mock()
content.read.side_effect = side_effect
self.response.close = unittest.mock.Mock()
self.response._get_encoding = unittest.mock.Mock()
res = self.loop.run_until_complete(
self.response.text(encoding='cp1251'))
self.assertEqual(res, '{"тест": "пройден"}')
self.assertTrue(self.response.close.called)
self.assertFalse(self.response._get_encoding.called)
def test_text_detect_encoding(self):
def side_effect(*args, **kwargs):
fut = asyncio.Future(loop=self.loop)
fut.set_result('{"тест": "пройден"}'.encode('cp1251'))
return fut
self.response.headers = {'CONTENT-TYPE': 'application/json'}
content = self.response.content = unittest.mock.Mock()
content.read.side_effect = side_effect
self.response.close = unittest.mock.Mock()
res = self.loop.run_until_complete(self.response.text())
self.assertEqual(res, '{"тест": "пройден"}')
self.assertTrue(self.response.close.called)
def test_json(self):
def side_effect(*args, **kwargs):
fut = asyncio.Future(loop=self.loop)
fut.set_result('{"тест": "пройден"}'.encode('cp1251'))
return fut
self.response.headers = {
'CONTENT-TYPE': 'application/json;charset=cp1251'}
content = self.response.content = unittest.mock.Mock()
content.read.side_effect = side_effect
self.response.close = unittest.mock.Mock()