trying to wrap xmlrpclib into classes

Steven Noels stevenn at outerthought.org
Wed Jan 22 13:54:21 CET 2003


Brian Quinlan wrote:

>>'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?
> 
> 
> You could make your Server class an xmlrpclib.Server subclass but I
> would just get rid of your Server class since it doesn't really do
> anything.

That's what I did, thanks. What do you mean with 'getting rid of my 
Server class...? I definitely need the one in xmlrpclib.py. I'm trying 
to wrap things in order to make it feel less XMLRPC'ish:

import xmlrpclib, time, strptime
from UrllibTransport import UrllibTransport

class Page(xmlrpclib.Server):

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

     def retrievePageInfo(self):
         pageInfo = self.server.wiki.getPageInfo(self.name)
         self.version = pageInfo['version']
         self.author = pageInfo['author']
         self.lastModified = UTC2time(pageInfo['lastModified'].value) # 
make a (time) tuple out of it
     def getName(self):
         return self.name

     def getVersion(self):
         return self.version

     def getAuthor(self):
         return self.author

     def getlastModified(self):
         return self.lastModified

     def getPageContent(self):
         pageContent = self.server.wiki.getPage(self.name)
         return pageContent.data

     def getPageContentVersion(self, version):
         pageContent = self.server.wiki.getPageVersion(self.name, version)
         return pageContent.data

class RecentChanges(xmlrpclib.Server):

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

     def getRecentChanges(self, time):
         rc = 
self.server.wiki.getRecentChanges(xmlrpclib.DateTime(time2UTC(time)))
         ...

Dunnow whether this is good design, so comments are welcome!

</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