[Patches] [ python-Patches-446912 ] Recursive object detection in xmlrpclib

noreply@sourceforge.net noreply@sourceforge.net
Thu, 02 Aug 2001 08:09:13 -0700


Patches item #446912, was opened at 2001-08-01 12:20
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=446912&group_id=5470

Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Alex Coventry (alex_coventry)
Assigned to: Fredrik Lundh (effbot)
Summary: Recursive object detection in xmlrpclib

Initial Comment:
The current implementation of xmlrpclib.Marshaller is a
little
inaccurate, in that it identifies as recursive any
container object that
has more than one reference to a given object.  E.g.

>>> import xmlrpclib
>>> m = xmlrpclib.Marshaller()
>>> a = (1,)
>>> m.dumps((a, a))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/scratch2/alex/lib/python2.2/xmlrpclib.py",
line 393, in dumps
    self.__dump(v)
  File "/scratch2/alex/lib/python2.2/xmlrpclib.py",
line 406, in __dump
    f(self, value)
  File "/scratch2/alex/lib/python2.2/xmlrpclib.py",
line 438, in dump_array
    self.__dump(v)
  File "/scratch2/alex/lib/python2.2/xmlrpclib.py",
line 406, in __dump
    f(self, value)
  File "/scratch2/alex/lib/python2.2/xmlrpclib.py",
line 434, in dump_array
    self.container(value)
  File "/scratch2/alex/lib/python2.2/xmlrpclib.py",
line 430, in container
    raise TypeError, "cannot marshal recursive data
structures"
TypeError: cannot marshal recursive data structures
>>> 

The attached patch corrects this by first getting the
reference graph of the object to be marshalled, and
topsort'ing it to check that it's not cyclic.  I'm
not sure whether this is better behaviour than the
current implementation's, as it could lead to massive
duplication in the xml response that gets generated.
However, at least the error message "cannot marshal
recursive data" should be changed if the current
implementation is left unchanged, as it misleadingly
implies that the object it was passed is recursive.

The attached testing script works with python from the
CVS repository.  A bunch of other tests are failing,
but I don't think they're related to xmlrpc.

HTH.
Alex.



----------------------------------------------------------------------

>Comment By: Alex Coventry (alex_coventry)
Date: 2001-08-02 08:09

Message:
Logged In: YES 
user_id=49686

There were errors in my code for iterating over the object
to be marshalled.  I'm deleting the old versions and 
submitting new patch and test files.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=446912&group_id=5470