[Soap-Python] Spyne: ability to change default results name from FooResult to WhateverXyz ?

Burak Arslan burak.arslan at arskom.com.tr
Thu Apr 30 10:26:59 CEST 2015


Hello,

On 04/30/15 03:11, Patricio Stegmann wrote:
> Burak,
> There is the message, but inside is the result which has its own name.
> It is automatically generated with Result suffix, but my ws consumer
> didnt want that. He wanted the name of it's spec on it. I added that
> keyword and slightly changed some spyne lines.
> I had lot of issues using multiple namespaces, in the lxml output
> generation, which I managed to solve using git version, and now it
> seems to work ok.

I'm always interested in ways people patch Spyne. If you think it's
worthy, please let me know.

> I have just a simple question. I need to be able to generate something
> like this:
>
> <MyResponse>
>   <Items>
>     <ItemList ofType="b">
>       <Item>blabla</Item>
>       <Item>bleble</Item>
>       <Item>blibli</Item>
>     </ItemList>
>     <ItemList ofType="c">
>       <Item>clacla</Item>
>       <Item>clecle</Item>
>       <Item>clicli</Item>
>     </ItemList>
>   </Items>
> </MyResponse>

from spyne import *
from spyne.util.xml import *
from lxml import etree

class ItemList(ComplexModel):
    of_type = XmlAttribute(Unicode(sub_name='ofType'))
    items = Unicode(max_occurs='unbounded', sub_name='Item')
    # 2.12 will support this, which is imo nicer to look at:
    items = Array(Unicode, wrapped=False, sub_name='Item')

class MyResponse(ComplexModel):
    items = Array(ItemList, sub_name="Items")

print etree.tostring(get_object_as_xml(MyResponse(
    items=[
        ItemList(of_type="b", items=[
            "blabla", "bleble", 'blibli',
        ]),
        ItemList(of_type="c", items=[
            "clacla", "clecle", 'clicli',
        ]),
    ]
)), pretty_print=True)


The sub_name additions here are to prevent you from breaking the PEP8 rules.

hth,

burak


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/soap/attachments/20150430/614dc837/attachment.html>


More information about the Soap mailing list