List Info

Thread: server-to-client message? and a small patch.




server-to-client message? and a small patch.
country flaguser name
United States
2007-05-30 18:25:47

Hi

I'm interested in the feature of server-to-client messages, specified
on the spec, but I can't find it's implementation on the python code,
is anyone working on it? if not I'll like to code it but I'll need
some guideline since I'm not sure how the blocking will be handle.

Also I have been playing around with the code and I think the
following patch is an improvement, the only part I'm not entirely sure
about is the empty string test as I think it's not a valid json
encoded object. I think this is too simple to open a ticket but if you
want to just let me know.

Index: _tests/test_json.py
===================================================================
--- _tests/test_json.py (revision 16)
+;++ _tests/test_json.py (working copy)
-87,6 +87,14
json = jsonrpc.dumps({'foobar':'spam', 'a':[1,2,3]})
self.assertJSON(json, u'{"a":[1,2,3],"foobar";:"spam"}')

+ def test_EmptyDictionary(self):
+ json = jsonrpc.dumps({})
+ self.assertJSON(json,u'{}')
+
+ def test_EmptyString(self):
+ json = jsonrpc.dumps('')
+ self.assertJSON(json,u'')
+
def test_FailOther(self):
self.failUnlessRaises(jsonrpc.JSONEncodeException,
lambda:jsonrpc.dumps(self))

Index: serviceHandler.py
===================================================================
--- serviceHandler.py (revision 16)
+;++ serviceHandler.py (working copy)
-55,23 +55,17
err = e
req={'id':id_}

- if err==None:
+ if not err:
try:
id_ = req['id']
methName = req['method']
args = req['params']
- except:
- err = BadServiceRequest(json)
-
- if err == None:
- try:
meth = self.findServiceEndpoint(methName)
- except Exception, e:
- err = e
-
- if err == None:
- try:
result = self.invokeServiceEndpoint(meth, args)
+ except KeyError:
+ err = BadServiceRequest(json)
+ except ServiceMethodNotFound, e:#this could also be deleted
+ err = e
except Exception, e:
err = e

-110,4 +104,5
err = {"name": "JSONEncodeException", "message":"Result
Object Not Serializable"}
data = dumps({"result":None, "id":id_,"error":err})

- return data
No newline at end of file
+ return data
+
Index: proxy.py
===================================================================
--- proxy.py (revision 16)
+;++ proxy.py (working copy)
-20,12 +20,14
"""

import urllib
-from jsonrpc.json import dumps, loads
+from jsonrpc.json import dumps, loads, JSONDecodeException

class JSONRPCException(Exception):
def __init__(self, rpcError):
Exception.__init__(self)
self.error = rpcError
+ def __str__(self):
+ return self.error

class ServiceProxy(object):
def __init__(self, serviceURL, serviceName=None):
-38,12 +40,14
return ServiceProxy(self.__serviceURL, name)

def __call__(self, *args):
- postdata = dumps({"method": self.__serviceName, 'params':
args, 'id':'jsonrpc'})
+ postdata = dumps({"method": self.__serviceName, 'params':
args, 'id':'jsonrpc'})
respdata = urllib.urlopen(self.__serviceURL, postdata).read()
- resp = loads(respdata)
+ try:
+ resp = loads(respdata)
+ except JSONDecodeException,e:
+ raise JSONRPCException(respdata)
+
if resp['error'] != None:
raise JSONRPCException(resp['error'])
else:
return resp['result']
-
-

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )