[Fedora-suds-list] Array of complex type weirdness

Martin Aspeli optilude at gmail.com
Tue Jun 22 06:56:42 UTC 2010


Hi,

I have a soaplib server (emulating a Java server) which does this:

from soaplib.serializers.primitive import String, Integer, DateTime,
Array, Fault
from soaplib.serializers.clazz import ClassSerializer

from soaplib.service import SoapServiceBase
from soaplib.service import soapmethod

class Transaction(ClassSerializer):

    class types:
        cost = Integer
        purchaseDate = DateTime
        status = Integer

class HistoryResponse(ClassSerializer):

    class types:
        transactions = Array(Transaction)
        totalRecords = Integer


class TransactionService(SoapServiceBase):

    @soapmethod(String, Integer, DateTime, DateTime, Integer,
_returns=HistoryResponse)
    def getHistory(self, tokenId, status, dateFrom, dateTo, pageId):

        transactionsList = createAPythonListOfTransactionObjects()
        response = HistoryResponse()
        response.transactions = transactionsList
        response.totalRecords = 1000

In Suds (in another process), when I get back the results from calling
getHistory(), the return value prints like this:

(HistoryResponse){
   totalRecords = 1000
   transactions =
      (TransactionArray){
         _type = "tns:TransactionArray"
         Transaction[] =
            (Transaction){
               purchaseDate = 2010-02-28 12:00:00
               cost = 1500
               status = 8
            },
            (Transaction){
               purchaseDate = 2010-02-28 12:00:00
               cost = 1200
               status = 2
            },
      }
 }


To loop over transactions, I have to do:

for item in response.transactions.Transaction:
    ...

Which is pretty awkward. I also suspect that this may not always be
necessary, as we had some other mocks going with SoapUI where it was
sufficient to iterate over response.transactions directly.

Am I doing something wrong?

Cheers,
Martin


More information about the suds mailing list