| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Twisted
Revision: 24679
Author: therve
Date: 05 Sep 2008 05:18:26
Diff at Trac: http://twistedmatrix.com/trac/changeset/24679
Changes:Merge xmlrpc-empty-response-3399
Author: therve
Reviewer: exarkun
Fixes #3399
Fix xmlrpc client so that he manages to return an error for buggy servers
sending an empty response.
| ... | ...@@ -450,3 +450,20 @@ | |
| 450 | 450 | d.addErrback(self.queryFactory.clientConnectionLost, self.reason) |
| 451 | 451 | self.queryFactory.badStatus('status', 'message') |
| 452 | 452 | return d |
| 453 | ||
| 454 | def test_parseResponseWithoutData(self): | |
| 455 | """ | |
| 456 | Some server can send a response without any data: | |
| 457 | L{_QueryFactory.parseResponse} should catch the error and call the | |
| 458 | result errback. | |
| 459 | """ | |
| 460 | content = """ | |
| 461 | <methodResponse> | |
| 462 | <params> | |
| 463 | <param> | |
| 464 | </param> | |
| 465 | </params> | |
| 466 | </methodResponse>""" | |
| 467 | d = self.queryFactory.deferred | |
| 468 | self.queryFactory.parseResponse(content) | |
| 469 | return self.assertFailure(d, IndexError) |
| ... | ...@@ -304,13 +304,13 @@ | |
| 304 | 304 | if not self.deferred: |
| 305 | 305 | return |
| 306 | 306 | try: |
| 307 | response = xmlrpclib.loads(contents) | |
| 307 | response = xmlrpclib.loads(contents)[0][0] | |
| 308 | 308 | except: |
| 309 | 309 | deferred, self.deferred = self.deferred, None |
| 310 | 310 | deferred.errback(failure.Failure()) |
| 311 | 311 | else: |
| 312 | 312 | deferred, self.deferred = self.deferred, None |
| 313 | deferred.callback(response[0][0]) | |
| 313 | deferred.callback(response) | |
| 314 | 314 | |
| 315 | 315 | def clientConnectionLost(self, _, reason): |
| 316 | 316 | if self.deferred is not None: |
| ... | ...@@ -391,6 +391,14 @@ | |
| 391 | 391 | self.allowNone = allowNone |
| 392 | 392 | |
| 393 | 393 | def callRemote(self, method, *args): |
| 394 | """ | |
| 395 | Call remote XML-RPC C{method} with given arguments. | |
| 396 | ||
| 397 | @return: a L{defer.Deferred} that will fire with the method response, | |
| 398 | or a failure if the method failed. Generally, the failure type will | |
| 399 | be L{Fault}, but you can also have an C{IndexError} on some buggy | |
| 400 | servers giving empty responses. | |
| 401 | """ | |
| 394 | 402 | factory = self.queryFactory( |
| 395 | 403 | self.path, self.host, method, self.user, |
| 396 | 404 | self.password, self.allowNone, args) |