本文整理汇总了Python中aiohttp.client.ClientSession._prepare_headers方法的典型用法代码示例。如果您正苦于以下问题:Python ClientSession._prepare_headers方法的具体用法?Python ClientSession._prepare_headers怎么用?Python ClientSession._prepare_headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aiohttp.client.ClientSession
的用法示例。
在下文中一共展示了ClientSession._prepare_headers方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_merge_headers_with_multi_dict
# 需要导入模块: from aiohttp.client import ClientSession [as 别名]
# 或者: from aiohttp.client.ClientSession import _prepare_headers [as 别名]
def test_merge_headers_with_multi_dict(self):
session = ClientSession(
headers={
"h1": "header1",
"h2": "header2"
}, loop=self.loop)
headers = session._prepare_headers(MultiDict([("h1", "h1")]))
self.assertIsInstance(headers, CIMultiDict)
self.assertEqual(headers, CIMultiDict([
("h1", "h1"),
("h2", "header2")
]))
示例2: test_merge_headers
# 需要导入模块: from aiohttp.client import ClientSession [as 别名]
# 或者: from aiohttp.client.ClientSession import _prepare_headers [as 别名]
def test_merge_headers(self):
# Check incoming simple dict
session = ClientSession(
headers={
"h1": "header1",
"h2": "header2"
}, loop=self.loop)
headers = session._prepare_headers({
"h1": "h1"
})
self.assertIsInstance(headers, CIMultiDict)
self.assertEqual(headers, CIMultiDict([
("h1", "h1"),
("h2", "header2")
]))
# Check incoming multi dict
session = ClientSession(
headers={
"h1": "header1",
"h2": "header2"
}, loop=self.loop)
headers = session._prepare_headers(MultiDict([("h1", "h1")]))
self.assertIsInstance(headers, CIMultiDict)
self.assertEqual(headers, CIMultiDict([
("h1", "h1"),
("h2", "header2")
]))
# Check incoming list of tuples
session = ClientSession(
headers={
"h1": "header1",
"h2": "header2"
}, loop=self.loop)
headers = session._prepare_headers([("h1", "h1")])
self.assertIsInstance(headers, CIMultiDict)
self.assertEqual(headers, CIMultiDict([
("h1", "h1"),
("h2", "header2")
]))
示例3: test_merge_headers_with_list_of_tuples_duplicated_names
# 需要导入模块: from aiohttp.client import ClientSession [as 别名]
# 或者: from aiohttp.client.ClientSession import _prepare_headers [as 别名]
def test_merge_headers_with_list_of_tuples_duplicated_names(self):
session = ClientSession(
headers={
"h1": "header1",
"h2": "header2"
}, loop=self.loop)
headers = session._prepare_headers([("h1", "v1"),
("h1", "v2")])
self.assertIsInstance(headers, CIMultiDict)
self.assertEqual(headers, CIMultiDict([
("H2", "header2"),
("H1", "v1"),
("H1", "v2"),
]))
session.close()