Changes between Version 5 and Version 6 of Simplistic_json_rpc-dispatcher
- Timestamp:
- Nov 24, 2009, 4:37:53 PM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Simplistic_json_rpc-dispatcher
v5 v6 4 4 ### myproj/myapp/views.py 5 5 6 import sets7 import jsonrpc8 6 7 import json 9 8 10 def JSON_RPC_io(object): 11 methods = set(['<method1>', '<method2>', '<method3>', ....]) # Set of available service method names 12 rpc_inputs = jsonrpc.json.loads(object.raw_post_data) 9 jsonrpc_methods = [] 10 11 def JSON_RPC_io(obj): 12 rpc_inputs = json.loads(obj.raw_post_data) 13 13 sub_eval = str(rpc_inputs['method']) + '(rpc_inputs[\'params\'])' 14 if rpc_inputs['method'] in methods:14 if rpc_inputs['method'] in jsonrpc_methods: 15 15 result = eval(sub_eval) 16 json_retur = json rpc.json.dumps({'result': result['result'], 'error': result['error'], 'id': rpc_inputs['id']})16 json_retur = json.dumps({'result': result['result'], 'error': result['error'], 'id': rpc_inputs['id']}) 17 17 response = HttpResponse(json_retur) 18 18 response.__setitem__('Content-Type', 'application/json-rpc') 19 19 return response 20 20 else: 21 json_retur = json rpc.json.dumps({'result': None, 'error': '<non_existent_method_mesg>', 'id': rpc_inputs['id']})21 json_retur = json.dumps({'result': None, 'error': '<non_existent_method_mesg>', 'id': rpc_inputs['id']}) 22 22 response = HttpResponse(json_retur) 23 23 response.__setitem__('Content-Type', 'application/json-rpc') … … 29 29 This function works as a decoding/encoding dispatcher between Django's '''HttpRequest'''-object and 30 30 arbitrary defined method-functions of the json-rpc service. Those '''method-functions shall return''' a 31 dictionary-object as '''{'result': <result_data>, 'error': <error_data>}''' . This dispatcher-function 32 is suitable for non-public json-rpc apps handling specific data process/validate tasks. 31 dictionary-object as '''{'result': <result_data>, 'error': <error_data>}''' and their '''names shall be appended/registered''' to the '''jsonrpc_methods list'''. This dispatcher-function is generally suitable for json-rpc apps handling different data process/validate tasks.