[Zope-dev] access to ZCatalog-data via xmlrpc

M.-A. Lemburg mal@lemburg.com
Thu, 30 May 2002 12:11:10 +0200


Joachim Schmitz wrote:
> 
> 
> --On Mittwoch, Mai 29, 2002 16:15:44 +0100 Toby Dickenson 
> <tdickenson@geminidataloggers.com> wrote:
> 
>> On Wednesday 29 May 2002 3:24 pm, Joachim Schmitz wrote:
>>
>>> Hi,
>>>
>>> I want to acces a ZCatalog via xmlrpc, but
>>>
>>> server=xmlrpclib.Server("http://myserver.aixtraware.de"
>>>                         ,BasicAuthTransport(username="user",password="pw
>>>                         "))
>>> r = server.Catalog()
>>>
>>> results in
>>>
>>> <Fault -1: "Unexpected Zope exception: cannot marshal <type
>>> 'IOBTreeItems'> objects">
>>>
>>> What is to do, to enable marshalling of those types ?

XML-RPC only has a limited set of types it can marshal and that
can't be changed without breaking the standard.

The alternative would be sending Python pickles encoded as
XML-RPC binary over the wire.

>>
>>
>> You could hack xmlrpclib to marshall those object, but I dont recommend
>> it.  Those objects can be big (but lazily evaluated), and you would be
>> opening a  significant denial of service vulnerability in your server.
> 
> But it also can be very interesting for exporting data from a Zope site, 
> to be used in other applications.
> 
>>
>> I suggest you create a method (Python Script?) that makes the catalog
>> query,  sanitizes the response by making sure it is not too big, and
>> returns a  vanilla list or dictionary
> 
> I wrote a little pythonscript to export data from a ZPatterns Rack, 
> where the data is stored in a propertysheet:
> 
> res=context.Catalog()
> 
> t=[]
> for m in  sequence.sort(res,(('reg_id','cmp','desc'),)):
>    r=m.propertysheets.Basic.propertyItems()
>    t.append(r)
> return t
> 
> This runs fine, when I test the script. But when I access it with 
> xmlrpc, I get:
> 
> <Fault -1: "Unexpected Zope exception: cannot marshal <type 'None'> 
> objects">
> 
> I changed Zope xmlrpclib.py and added to the Marshaller class:
> 
>    def dump_None(self, value):
>        self.write("<value><string>None</string></value>\n")
>    dispatch[NoneType] = dump_None
> 
> Now that works, but I think the xmlrpclib.py, should be able to marshall 
> the "None" type.

None doesn't have an equivalent type in XML-RPC.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Software:                   http://www.egenix.com/files/python/
Meet us at EuroPython 2002:                 http://www.europython.org/