| 1 |
# Copyright (c) Twisted Matrix Laboratories. |
| 2 |
# See LICENSE for details. |
| 3 |
|
| 4 |
""" |
| 5 |
This example prints raw XML-RPC traffic for a client. |
| 6 |
|
| 7 |
Usage: |
| 8 |
$ python xmlrpc-debug.py |
| 9 |
|
| 10 |
The example will make a simple XML-RPC request to bugzilla.redhat.com and print |
| 11 |
the raw XML response string from the server. |
| 12 |
""" |
| 13 |
|
| 14 |
from twisted.internet import reactor |
| 15 |
from twisted.web.xmlrpc import Proxy, QueryFactory |
| 16 |
|
| 17 |
|
| 18 |
class DebuggingQueryFactory(QueryFactory): |
| 19 |
"""Print the server's raw responses before continuing with parsing.""" |
| 20 |
|
| 21 |
def parseResponse(self, contents): |
| 22 |
print(contents) # show the raw XML-RPC string |
| 23 |
return QueryFactory.parseResponse(self, contents) |
| 24 |
|
| 25 |
|
| 26 |
def printValue(value): |
| 27 |
print(repr(value)) |
| 28 |
reactor.stop() |
| 29 |
|
| 30 |
|
| 31 |
def printError(error): |
| 32 |
print("error", error) |
| 33 |
reactor.stop() |
| 34 |
|
| 35 |
|
| 36 |
proxy = Proxy(b"https://bugzilla.redhat.com/xmlrpc.cgi") |
| 37 |
|
| 38 |
# Enable our debugging factory for our client: |
| 39 |
proxy.queryFactory = DebuggingQueryFactory |
| 40 |
|
| 41 |
# "Bugzilla.version" returns the Bugzilla software version, |
| 42 |
# like "{'version': '5.0.4.rh11'}": |
| 43 |
proxy.callRemote("Bugzilla.version").addCallbacks(printValue, printError) |
| 44 |
|
| 45 |
reactor.run() |