INCUTIO HOME | SCRIPTS | CONTACT

Accessing The Jargon File using Python's XMLRPClib

Python provides an excellent environment for testing and debugging XML-RPC libraries in the form of xmlrpclib, the Python XML-RPC library. xmlrpclib is part of the standard Python base library now but older versions of Python may not have it installed. You can download the library separately from here.

If you don't have Python, you can install it from http://www.python.org/download/. Installation for Windows is trivial - just download and run the 7MB installer.

The reason Python makes such a good debugging tool is its interactive prompt. In Windows, a GUI version of this can be accessed by running IDLE in the Python section of the Start menu. Unix users can simply type 'python' (the graphical IDLE client is also available on non-windows platforms). You can then type Python commands and watch them execute immediately.

Here's how to use Python to access Incutio's web service for the Jargon File:

>>> import xmlrpclib
>>> j = xmlrpclib.Server('http://scripts.incutio.com/xmlrpc/services/jargonfile.php')
>>> j.system.listMethods()
['jargon.about', 'jargon.search', 'jargon.getEntryByShortname', 'jargon.getEntryByTitle' ...
>>> j.system.methodHelp('jargon.search')
'Searches the Jargon File and returns an array of shortnames for entries containing the term. 
These can then be retrieved using the jargon.getEntryByShortname method.'
>>> j.jargon.search('eric')
['0', 'Acme', 'ANSI', 'AOL!', 'ASCII', 'backbone-cabal', 'Bad-Thing', 'Befunge' ...
>>> j.jargon.getEntryByShortname('backbone-cabal')
{'definition': 'backbone cabal n. \nA group of large-site administrators who\npushed ...
>>> print j.jargon.getEntryByShortname('backbone-cabal')['definition']
backbone cabal n. 
A group of large-site administrators who
pushed through the [[[Great-Renaming]]] and reined in the chaos of
[[[Usenet]]] during most of the 1980s.  During most of its lifetime,
the Cabal (as it was sometimes capitalized) steadfastly denied its
own existence; it was almost obligatory for anyone privy to their
secrets to respond "There is no Cabal" whenever the existence or
activities of the group were speculated on in public.

The result of this policy was an attractive aura of mystery.  Even
a decade after the cabal [[[mailing-list]]] disbanded in late 1988
following a bitter internal catfight, many people believed (or
claimed to believe) that it had not actually disbanded but only
gone deeper underground with its power intact.

This belief became a model for various paranoid theories about
various Cabals with dark nefarious objectives beginning with taking
over the Usenet or Internet.  These paranoias were later satirized
in ways that took on a life of their own.  See [[[Eric-Conspiracy]]]
for one example.

See [[[NANA]]] for the subsequent history of "the Cabal".
>>> 

Debugging

To debug XML-RPC servers from Python, create the client object using the optional verbose=1 paramater. You can then use the client as normal and watch as the XML-RPC request and response is displayed in the console.

>>> j = xmlrpclib.Server('http://scripts.incutio.com/xmlrpc/services/jargonfile.php', verbose=1)
>>> j.system.methodHelp('jargon.getEntryByShortname')
connect: (scripts.incutio.com, 80)
send: 'POST /xmlrpc/services/jargonfile.php HTTP/1.0\r\n'
send: 'Host: scripts.incutio.com\r\n'
send: 'User-Agent: xmlrpclib.py/1.0.0 (by www.pythonware.com)\r\n'
send: 'Content-Type: text/xml\r\n'
send: 'Content-Length: 187\r\n'
send: '\r\n'
send: "<?xml version='1.0'?>\n<methodCall>\n<methodName>system.methodHelp</methodName>\n<params>
<param>\n<value><string>jargon.getEntryByShortname</string></value>\n</param>\n
</params>\n</methodCall>\n"
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Thu, 05 Sep 2002 12:12:10 GMT
header: Server: Apache/1.3.26 (Unix) mod_ssl/2.8.10 OpenSSL/0.9.6d PHP/4.2.2
header: X-Powered-By: PHP/4.2.2
header: Connection: close
header: Content-Length: 260
header: Content-Type: text/xml
body: '<?xml version="1.0"?>\n<methodResponse>\n  <params>\n    <param>\n      <value>\n
        <string>Returns the Jargon File entry for the specified shortname, or a 404 error 
if the entry is not found.</string>\n      </value>\n    </param>\n  </params>\n
</methodResponse>\n'
'Returns the Jargon File entry for the specified shortname, or a 404 error if ...
>>> 
scripts.incutio.com light logo
AskApache Web Development