473,473 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

mirroring object attributes using xml-rpc

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
4 1431
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
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Krzysztof Stachlewski | last post by:
I tried to run the following piece of code: Python 2.3.4 (#53, May 25 2004, 21:17:02) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> o = object() >>> o.a...
18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
7
by: Info 3000 | last post by:
Hello, I'm beginner in XML. I have just a little question : I understand that I can write : <Book> <Title> A nice day </Title> <Author> James Nicepen </Author> </Book>
0
by: rein.petersen | last post by:
Hi All, Some of you may have encountered complications when trying to serialize an object derived from CollectionBase (implementing ICollection or IEnumerable). Specifically, the...
0
by: serge | last post by:
I have 2 SQL Enterprise Editions running SP2 and same collation. When i try to start database mirroring I get the following error message: "The remote copy of database "ABC" has not been...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.