mirroring object attributes using xml-rpc
Fredrik Lundh
fredrik at pythonware.com
Thu Jul 6 02:24:13 EDT 2006
sashang at 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>
More information about the Python-list
mailing list