← Back to team overview

ladon-dev-team team mailing list archive

[Merge] lp:~roger-lp/ladon/trunk into lp:ladon

 

roger has proposed merging lp:~roger-lp/ladon/trunk into lp:ladon.

Requested reviews:
  Ladon Developer (ladon-dev-team)
Related bugs:
  Bug #1071807 in ladon: "jsonrpc10 only supports positional arguments"
  https://bugs.launchpad.net/ladon/+bug/1071807

For more details, see:
https://code.launchpad.net/~roger-lp/ladon/trunk/+merge/132114

Bug #1071807 was fixed.
-- 
https://code.launchpad.net/~roger-lp/ladon/trunk/+merge/132114
Your team Ladon Developer is requested to review the proposed merge of lp:~roger-lp/ladon/trunk into lp:ladon.
=== modified file 'frameworks/python/src/ladon/interfaces/jsonrpc10.py'
--- frameworks/python/src/ladon/interfaces/jsonrpc10.py	2012-10-26 11:28:06 +0000
+++ frameworks/python/src/ladon/interfaces/jsonrpc10.py	2012-10-30 14:27:22 +0000
@@ -30,6 +30,26 @@
 
 	def __str__(self):
 		return self.faultstring
+	
+class MethodArgsCountFault(ServiceFault):
+	def __init__(self,methodname,targsscount,gargscount,passback_dict):
+		self.methodname = methodname
+		self.targsscount = targsscount
+		self.gargscount = gargscount
+		self.passback_dict = passback_dict
+		super(MethodArgsCountFault,self).__init__('service','Method "%s" takes exactly %s arguments, %s given.' % \
+			(self.methodname,self.targsscount,self.gargscount), None, 2)
+
+	def __str__(self):
+		return self.faultstring
+	
+class RequestParamsArrayFault(ServiceFault):
+	def __init__(self,passback_dict):
+		self.passback_dict = passback_dict
+		super(RequestParamsArrayFault,self).__init__('service','Params must be array of objects.',None,2)
+
+	def __str__(self):
+		return self.faultstring
 
 class JSONRPCServiceDescriptor(ServiceDescriptor):	
 	javascript_type_map = type_to_jsontype
@@ -120,17 +140,21 @@
 		if 'id' not in req_dict:
 			raise RequestPropFault('id',passback_dict)
 		minfo = sinfo.methods[req_dict['method']]
-		if (req_dict['params'] is None or len(req_dict['params']) == 0) and len(minfo.args()) > 0:
+		params = req_dict['params']
+		if params is not None and type(params) is not list:
+			raise RequestParamsArrayFault(passback_dict)
+		params_len = len(params) if params is not None else 0
+		args_len = len(minfo.args())
+		if params_len == 0 and  args_len> 0:
 			raise RequestParamFault(minfo.args()[0]['name'],passback_dict)
-		else:
-			for arg in minfo.args():
-				isgiven = False
-				for param in req_dict['params']:
-					if param == arg['name']:
-						isgiven = True
-				if not isgiven:
-					raise RequestParamFault(arg['name'],passback_dict)
-		req_dict['args'] = req_dict['params']
+		elif params_len < args_len:
+			raise RequestParamFault(minfo.args()[params_len]['name'],passback_dict)
+		elif params_len > args_len:
+			raise MethodArgsCountFault(req_dict['method'], args_len, params_len,passback_dict)
+		req_dict['args'] = {}
+		if params is not None:
+			for i in range(len(params)):
+				req_dict['args'][minfo.args()[i]['name']] = params[i]
 		req_dict['methodname'] = req_dict['method']
 		del req_dict['params']
 		del req_dict['method']

=== modified file 'frameworks/python/tests/testjsonrpc10.py'
--- frameworks/python/tests/testjsonrpc10.py	2012-10-23 12:25:57 +0000
+++ frameworks/python/tests/testjsonrpc10.py	2012-10-30 14:27:22 +0000
@@ -79,7 +79,7 @@
 		
 	def test_passback_string(self):
 		val = 'Yo!!!'
