本文整理汇总了Python中jsonrpclib.Server._additional_headers方法的典型用法代码示例。如果您正苦于以下问题:Python Server._additional_headers方法的具体用法?Python Server._additional_headers怎么用?Python Server._additional_headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonrpclib.Server
的用法示例。
在下文中一共展示了Server._additional_headers方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_should_override_global_headers
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import _additional_headers [as 别名]
def test_should_override_global_headers(self):
# given
client = Server('http://localhost:{0}'.format(self.port), verbose=1,
headers={'X-Test' : 'Global'})
# when
with self.captured_headers() as headers:
with client._additional_headers({'X-Test' : 'Method'}) as cl:
response = cl.ping()
self.assertTrue(response)
# then
self.assertTrue('x-test' in headers)
self.assertEqual(headers['x-test'], 'Method')
示例2: test_should_add_custom_headers_to_methods
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import _additional_headers [as 别名]
def test_should_add_custom_headers_to_methods(self):
# given
client = Server('http://localhost:{0}'.format(self.port), verbose=1)
# when
with self.captured_headers() as headers:
with client._additional_headers({'X-Method' : 'Method'}) as cl:
response = cl.ping()
self.assertTrue(response)
# then
self.assertTrue('x-method' in headers)
self.assertEqual(headers['x-method'], 'Method')
示例3: test_should_allow_to_nest_additional_header_blocks
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import _additional_headers [as 别名]
def test_should_allow_to_nest_additional_header_blocks(self):
# given
client = Server('http://localhost:%d' % self.port, verbose=1)
# when
with client._additional_headers({'X-Level-1' : '1'}) as cl_level1:
with self.captured_headers() as headers1:
response = cl_level1.ping()
self.assertTrue(response)
with cl_level1._additional_headers({'X-Level-2' : '2'}) as cl:
with self.captured_headers() as headers2:
response = cl.ping()
self.assertTrue(response)
# then
self.assertTrue('x-level-1' in headers1)
self.assertEqual(headers1['x-level-1'], '1')
self.assertTrue('x-level-1' in headers2)
self.assertEqual(headers1['x-level-1'], '1')
self.assertTrue('x-level-2' in headers2)
self.assertEqual(headers2['x-level-2'], '2')