I'm trying to use a combination of Spyne and Suds(although I'm not very particular on using Suds) to create a module which functions as a middleman between two SOAP entities.
There is a client, C, which connects to server S, calls a method M, which returns a ComplexType, D. The same data object needs to be sent by S to another server S1. Of course there is a method M1 which takes D type as parameter on server S1. The problem I'm facing is I can't just send D to S1, without making a conversion to a type which is recognized by Suds.
Is there a smart way to do this, without copying field by field the attributes of D from one "type" to the other?
You can indeed convert incoming objects to dicts and pass them to suds. But Spyne already offers both ways object<==>dict conversion facitilies.
To convert to dict you can use spyne.util.dictdoc
.
e.g.
from spyne.model.complex import ComplexModel
from spyne.model.primitive import Integer
class B(ComplexModel):
c = Integer
class A(ComplexModel):
a = Integer
b = B
from spyne.util.dictdoc import get_object_as_dict
print get_object_as_dict(A(a=4, b=B(c=5)), A)
# prints {'a': 4, 'b': {'c': 5}}
get_object_as_dict(A(a=4, b=B(c=5)), A, ignore_wrappers=False)
# prints {'A': {'a': 4, 'b': {'B': {'c': 5}}}}
I hope it helps.