Problem with an OrderedDict

Bzzzz <[email protected]> Mon, 2 Mar 2015 18:08:20 +0100
Newsgroups gmane.comp.python.pyro
Organization Anyone, anywhere BUT in banana demokratik republik of france
Message-ID <[email protected]>
--MP_/xKhbj5iQW_tvW12=xVz=uRG
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi list,

I _need_ to have Pyro4 pass a huge OD; however, the echoserver example
I modified for test (see attachment) is breaking with:

First start the built-in test echo server with something like:
$ python -m Pyro4.test.echoserver
Enter the server's uri that was printed:
PYRO:test.echoserver@localhost:37305
------------
got back from the server: hello
------------
got back from the server: [1, 2, 3, 4]
------------
NATIVE = {'qs': 56, 'az': 20, 'wx': 78}
got back from the server: {u'qs': 56, u'az': 20, u'wx': 78}
------
NATIVE = OrderedDict([('wx', 78), ('qs', 56), ('az', 20)])
Traceback (most recent call last):
  File "client.py", line 46, in <module>
    response = echoserver.echo( do )
  File
"/usr/local/lib/python2.7/dist-packages/Pyro4-4.34-py2.7.egg/Pyro4/core.py",
line 169, in __call__ return self.__send(self.__name, args, kwargs) File
"/usr/local/lib/python2.7/dist-packages/Pyro4-4.34-py2.7.egg/Pyro4/core.py",
line 367, in _pyroInvoke compress=Pyro4.config.COMPRESSION) File
"/usr/local/lib/python2.7/dist-packages/Pyro4-4.34-py2.7.egg/Pyro4/util.py",
line 167, in serializeCall data = self.dumpsCall(obj, method, vargs,
kwargs) File
"/usr/local/lib/python2.7/dist-packages/Pyro4-4.34-py2.7.egg/Pyro4/util.py",
line 456, in dumpsCall return serpent.dumps((obj, method, vargs,
kwargs), module_in_classname=True) File
"build/bdist.linux-x86_64/egg/serpent.py", line 67, in dumps File
"build/bdist.linux-x86_64/egg/serpent.py", line 223, in serialize File
"build/bdist.linux-x86_64/egg/serpent.py", line 254, in _serialize File
"build/bdist.linux-x86_64/egg/serpent.py", line 304, in
ser_builtins_tuple File "build/bdist.linux-x86_64/egg/serpent.py", line
254, in _serialize File "build/bdist.linux-x86_64/egg/serpent.py", line
304, in ser_builtins_tuple File
"build/bdist.linux-x86_64/egg/serpent.py", line 254, in _serialize File
"build/bdist.linux-x86_64/egg/serpent.py", line 471, in
ser_default_class File "build/bdist.linux-x86_64/egg/serpent.py", line
254, in _serialize File "build/bdist.linux-x86_64/egg/serpent.py", line
360, in ser_builtins_dict File
"build/bdist.linux-x86_64/egg/serpent.py", line 254, in _serialize File
"build/bdist.linux-x86_64/egg/serpent.py", line 327, in
ser_builtins_list File "build/bdist.linux-x86_64/egg/serpent.py", line
254, in _serialize File "build/bdist.linux-x86_64/egg/serpent.py", line
327, in ser_builtins_list File
"build/bdist.linux-x86_64/egg/serpent.py", line 254, in _serialize File
"build/bdist.linux-x86_64/egg/serpent.py", line 327, in
ser_builtins_list File "build/bdist.linux-x86_64/egg/serpent.py", line
254, in _serialize File "build/bdist.linux-x86_64/egg/serpent.py", line
327, in ser_builtins_list File
"build/bdist.linux-x86_64/egg/serpent.py", line 254, in _serialize File
"build/bdist.linux-x86_64/egg/serpent.py", line 312, in
ser_builtins_list ValueError: Circular reference detected (list)


This OD contains a DB structure with user rights on each and every
object.

This is a real problem, as if I can't have an OD to be correctly
processed, I'll be obliged to add numbering into a regular dict,
reorder everything at either emission and reception, and other
processing that'll take a lot of code.

So, is it possible to fix this issue and how?

Jean-Yves
--MP_/xKhbj5iQW_tvW12=xVz=uRG
Content-Type: text/x-python
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=client.py

from __future__ import print_function
import sys

import Pyro4
import Pyro4.util


print("First start the built-in test echo server with something like:")
print("$ python -m Pyro4.test.echoserver")
print("Enter the server's uri that was printed:")

if sys.version_info < (3, 0):
    uri = raw_input()
else:
    uri = input()

uri = uri.strip()
echoserver = Pyro4.Proxy(uri)

print("------------")

response = echoserver.echo("hello")
print("got back from the server: %s" % response)

print("------------")

response = echoserver.echo([1, 2, 3, 4])
print("got back from the server: %s" % response)

print("------------")

# NORMAL DICT
dn = {'wx':78,'qs':56,'az':20}
print("NATIVE = %s" % dn)
response = echoserver.echo( dn )
print("got back from the server: %s" % response)
# MUST OUTPUT: {'qs': 56, 'az': 20, 'wx': 78}
print("------")
# OrderedDict (REMEMBERS INSERTION ORDER)
from collections import OrderedDict as OD
do = OD()
do['wx']=78
do['qs']=56
do['az']=20
print("NATIVE = %s" % do)
response = echoserver.echo( do )
print("got back from the server: %s" % response)
# MUST OUTPUT: OrderedDict([('wx', 78), ('qs', 56), ('az', 20)])

print("------------")


try:
    echoserver.error()
except:
    print("\ncaught an exception (expected), traceback:")
    print("".join(Pyro4.util.getPyroTraceback()))

print("\nshutting down the test echo server. (restart it if you want to run this again)")
echoserver.shutdown()

--MP_/xKhbj5iQW_tvW12=xVz=uRG
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
--MP_/xKhbj5iQW_tvW12=xVz=uRG
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Pyro-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyro-core

--MP_/xKhbj5iQW_tvW12=xVz=uRG--