proxy for xmlrpc calls

2006-08-12 Thread Xavier
I'm attempting to write a proxy for xmlrpc calls.

I'm starting from this code;

class MagicObject:

 def __call__(self,*args,**kwargs):
 return MagicObject.__dict__['_stop'](self,self.n,*args,**kwargs)

 def __getattr__(self,name):
 if name in ('__str__','__repr__'): return lambda:'instance of 
%s at %s' % (str(self.__class__),id(self))
 if not self.__dict__.has_key('n'):self.n=[]
 self.n.append(name)
 return self

 def _stop(self,n,*args,**kwargs):
 self.n=[]
 return self.default(n,*args,**kwargs)

 def default(self,n,*args,**kwargs):
 return 'stop',n,args,kwargs



 >>c=MagicObject()
 >>x=c.beubeb.z(1,2,3,a='bbb')
 >>print x
('stop', ['beubeb', 'z'], (1, 2, 3), {'a': 'bbb'})

I did not write this, the source is here:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/435757

I want to expand this to do something like;

 >>a=MagicObject()
 >>x = a.b.c.d

Then on the last __getattr__ send a call over xmlrpc.
How do I determine when the last __getattr__ will be?

With method calls you know to send a call on xmlrpc when you hit 
__call__.  But if you're dealing with a getting nested attributes
what do you do?  How do I know when there are no more attributes?
I thought about getting the source code from
the correct frame, but I don't think thats a good solution.

Any ideas?
Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: proxy for xmlrpc calls

2006-08-14 Thread Fredrik Lundh
Xavier wrote:

> I'm attempting to write a proxy for xmlrpc calls.

why not use the one in the standard library?

> I want to expand this to do something like;
>
> >>a=MagicObject()
> >>x = a.b.c.d
>
> Then on the last __getattr__ send a call over xmlrpc.
> How do I determine when the last __getattr__ will be?

you can't determine that.

(and XML-RPC doesn't support attribute access either, so this sounds
like a rather pointless exercise)

> I thought about getting the source code from the correct frame, but
> I don't think thats a good solution.

getting the source won't help, unless you're willing to violate Python's
execution model.

> Any ideas?

stick to the standard.

 



-- 
http://mail.python.org/mailman/listinfo/python-list