Re: Serializing attributes and indexing
Irmen de Jong <[email protected]> Fri, 04 Jul 2014 22:44:53 +0200
| Newsgroups | gmane.comp.python.pyro |
|---|---|
| Message-ID | <[email protected]> |
On 4-7-2014 21:06, Plamen Dimitrov wrote:
> Hi Irmen,
>
> Thank you for your last reply - it was all I needed to know about customer serialization
> and the good practice of relying on the automatic serialization of the proxy objects
> themselves.
>
> I wanted to ask you about another thing - serializing object attributes and possibly
> indexing. I have problems serializing cases like
>
> 1) params = Pyro4.Proxy("some-uri-here")
> params["some_present_key"]
>
> resulting in an error of the kind "TypeError: 'Proxy' object is unsubscriptable".
Yeah, only method calls are proxied.
Attribute access and indexing aren't.
> It might be an edge case so I was also wondering about a far simple case when I need to
> access a simple attribute/field of a remote object:
>
> 2) firefox = Pyro4.Proxy("PYRONAME:firefox")
> print firefox.download_location
>
> where the download location is a simple string of the kind
>
> firefox.download_location = "C:\\"
>
> I was thinking about relying on a get() method in the first case
> (params.get("some_present_key")) and properties in the second. Do you think there is a
> more natural solution to this that requires less modification of an already existing code?
Indeed, the get() method is what I'm suggesting as well.
You could perhaps subclass Pyro4.Proxy with a custom proxy class that implements
__index__ and make it call your get() method, but I think that's more hassle that it's
worth.
Adding properties to your remote object instead of attributes won't work.
They will live strictly on the remote object and are not automagically translated to
properties on the proxy object on the client side.
Irmen
------------------------------------------------------------------------------
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft