Skip to content

Commit

Permalink
Tweaked for supporting jsonrpclib v.0.11 and added a few reporting tw…
Browse files Browse the repository at this point in the history
…eaks.

git-svn-id: http://tornadorpc.googlecode.com/svn/trunk@6 6a0cc88c-bc38-11de-9a73-11f8458f6c97
  • Loading branch information
catchjosh committed Nov 2, 2009
1 parent de5ad47 commit ab8a67e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 17 additions & 4 deletions tornadorpc/base.py
Expand Up @@ -67,11 +67,24 @@ def run(self, handler, request_body):
to the client.
"""
self.handler = handler
requests = self.parse_request(request_body)
try:
requests = self.parse_request(request_body)
except:
self.traceback()
return self.faults.parse_error()
if type(requests) is not types.TupleType:
# SHOULD be the result of a fault call,
# according tothe parse_request spec below.
return requests
if type(requests) in types.StringTypes:
# Should be the response text of a fault
return requests
elif 'response' in dir(requests):
# Fault types should have a 'response' method
return requests.response()
else:
# No idea, hopefully the handler knows what it
# is doing.
return requests
responses = []
for request in requests:
response = self.dispatch(request[0], request[1])
Expand Down Expand Up @@ -136,7 +149,7 @@ def dispatch(self, method_name, params):
# Bad argument formatting?
return self.faults.invalid_params()

def traceback(self, method_name, params):
def traceback(self, method_name='REQUEST', params=[]):
import traceback
err_lines = traceback.format_exc().splitlines()
err_title = "ERROR IN %s" % method_name
Expand All @@ -155,7 +168,7 @@ def traceback(self, method_name, params):
# Log here
return

def parse_requesr(self, request_body):
def parse_request(self, request_body):
"""
Extend this on the implementing protocol. If it
should error out, return the output of the
Expand Down
3 changes: 2 additions & 1 deletion tornadorpc/json.py
Expand Up @@ -52,6 +52,7 @@ def parse_request(self, request_body):
request = jsonrpclib.loads(request_body)
except:
# Bad request formatting. Bad.
self.traceback()
return self.faults.parse_error()
self._requests = request
self._batch = False
Expand Down Expand Up @@ -80,7 +81,7 @@ def parse_responses(self, responses):
# response entry
continue
rpcid = request['id']
version = jsonrpclib._version
version = jsonrpclib.config.version
if 'jsonrpc' not in request.keys():
version = 1.0
try:
Expand Down

0 comments on commit ab8a67e

Please sign in to comment.