trying to wrap xmlrpclib into classes

Steven Noels stevenn at outerthought.org
Tue Jan 21 10:43:54 CET 2003


Hi there,

<warning>These are my first steps into Python programming, pardon my 
cluelessness</warning>

I'm trying to create a little application which uses xmlrpclib to 
retrieve information from some server. After some Googling, I succeeded 
in accessing my server and I'm pretty confident I will get where I want 
with conventional procedural/functional programming. Since part of my 
venture in learning Python is to use OO, I start from scratch this 
morning, trying to wrap stuff into objects. And I'm failing fast :(

This is where I got so far:

import xmlrpclib, time, strptime
from UrllibTransport import UrllibTransport

class Server:
     def __init__(self, URL):
         self.server_url = URL
         self.server = xmlrpclib.Server(self.server_url, 
transport=UrllibTransport())

class Page:
     def __init__(self, name, URL):
         self.name = name
         self.server = Server(URL)
     def getInfo(self):
         self.result = self.server.wiki.getPageInfo(name)

page = Page('Main', 'http://wiki.cocoondev.org/RPC2/')
pageinfo = page.getInfo()

I have a Server class, which should represent an XMLRPC 'connection', 
and I also defined a Page class, which should represent a logical 
structure available across that connection.

(API documented here: 
http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=WikiRPCInterface)

Instantiating my page goes well, but trying to access a method like 
getInfo, which should invoke server.wiki.getPageInfo(name) through my 
server object does not work, for obvious reasons:

     self.result = self.server.wiki.getPageInfo(name)
AttributeError: Server instance has no attribute 'wiki'

'Somehow', I want this Page object to forward the method invocation to 
my Server object, but I'm stuck on the _how_. Should I let my Server 
class inherit from the xmlrpclib.Server class? My Page class too?

I will try into that direction, but any tips and pointers would be 
appreciated. Also, sorry if this isn't the clueless newbie user's list.

Cheers,

</Steven>
-- 
Steven Noels                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at            http://blogs.cocoondev.org/stevenn/
stevenn at outerthought.org                stevenn at apache.org






More information about the Python-list mailing list