[Zope-dev] further how-to remarks on XMLRPCMethod

Ben Leslie benno@sesgroup.net
Thu, 28 Oct 1999 15:48:11 +1000


> At 02:10 AM 10/28/99 +1000, Ben Leslie wrote:
> >
> >Below is a snippet of code which is the closet I've come to getting this
> >to work. Unfortunately this totally kills and persistance
> >
> >
> >    def __getattr__(self, name):
> >        if name in ('ages', 'add', 'multiply'):
> >                myserv = xmlrpclib.Server(self.server)
> >                return (getattr(myserv,name))
> >        else:
> >                return Acquisition.Acquired
> 
> By the way, just as a postscript to my explanation of how to do this with
> __of__, keep in mind that just because an object is persistent doesn't mean
> it can't have non-persistent sub-objects...  for example:
> 
> class RPCMethodCollection:
> 	def __init__(self,server,allowed_names):
> 		self.server = server
> 		self.
> 
> 	def __getattr__(self,name):
> 		if name in self.allowed_names:
> 			myserv = xmlrpclib.Server(self.server)
> 			return (getattr(myserv,name))
> 		raise AttributeError,name
> 
> Then have XMLRPCClient add a "methods" attribute that is an instance of
> RPCMethodCollection.  You can now say things like:
> 
> <!--#with "someserver.methods"-->
> <!--#call "add(2,3)"-->
> <!--#/with-->
> 
> Which leads to my final point, namely that maybe, instead of making the
> client object provide all the methods, maybe from a design perspective it
> would make more sense to have very lightweight "XMLRPCMethod" objects which
> talk to an "XMLRPCServer" object.  This allows you to have much more
> fine-grained permissions control on use of the methods, and it'll be easier
> to call them from DTML anyhow.


Phillip, thanks a lot for the advice on how to use __of__ it was a great help.

I personally prefer being able to freely access any method available on a 
server without having to create a seperate wrapper for each one. I realise
that this isn't as fine grained from a security point of view, however 
in the project I am currently working on I will be calling a large number
methods on another server. I didn't really want to have to create a wrapper
for each single one, just seems like overkill to me.

Although having fine grained security may be a desirable thing. I think I
will need to think about this some more :)

Any way at the moment I have edited my XMLRPCClient product so that it supports

"server.method(x, y)" 

syntax. There a couple of problems with this though.

1) You have to explicitly name the functions you want to call in this manner.

2) You cannot call nested functions in this manner ie:

"betty.examples.getStateName(42)" would not work.

You can still access these through the 

"betty('examples.getStateName', 42)"  syntax though.


Any comments appreciated.

Benno