Skip to content

Commit

Permalink
Updated JSONRPC to conform JSON-RPC 1.0/1.1/2.0 and to return
Browse files Browse the repository at this point in the history
JSON-RPC 2.0 error dicts in onRemeoteError (other errors are
mapped to JSON-RPC 2.0 format)

git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@2330 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information
keesbos committed Nov 30, 2009
1 parent dd4d656 commit 00678d5
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 159 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
@@ -1,6 +1,10 @@
Changes made to Pyjamas since 0.6
---------------------------------

* Updated JSONRPC to conform JSON-RPC 1.0/1.1/2.0 and to return
JSON-RPC 2.0 error dicts ini onRemeoteError (other errors are
mapped to JSON-RPC 2.0 format)

* Enhanced dict initialization: dict(a=1, b=2)

* Added setFocus function to TextBoxBase to override FocusMixin.setFocus
Expand Down
35 changes: 27 additions & 8 deletions examples/jsonrpc/JSONRPCExample.py
Expand Up @@ -18,7 +18,10 @@ def onModuleLoad(self):
self.METHOD_REVERSE = "Reverse"
self.METHOD_UPPERCASE = "UPPERCASE"
self.METHOD_LOWERCASE = "lowercase"
self.methods = [self.METHOD_ECHO, self.METHOD_REVERSE, self.METHOD_UPPERCASE, self.METHOD_LOWERCASE]
self.METHOD_NONEXISTANT = "Non existant"
self.methods = [self.METHOD_ECHO, self.METHOD_REVERSE,
self.METHOD_UPPERCASE, self.METHOD_LOWERCASE,
self.METHOD_NONEXISTANT]

self.remote_php = EchoServicePHP()
self.remote_py = EchoServicePython()
Expand Down Expand Up @@ -87,6 +90,8 @@ def onClick(self, sender):
id = self.remote_php.uppercase(text, self)
elif method == self.METHOD_LOWERCASE:
id = self.remote_php.lowercase(text, self)
elif method == self.METHOD_NONEXISTANT:
id = self.remote_php.nonexistant(text, self)
else:
if method == self.METHOD_ECHO:
id = self.remote_py.echo(text, self)
Expand All @@ -96,25 +101,39 @@ def onClick(self, sender):
id = self.remote_py.uppercase(text, self)
elif method == self.METHOD_LOWERCASE:
id = self.remote_py.lowercase(text, self)
if id<0:
self.status.setText(self.TEXT_ERROR)
elif method == self.METHOD_NONEXISTANT:
id = self.remote_py.nonexistant(text, self)

def onRemoteResponse(self, response, request_info):
self.status.setText(response)

def onRemoteError(self, code, message, request_info):
self.status.setText("Server Error or Invalid Response: ERROR %d - %s" %
(code, message))
def onRemoteError(self, code, errobj, request_info):
# onRemoteError gets the HTTP error code or 0 and
# errobj is an jsonrpc 2.0 error dict:
# {
# 'jsonrpc': "2.0",
# 'code': jsonrpc-error-code (integer) ,
# 'message': jsonrpc-error-message (string) ,
# 'data' : extra-error-data
# }
message = errobj['message']
if code != 0:
self.status.setText("HTTP error %d: %s" %
(code, message))
else:
code = errobj['code']
self.status.setText("JSONRPC Error %s: %s" %
(code, message))


class EchoServicePHP(JSONProxy):
def __init__(self):
JSONProxy.__init__(self, "services/EchoService.php", ["echo", "reverse", "uppercase", "lowercase"])
JSONProxy.__init__(self, "services/EchoService.php", ["echo", "reverse", "uppercase", "lowercase", "nonexistant"])


class EchoServicePython(JSONProxy):
def __init__(self):
JSONProxy.__init__(self, "services/EchoService.py", ["echo", "reverse", "uppercase", "lowercase"])
JSONProxy.__init__(self, "services/EchoService.py", ["echo", "reverse", "uppercase", "lowercase", "nonexistant"])

if __name__ == '__main__':
# for pyjd, set up a web server and load the HTML from there:
Expand Down
103 changes: 0 additions & 103 deletions library/__browser__/pyjamas/JSONService.py

This file was deleted.

0 comments on commit 00678d5

Please sign in to comment.