Hi Alex, All,

Here's my version of your code:

class SearchResult(ComplexModel):
  """A search result returned by LDAP"""
  subjectName = Mandatory.Unicode
  serialNumber = Mandatory.Unicode
  before = Mandatory.Date
  after = Mandatory.Date

  subjectAltName = TypeSubjectAltName(min_occurs = 1, nillable = False)
  # not sure about this one, is this  ^ here a ComplexModel subclass?

  certificatePolicy = Mandatory.Unicode #oid
  certificate = ByteArray(default = None)


class DSearchService(ServiceBase):
  @srpc(Array(SearchRequest), _returns = Array(SearchResult))
  def Search(request):
     result = SearchResult()
     result.subjectName = 'dummy'

     return [result]

Your code in the last mail is also perfectly fine if that's the kind of Xml document you need to produce.

On 08/30/12 20:56, C Anthony Risinger wrote:
try:

result.results.append(resultElement)


This is suds code, not Spyne. Spyne tries to hide implementation details, so it's a little bit different.

Here's an example:

class Return(ComplexModel):
    responses = Array(String)

['a','b'] gets serialized as:

<Return>
<responses>
<string>a</string>
<string>b</string>
</responses>
</Return>

However for the following object;

class Return(ComplexModel):
responses = String(max_occurs='unbounded') # or max_occurs=Decimal('inf'), both work.

['a','b'] gets serialized as:

<Return>
<responses>a</responses>
<responses>b</responses>
</Return>

Both are the same thing from Spyne's perspective, because Spyne hides such details from the user. But Suds does not, so dealing with these responses would be different in Suds' case.

On 08/30/12 21:39, Alex Railean wrote:
(Pdb) res = Array(SearchResult)
(Pdb) res
<class 'spyne.model.complex.Array'>
(Pdb) res.append(resultElement)
*** AttributeError: type object 'Array' has no attribute 'append'


Classes in spyne.model package are just markers, so this would not work. You should work with their native types. When returning for Array types, just return any kind of iterable (e.g. tuple, list, generator, iterator, etc)

Hope this helps,

Best,
Burak

On 08/30/12 18:56, Alex Railean wrote:
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

_______________________________________________
Soap mailing list
[email protected]
http://mail.python.org/mailman/listinfo/soap

_______________________________________________
Soap mailing list
[email protected]
http://mail.python.org/mailman/listinfo/soap

Reply via email to