forked from twisted/twisted
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: explain xmlrpc.Proxy's queryFactory
Give an example of how to debug raw XML-RPC responses using xmlrpc.Proxy.
- Loading branch information
Showing
5 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Copyright (c) Twisted Matrix Laboratories. | ||
# See LICENSE for details. | ||
|
||
""" | ||
This example prints raw XML-RPC traffic for a client. | ||
Usage: | ||
$ python xmlrpc-debug.py | ||
The example will make a simple XML-RPC request to bugzilla.redhat.com and print | ||
the raw XML response string from the server. | ||
""" | ||
|
||
from __future__ import print_function | ||
|
||
from twisted.web.xmlrpc import Proxy | ||
from twisted.web.xmlrpc import QueryFactory | ||
from twisted.internet import reactor | ||
|
||
|
||
|
||
class DebuggingQueryFactory(QueryFactory): | ||
""" Print the server's raw responses before continuing with parsing. """ | ||
def parseResponse(self, contents): | ||
print(contents) # show the raw XML-RPC string | ||
return QueryFactory.parseResponse(self, contents) | ||
|
||
|
||
|
||
def printValue(value): | ||
print(repr(value)) | ||
reactor.stop() | ||
|
||
|
||
|
||
def printError(error): | ||
print('error', error) | ||
reactor.stop() | ||
|
||
|
||
|
||
proxy = Proxy(b'https://bugzilla.redhat.com/xmlrpc.cgi') | ||
|
||
# Enable our debugging factory for our client: | ||
proxy.queryFactory = DebuggingQueryFactory | ||
|
||
# "Bugzilla.version" returns the Bugzilla software version, | ||
# like "{'version': '5.0.4.rh11'}": | ||
proxy.callRemote('Bugzilla.version').addCallbacks(printValue, printError) | ||
|
||
reactor.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
xmlrpc's QueryFactory class is now public, more explanation for xmlrpc's queryFactory, and new xmlrpc-debug.py example script for debugging raw XML-RPC traffic. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters