[REM] conditional test, set json-rpc response result directly from method call instead of going through an intermediate variable

bzr revid: xmo@openerp.com-20110711114827-od8se08z08qentmm
This commit is contained in:
Xavier Morel 2011-07-11 13:48:27 +02:00
parent 76111033ef
commit 6d1263a97a
1 changed files with 5 additions and 6 deletions

View File

@ -280,7 +280,7 @@ class JsonRequest(object):
return self.params return self.params
def dispatch(self, controller, method, requestf=None, request=None): def dispatch(self, controller, method, requestf=None, request=None):
''' Calls the method asked for by the JSON-RPC2 request """ Calls the method asked for by the JSON-RPC2 request
:param controller: the instance of the controller which received the request :param controller: the instance of the controller which received the request
:type controller: type :type controller: type
@ -293,17 +293,19 @@ class JsonRequest(object):
:returns: a string-encoded JSON-RPC2 reply :returns: a string-encoded JSON-RPC2 reply
:rtype: bytes :rtype: bytes
''' """
# Read POST content or POST Form Data named "request" # Read POST content or POST Form Data named "request"
if requestf: if requestf:
request = simplejson.load(requestf, object_hook=nonliterals.non_literal_decoder) request = simplejson.load(requestf, object_hook=nonliterals.non_literal_decoder)
else: else:
request = simplejson.loads(request, object_hook=nonliterals.non_literal_decoder) request = simplejson.loads(request, object_hook=nonliterals.non_literal_decoder)
response = {"jsonrpc": "2.0", "id": request.get('id')}
try: try:
print "--> %s.%s %s" % (controller.__class__.__name__, method.__name__, request) print "--> %s.%s %s" % (controller.__class__.__name__, method.__name__, request)
error = None error = None
self.parse(request) self.parse(request)
result = method(controller, self, **self.params) response["result"] = method(controller, self, **self.params)
except OpenERPUnboundException: except OpenERPUnboundException:
error = { error = {
'code': 100, 'code': 100,
@ -335,11 +337,8 @@ class JsonRequest(object):
'debug': "Client %s" % traceback.format_exc() 'debug': "Client %s" % traceback.format_exc()
} }
} }
response = {"jsonrpc": "2.0", "id": request.get('id')}
if error: if error:
response["error"] = error response["error"] = error
else:
response["result"] = result
print "<--", response print "<--", response
print print