Hi Nathan,
The issue was that you did not instantiate your classes.
Names from the spyne.model package are there just for the shows --
they're type markers and don't actually do much serialization, if at
all. The following Spyne class:
class SomeObject(ComplexModel):
a=Integer
b=String
c=Array(Double)
... is "equivalent" to the following C++ code:
struct SomeObject {
int a;
string b;
vector<double> c;
}
So in order to use Spyne classes, you need to instantiate them, just
like you would instantiate a C++ class. I realize that declaring classes
like this is not the most pythonic way, but I firmly believe that
"static typing (with declarative constraints) works wonders when your
data comes from untrusted sources". Spyne is the result of my being
stubborn about this opinion :) I chose to abuse Python's class
attributes to make the class declaration as eye-pleasing as possible,
but I admit that sometimes it comes off as a little bit weird at first.
Hopefully it's a fair trade-off.
So anyway, please have a look at the following gist to see my changes to
your code to make it work.
https://gist.github.com/plq/4970712
Please let me know if you have further questions.
By the way, if you do want to help, blog posts about your Spyne
experience or pull requests for the documentation are highly
appreciated. I try to do my best with the documentation, but first
timers documenting their Spyne experience is very valuable and something
I can't really do.
Thanks and best regards,
Burak
On 16/02/13 21:26, [email protected] wrote:
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
>
_______________________________________________
Soap mailing list
[email protected]
http://mail.python.org/mailman/listinfo/soap