[Soap-Python] Spyne and the basic use of Arrays
Alex Railean
ralienpp at gmail.com
Thu Aug 30 17:56:38 CEST 2012
Hello,
I am having a hard time figuring out how to use arrays in Spyne.
Here are my data type definitions:
{
class SearchResult(ComplexModel):
"""A search result returned by LDAP"""
subjectName = Unicode(min_occurs = 1, nillable = False)
serialNumber = Unicode(min_occurs = 1, nillable = False)
before = Date(min_occurs = 1, nillable = False)
after = Date(min_occurs = 1, nillable = False)
subjectAltName = TypeSubjectAltName(min_occurs = 1, nillable = False)
certificatePolicy = Unicode(min_occurs = 1, nillable = False) #oid
certificate = ByteArray(default = None)
class DSearchResponse(ComplexModel):
results = Array(SearchResult)
}
I receive a request with some search criteria, retrieve the results
from an LDAP server, then return the response via SOAP/XML.
A result can be a single entry, or a list of entries - thus I created
a type called SearchResult (for one entry), and set the return type of
my service method to a type that contains an array of SearchResult
object.
This is what the service looks like:
{
class DSearchService(ServiceBase):
@srpc(DSearchRequest, _returns = DSearchResponse)
def Search(request):
result = DSearchResponse()
resultElement = SearchResult()
resultElement.subjectName = 'dummy'
result.append(resultElement) # <--- ouch!
return result
}
My understanding is that the Array type behaves like a list, so I
attempt to use it like one - but that results in an error.
I have reviewed the documentation and didn't find a sample that could
show me how to add elements to an array. The UserManager sample seems
to be close, because it does define `permissions` as
`Array(Permission)` - but the sample itself does not contain an
example of how to add a permission to the list.
Burak, can you offer some hints, or some examples of using arrays?
Alex
More information about the Soap
mailing list