-		req = {'method':'passback_string','params':{'arg':val},'id':0}
+		req = {'method':'passback_string','params':[val],'id':0}
 		jreq = json.dumps(req)
 		
 		status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -91,7 +91,7 @@
 		
 	def test_passback_int(self):
 		val = 11
-		req = {'method':'passback_int','params':{'arg':val},'id':0}
+		req = {'method':'passback_int','params':[val],'id':0}
 		jreq = json.dumps(req)
 		
 		status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -103,7 +103,7 @@
 	
 	def test_passback_float(self):
 		val = 11.11
-		req = {'method':'passback_float','params':{'arg':val},'id':0}
+		req = {'method':'passback_float','params':[val],'id':0}
 		jreq = json.dumps(req)
 		
 		status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -115,7 +115,7 @@
 		
 	def test_passback_bool(self):
 		val = True
-		req = {'method':'passback_bool','params':{'arg':val},'id':0}
+		req = {'method':'passback_bool','params':[val],'id':0}
 		jreq = json.dumps(req)
 		
 		status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -127,7 +127,7 @@
 		
 	def test_passback_bytes(self):
 		val = 'Yo!!!'
-		req = {'method':'passback_bytes','params':{'arg':val},'id':0}
+		req = {'method':'passback_bytes','params':[val],'id':0}
 		jreq = json.dumps(req)
 		
 		status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -198,7 +198,7 @@
 		self.assertEqual(res['id'], '0')
 		self.assertIs(res['result'], None)
 		
-		req = {'method':'passback_string','params':{'arg': 'Yo!!!'},'id':0}
+		req = {'method':'passback_string','params':['Yo!!!'],'id':0}
 		jreq = json.dumps(req)
 		
 		status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -210,7 +210,7 @@
 		self.assertEqual(res['id'], '0')
 		self.assertEqual(res['result'], 'Yo!!!')
 		
-		req = {'method':'params','params':{},'id':0}
+		req = {'method':'params','params':[],'id':0}
 		jreq = json.dumps(req)
 		
 		status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -222,7 +222,7 @@
 		self.assertEqual(res['id'], '0')
 		self.assertTrue('"arg0"' in res['error']['string'])
 		
-		req = {'method':'params','params':{'arg0':11},'id':0}
+		req = {'method':'params','params':[11],'id':0}
 		jreq = json.dumps(req)
 		
 		status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -234,7 +234,7 @@
 		self.assertEqual(res['id'], '0')
 		self.assertTrue('"arg1"' in res['error']['string'])
 		
-		req = {'method':'params','params':{'arg0':11, 'arg1':11.11},'id':0}
+		req = {'method':'params','params':[11, 11.11],'id':0}
 		jreq = json.dumps(req)
 		
 		status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
@@ -245,6 +245,31 @@
 		self.assertIs(type(res['error']), dict)
 		self.assertEqual(res['id'], '0')
 		self.assertTrue('"arg2"' in res['error']['string'])
+		
+		req = {'method':'params','params':[11,11.11,'Yo!!!','Yo!!!'],'id':0}
+		jreq = json.dumps(req)
+		
+		status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
+		
+		self.assertEqual(status, 200)
+		res = json.loads(PORTABLE_STRING(resdata,'utf-8'))
+
+		self.assertIs(type(res['error']), dict)
+		self.assertEqual(res['id'], '0')
+		self.assertTrue('3' in res['error']['string'])
+		self.assertTrue('4' in res['error']['string'])
+		
+		req = {'method':'params','params':{},'id':0}
+		jreq = json.dumps(req)
+		
+		status,reason,resdata = self.post_helper.post_request(jreq.encode('utf-8'),extra_path='jsonrpc10',encoding='utf-8')
+		
+		self.assertEqual(status, 200)
+		res = json.loads(PORTABLE_STRING(resdata,'utf-8'))
+
+		self.assertIs(type(res['error']), dict)
+		self.assertEqual(res['id'], '0')
+		self.assertTrue('Params must be array of objects.' == res['error']['string'])
 
 if __name__ == '__main__':
 	import servicerunner


Follow ups