@@ -165,6 +165,8 @@ def __run_request(self, request, notify=None):
165
165
global _last_response
166
166
_last_request = request
167
167
168
+ print request
169
+
168
170
response = self .__transport .request (
169
171
self .__host ,
170
172
self .__handler ,
@@ -204,7 +206,7 @@ def __call__(self, *args, **kwargs):
204
206
205
207
# Batch implementation
206
208
207
- class Job (object ):
209
+ class MultiCallMethod (object ):
208
210
209
211
def __init__ (self , method , notify = False ):
210
212
self .method = method
@@ -227,15 +229,15 @@ def request(self, encoding=None, rpcid=None):
227
229
def __repr__ (self ):
228
230
return '%s' % self .request ()
229
231
230
- class MultiCall (ServerProxy ):
232
+ class MultiCall (object ):
231
233
232
- def __init__ (self , uri , * args , ** kwargs ):
234
+ def __init__ (self , server ):
235
+ self .__server = server
233
236
self .__job_list = []
234
- ServerProxy .__init__ (self , uri , * args , ** kwargs )
235
237
236
238
def __run_request (self , request_body ):
237
- run_request = getattr (ServerProxy , '_ServerProxy__run_request' )
238
- return run_request (self , request_body )
239
+ run_request = getattr (self . __server , '_ServerProxy__run_request' )
240
+ return run_request (request_body )
239
241
240
242
def __request (self ):
241
243
if len (self .__job_list ) < 1 :
@@ -248,15 +250,15 @@ def __request(self):
248
250
return [ response ['result' ] for response in responses ]
249
251
250
252
def __notify (self , method , params = []):
251
- new_job = Job (method , notify = True )
253
+ new_job = MultiCallMethod (method , notify = True )
252
254
new_job .params = params
253
255
self .__job_list .append (new_job )
254
256
255
257
def __getattr__ (self , name ):
256
258
if name in ('__run' , '__notify' ):
257
259
wrapped_name = '_%s%s' % (self .__class__ .__name__ , name )
258
260
return getattr (self , wrapped_name )
259
- new_job = Job (name )
261
+ new_job = MultiCallMethod (name )
260
262
self .__job_list .append (new_job )
261
263
return new_job
262
264
@@ -266,7 +268,7 @@ def __getattr__(self, name):
266
268
# Not really sure if we should include these, but oh well.
267
269
Server = ServerProxy
268
270
269
- class Fault (dict ):
271
+ class Fault (object ):
270
272
# JSON-RPC error class
271
273
def __init__ (self , code = - 32000 , message = 'Server error' ):
272
274
self .faultCode = code
@@ -279,8 +281,10 @@ def response(self, rpcid=None, version=None):
279
281
global _version
280
282
if not version :
281
283
version = _version
282
- return dumps (self , rpcid = None , methodresponse = True ,
283
- version = version )
284
+ return dumps (self , rpcid = rpcid , version = version )
285
+
286
+ def __repr__ (self ):
287
+ return '<Fault %s: %s>' % (self .faultCode , self .faultString )
284
288
285
289
def random_id (length = 8 ):
286
290
import string
@@ -343,7 +347,7 @@ def dumps(params=[], methodname=None, methodresponse=None,
343
347
"""
344
348
global _version
345
349
if not version :
346
- verion = _version
350
+ version = _version
347
351
valid_params = (types .TupleType , types .ListType , types .DictType )
348
352
if methodname in types .StringTypes and \
349
353
type (params ) not in valid_params and \
@@ -354,18 +358,16 @@ def dumps(params=[], methodname=None, methodresponse=None,
354
358
"""
355
359
raise TypeError ('Params must be a dict, list, tuple or Fault ' +
356
360
'instance.' )
357
- if type (methodname ) not in types .StringTypes and methodresponse != True :
358
- raise ValueError ('Method name must be a string, or methodresponse ' +
359
- 'must be set to True.' )
360
- if isinstance (params , Fault ) and not methodresponse :
361
- raise TypeError ('You can only use a Fault for responses.' )
362
361
# Begin parsing object
363
362
payload = Payload (rpcid = rpcid , version = version )
364
363
if not encoding :
365
364
encoding = 'utf-8'
366
365
if type (params ) is Fault :
367
366
response = payload .error (params .faultCode , params .faultString )
368
367
return jdumps (response , encoding = encoding )
368
+ if type (methodname ) not in types .StringTypes and methodresponse != True :
369
+ raise ValueError ('Method name must be a string, or methodresponse ' +
370
+ 'must be set to True.' )
369
371
if methodresponse is True :
370
372
if rpcid is None :
371
373
raise ValueError ('A method response must have an rpcid.' )
0 commit comments