Thank you very much for your quick response.  Spyne is a great
tool and I appreciate you putting it together.  Unfortunately, I
think there must be something fundamentally wrong with the way I am using
Spyne with Arrays and lists.  I was not able to get your suggestions
to work.  So I upgraded to 2.10.0-py2.7 to see if the orginal syntax
would work in 2.10, but that didn't make a difference
either. 
I am trying to replace a soap server interface that
already exists, and the clients I have are particular about the names
used.
So I have created a cut-down version of my server with a
suds-type client script (at the top) which I hope will help to show you
what I am seeing.  I am sorry to do this for two reasons: 
First, it will show how little I know about python/spyne, and second it is
not usually fun to read through other people's code.
Problem 1 (See
line 83):  I do not understand the "Array" paradigm. 
In all the examples I looked through class members are declared like this
'some_member = Array( Thing)'  but then in the function definition
they just assign 'x.some_member = [ a1, b2, c3 ]' because this works
(except for the name issue <name>Array).  To me it seems like I
should be able to have a member declared as an Array and then in the
function definition I should just be able to 'append' to that
member.  This is probalby because I think of Arrays as python lists--
and they clearly are not.
Problem 2 (See line 108): I can not find a
work around that affects the type-name seen by the clients.
I am
sorry for the bother, but thank you for your patience and assitance. 
I think there something significant I am missing, but hopefully it is some
little thing.
-Nathan
> On 02/16/13 05:51,
[email protected] wrote:

>>

>> Does anyone have an example of creating and Iterable, or Array as
part

>> of the response where the name is changed to something else?

>>

>

> Hi Nathan,

>

> Normally, Array(String, type_name='ArrayOfString') should work, but
it

> doesn't. I've fixed this in the trunk and the fix will ship in
2.10.0.

>

> As a workaround, you can do this:

>

> ArrayOfTicketList = Array(TicketList)

> ArrayOfTicketList.__type_name__ = 'ArrayOfTicketList'

>

> ... and use ArrayOfTicketList in class and function definitions
instead.

>

> Does that help?

>

> Best regards,

> Burak

>

>

> _______________________________________________

> Soap mailing list

> [email protected]

> http://mail.python.org/mailman/listinfo/soap

>
#!/usr/bin/python
'''

# Code to test the GetTicketList service function:

from suds.client import Client
url = 'http://10.9.0.15:7789/?wsdl'
company = '2CA'
store   = 1
password = '1234'

client = Client(url)
client.service.GetTicketList( 'company_name', 1, '1234' )

'''

import sys
import os
from subprocess import *

import logging

from spyne.decorator import srpc
from spyne.service import ServiceBase
from spyne.model.complex import ComplexModel
from spyne.model.complex import Array
from spyne.model.primitive import Integer
from spyne.model.primitive import String
from spyne.model.primitive import Boolean
from spyne.model.primitive import Float

from spyne.util.simple import wsgi_soap_application

soap_namespace = 'http://olympuspos.net'

def run_cmd(cmd):
    p = Popen(cmd, shell=True, stdout=PIPE)
    output = p.communicate()[0]
    return output


def get_ip():
    result = run_cmd( 'ip addr' )
    lines = result.split('\n')
    skip = True
    ip = ''
    for line in lines:
        if 'BROADCAST' in line:
            skip = False
        if skip:
            continue
        if 'inet' in line:
            a, address, b, mask, c, d, interface = line.split()
            ip, net = address.split('/')
            break
    return ip


class TicketEntry(ComplexModel):
    __namespace__ = soap_namespace
    ticketEntryNum  = String
    itemId          = Integer


class Ticket(ComplexModel):
    __namespace__ = soap_namespace
    ticketNum       = String
    register        = String
    employeeID      = Integer
    Entries         = Array( TicketEntry, type_name='ArrayOfTicketEntry' )


class TicketListing(ComplexModel):
    __namespace__ = soap_namespace
    ticketNum       = String
    register        = String
    employeeName    = String


class TicketListResult(ComplexModel):
    __namespace__ = soap_namespace
    success = Boolean
    Tickets = Array( TicketListing, type_name='ArrayOfTicketListing' )


class AgentSoapService(ServiceBase):
    #__service_name__  The class name will be made public in the wsdl document unless explicitly overridden

    #
    # GetTicketList
    #
    @srpc(String, Integer, String, _returns=TicketListResult )
    def GetTicketList( company, store, storePassword ):
        r = TicketListResult
        r.success = True#r.success, message = config.credentials( company, store, storePassword )
        if not r.success:
            print message
        tickets = []
        if r.success:
            for ticketNum in all_tickets:
                ticket = all_tickets[ ticketNum ]
                tl = TicketListing
                tl.ticketNum     = ticket.ticketNum
                tl.register      = ticket.register
                tl.employeeName  = "CEO Robert"#t['employeeID']
                tickets.append( tl )
        # Doesnt Work:
        #r.Tickets = Array(TicketListing)
        #r.Tickets.__type_name__ = 'ArrayOfTicketList'

        # Doesnt Work:
        r.Tickets = tickets


        return r

if 1: # Setup fake data for GetTicketList
    te1 = TicketEntry
    te1.ticketEntryNum  = '1'
    te1.itemId          = 42

    te2 = TicketEntry
    te2.ticketEntryNum  = '2'
    te2.itemId          = 62

    t = Ticket
    t.ticketNum       = '2000'
    t.register        = '0'
    t.employeeID      = 6
    t.Entries         = [ te1, te2 ] #Array( TicketEntry, type_name='ArrayOfTicketEntry' )

all_tickets = { t.ticketNum:t }

if __name__=='__main__':
    from wsgiref.simple_server import make_server

    logging.basicConfig(level=logging.DEBUG)
    logging.getLogger('spyne.protocol.xml').setLevel(logging.DEBUG)

    ip = get_ip()
    if not len( ip ):
        exit ()

    logging.info( "listening to http://%s:7789"; % ip )
    logging.info( "wsdl is at: http://%s:7789/?wsdl"; % ip )

    wsgi_app = wsgi_soap_application([AgentSoapService], soap_namespace )
    server = make_server(ip, 7789, wsgi_app)
    server.serve_forever()
    print "listening to http://%s:7789"; % ip
    print "wsdl is at: http://%s:7789/?wsdl"; % ip
_______________________________________________
Soap mailing list
[email protected]
http://mail.python.org/mailman/listinfo/soap

Reply via email to