本文整理汇总了Python中jsonrpclib.Server._run_request方法的典型用法代码示例。如果您正苦于以下问题:Python Server._run_request方法的具体用法?Python Server._run_request怎么用?Python Server._run_request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jsonrpclib.Server
的用法示例。
在下文中一共展示了Server._run_request方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCompatibility
# 需要导入模块: from jsonrpclib import Server [as 别名]
# 或者: from jsonrpclib.Server import _run_request [as 别名]
#.........这里部分代码省略.........
def test_notification(self):
""" Testing a notification (response should be null) """
result = self.client._notify.update(1, 2, 3, 4, 5)
self.assertTrue(result == None)
request = json.loads(self.history.request)
response = self.history.response
verify_request = {
"jsonrpc": "2.0", "method": "update", "params": [1, 2, 3, 4, 5]
}
verify_response = ''
self.assertTrue(request == verify_request)
self.assertTrue(response == verify_response)
def test_non_existent_method(self):
self.assertRaises(ProtocolError, self.client.foobar)
request = json.loads(self.history.request)
response = json.loads(self.history.response)
verify_request = {
"jsonrpc": "2.0", "method": "foobar", "id": request['id']
}
verify_response = {
"jsonrpc": "2.0",
"error":
{"code":-32601, "message": response['error']['message']},
"id": request['id']
}
self.assertTrue(request == verify_request)
self.assertTrue(response == verify_response)
def test_invalid_json(self):
invalid_json = '{"jsonrpc": "2.0", "method": "foobar, ' + \
'"params": "bar", "baz]'
self.client._run_request(invalid_json)
response = json.loads(self.history.response)
verify_response = json.loads(
'{"jsonrpc": "2.0", "error": {"code": -32700,' +
' "message": "Parse error."}, "id": null}'
)
verify_response['error']['message'] = response['error']['message']
self.assertTrue(response == verify_response)
def test_invalid_request(self):
invalid_request = '{"jsonrpc": "2.0", "method": 1, "params": "bar"}'
self.client._run_request(invalid_request)
response = json.loads(self.history.response)
verify_response = json.loads(
'{"jsonrpc": "2.0", "error": {"code": -32600, ' +
'"message": "Invalid Request."}, "id": null}'
)
verify_response['error']['message'] = response['error']['message']
self.assertTrue(response == verify_response)
def test_batch_invalid_json(self):
invalid_request = '[ {"jsonrpc": "2.0", "method": "sum", ' + \
'"params": [1,2,4], "id": "1"},{"jsonrpc": "2.0", "method" ]'
self.client._run_request(invalid_request)
response = json.loads(self.history.response)
verify_response = json.loads(
'{"jsonrpc": "2.0", "error": {"code": -32700,' +
'"message": "Parse error."}, "id": null}'
)
verify_response['error']['message'] = response['error']['message']
self.assertTrue(response == verify_response)
def test_empty_array(self):