Name

ServerProxy

Synopsis

class ServerProxy(url)

If the server at the given url supports introspection, s supplies an attribute s .server that in turn supplies three methods:

s .server.listMethods( )

Returns a list of strings, one per each method supported by the server.

s .server.methodSignature( name )

Returns a list of strings, each a signature of method name on the server. A signature string is composed of type names separated by commas: first the type of the return value, then the type of each argument. When method name has no defined signature, s.server.methodSignature( name ) returns some object that is not a list.

s .server.methodHelp( name )

Returns a string with help about method name. The string can be either plain text or HTML. When the method name has no defined help, s.server.methodHelp( name ) returns an empty string ''.

The following example uses xmlrpclib to access O’Reilly’s Meerkat open wire service (see http://www.oreillynet.com/meerkat/ for more information about Meerkat) and displays the last few news items about Python.

import xmlrpclib

proxy = xmlrpclib.ServerProxy(
    'http://www.oreillynet.com/meerkat/xml-rpc/server.php')
results = proxy.meerkat.getItems({'search':'Python', 'num_items':7})

want_keys = 'title link description'.split( )
n = 0
for result in results:
    n = n + 1
    for key in want_keys:
        print '%d. %s: %s' % (n, key.title( ), result.get(key))
    print

Get Python in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.