By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,767 Members | 1,375 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,767 IT Pros & Developers. It's quick & easy.

mirroring object attributes using xml-rpc

P: n/a
Hi

Say I have a class like the following

class Test:
i = 1

def geti(self):
return self.i

And I use it in an xml-rpc server like this:

t = Test()
s.register_instance(t)

Then the client code can get the value of i like this:
c = xmlrpclib.ServerProxy("address")
c.geti()

but why can't I get the value of i like this?

c.i

How can I implement such behaviour? Moreover, if there were more member
objects in the class Test, how can tell the client 1) that these
attributes exist and 2) how can I use them from the client side without
having to resort to defining a function get_xxx() in the server class?

Jul 5 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Just to make things clearer the problem I have is if I do this:

c = xmlrpclib.ServerProxy("http://somewhere")
c.i

I get this error:

<Fault 1: "exceptions.TypeError:'int' object is not callable">

So how do I fake things so that xmlrpc knows not to try and call i but
gets the value of i instead?

Jul 6 '06 #2

P: n/a
sa*****@gmail.com wrote:
Then the client code can get the value of i like this:
c = xmlrpclib.ServerProxy("address")
c.geti()

but why can't I get the value of i like this?

c.i
you can't. the XML-RPC protocol only supports method calls, not
attribute accesses.
How can I implement such behaviour?
you could use reflection to automatically wrap attributes on the server
side; e.g.

class foo:
x = 10
# generic getter
def __getattr__(self, key):
if not key.startswith("get_"):
raise AttributeError
value = getattr(self, key[4:])
return lambda: value

f = foo()
print f.x
print f.get_x()

</F>

Jul 6 '06 #3

P: n/a
sa*****@gmail.com wrote:
but why can't I get the value of i like this?

c.i

How can I implement such behaviour?
Not supported by XMLRpc. Switch to Pyro: http://pyro.sourceforge.net

--Irmen
Jul 6 '06 #4

P: n/a

sashangThen the client code can get the value of i like this:
sashangc = xmlrpclib.ServerProxy("address")
sashangc.geti()

sashangbut why can't I get the value of i like this?

sashangc.i

"RPC" stands for "Remote Procedure Call". You're looking for a remote
object access protocol. As Irmen pointed out, Pyro is one such beast,
though it is limited to use with Python. If you need something that's more
language-independent, you might look at SOAP. Personally, XMLRPC has been
sufficient for me for several years.

Skip
Jul 6 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.