[z3-checkins] r27085 - z3/jsonserver/branch/zope2_test
reebalazs at codespeak.net
reebalazs at codespeak.net
Thu May 11 17:36:05 CEST 2006
Author: reebalazs
Date: Thu May 11 17:36:03 2006
New Revision: 27085
Modified:
z3/jsonserver/branch/zope2_test/jsonrpc.py
Log:
Implement JSON-RPC 1.1
Modified: z3/jsonserver/branch/zope2_test/jsonrpc.py
==============================================================================
--- z3/jsonserver/branch/zope2_test/jsonrpc.py (original)
+++ z3/jsonserver/branch/zope2_test/jsonrpc.py Thu May 11 17:36:03 2006
@@ -78,19 +78,37 @@
# Separare positional keywords from args
# this works if client emits {'jsonclass': ['zope.kw', kw]}
args, kw = [], {}
- for arg in params:
- success = False
- if isinstance(arg, dict) and 'jsonclass' in arg:
- # json class hints
- # TODO handle Date
- pass
- elif isinstance(arg, dict) and pythonkwmarker in arg:
- # a keyword parm
- kw.update(arg[pythonkwmarker])
- success = True
- if not success:
- # a normal positional parm
- args.append(arg)
+ if isinstance(params, dict):
+ argcounter = []
+ for key, value in params.iteritems():
+ try:
+ index = int(key)
+ except ValueError:
+ # a key
+ kw[key] = value
+ else:
+ # an arg
+ argcounter.append((index, value))
+ # now put together the args
+ argcounter.sort()
+ for i, (index, value) in enumerate(argcounter):
+ if i != index:
+ raise IndexError, "Bad order or arguments in JSON payload"
+ args.append(value)
+ else:
+ for arg in params:
+ success = False
+ if isinstance(arg, dict) and 'jsonclass' in arg:
+ # json class hints
+ # TODO handle Date
+ pass
+ elif isinstance(arg, dict) and pythonkwmarker in arg:
+ # a keyword parm
+ kw.update(arg[pythonkwmarker])
+ success = True
+ if not success:
+ # a normal positional parm
+ args.append(arg)
return jsonID, method, args, kw
More information about the z3-checkins
mailing list