[Patches] [ python-Patches-1374063 ] Broader iterable support for xmlrpclib

SourceForge.net noreply at sourceforge.net
Sun Feb 11 20:14:29 CET 2007


Patches item #1374063, was opened at 2005-12-05 22:14
Message generated for change (Comment added) made by montanaro
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1374063&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.5
Status: Open
>Resolution: None
Priority: 5
Private: No
Submitted By: Skip Montanaro (montanaro)
Assigned to: Skip Montanaro (montanaro)
Summary: Broader iterable support for xmlrpclib

Initial Comment:
The XML-RPC spec supports a fairly limited set of datatypes.
Most languages, Python included, contain many more types
than XML-RPC.  Some types, such as Python's complex number
type, have no reasonable analog in XML-RPC.  Others, such as
unicode objects and array objects do.  This patch allows
anything that can be converted to a list but that is not
otherwise supported directly by the xmlrpclib module already
to be marshalled as an XML-RPC array if the allow_iter
parameter to the ServerProxy constructor evaluated to true.
This includes sets and arrays.

Motivation...

1. Python already overloads the XML-RPC array type with both
   lists and tuples.  This just extends that overloading to
   other currently unsupported Python types which can be
   converted to lists.  Why should lists and tuples have all the
   fun?

2. Providing transparent conversion to XML-RPC arrays keeps
   calling code a bit cleaner.  One of the attractions of
   XML-RPC is that the remote procedure call looks identical
   to a local call.  This is especially true in Python
   because of /F's excellent little _Method class.  Clearly
   as a programmer I could type:

       import array
       a = array.array('i', [1, 2,3])
       ...
       from somemodule import somefunction
       print somefunction(list(a))

   but that reveals details of the implementation of
   somefunction, namely that it can't handle arrays
   directly, even though in most respects arrays
   and lists are interchangeable.

Attached is a patch for the xmlrpclib library that
implements this feature, including minor doc changes and a
new test case.


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

>Comment By: Skip Montanaro (montanaro)
Date: 2007-02-11 13:14

Message:
Logged In: YES 
user_id=44345
Originator: YES

Martin,

I'm returning to this after a pause as well...  Suppose I have a subclass
of dict.  When dumping with
my proposed patch it will get dumped as a list.  If it is to be dumped as
some lowest common
denominator type, it should be a dict I think.  For example:

#!/usr/bin/env python

class D(dict):
    pass

d = D(x=1, y=2, z=3)
print d
print list(d)

Until we address is case (at least) I'm un-accepting the patch...

Skip


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

Comment By: Martin v. Löwis (loewis)
Date: 2006-12-03 06:32

Message:
Logged In: YES 
user_id=21627
Originator: NO

The patch is fine. Notice that it is currently out of date, due to
inclusion of patch #1070046.

This other patch added generic support for objects having an __dict__
attribute, marshaling them struct elements. This is in real conflict to
this patch: an object both supporting a list conversion and having a
__dict__ attribute could be marshaled either way.

My proposal is to resolve this in favor of this patch: If an object has a
list conversion, it's most likely meant to be a list.

If you agree to this resolution, please update the code and the
documentation, and apply this patch.

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

Comment By: Skip Montanaro (montanaro)
Date: 2005-12-05 22:23

Message:
Logged In: YES 
user_id=44345

Oh, I forgot my original use case.  I was constructing a list of
musicians
from a larger data structure and used a set to guarantee uniqueness
during construction.  I didn't really care about element ordering.  I
either had to convert the set to a list when calling the local function
that made the RPC call, or modify the local function to always convert
that arg to a list.  Both alternatives seemed unattractive to me.


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

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


More information about the Patches mailing list