[Soap-Python] Creating a "Tree" response with spyne
Ken Prows
ken.prows at online-rewards.com
Tue Jan 8 17:54:05 CET 2013
On Tue, Jan 8, 2013 at 11:13 AM, Burak Arslan
<burak.arslan at arskom.com.tr> wrote:
> On 01/08/13 18:01, Ken Prows wrote:
>>
>> So it looks like SelfReference doesn't work within an Array.
>
> Hi there,
>
> That's correct. What you can do instead:
>
> class Category(ComplexModel):
> category_id = Integer(min_occurs=1, max_occurs=1, nillable=False)
> name = Unicode(min_occurs=1, max_occurs=1, nillable=False)
>
> Category._type_info['children'] = Array(Category)
>
> Does it help?
>
Thank you for the super quick response! :)
Unfortunately, Category._type_info['children'] = Array(Category) dies with:
...
File "/Library/Python/2.7/site-packages/spyne-2.10.0-py2.7.egg/spyne/model/complex.py",
line 591, in resolve_namespace
v.resolve_namespace(v, default_ns)
File "/Library/Python/2.7/site-packages/spyne-2.10.0-py2.7.egg/spyne/model/_base.py",
line 212, in resolve_namespace
not cls.is_default(cls)):
File "/Library/Python/2.7/site-packages/spyne-2.10.0-py2.7.egg/spyne/model/primitive.py",
line 208, in is_default
and cls.Attributes.max_len == Unicode.Attributes.max_len
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/decimal.py",
line 868, in __eq__
if self._check_nans(other, context):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/decimal.py",
line 738, in _check_nans
self_is_nan = self._isnan()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/decimal.py",
line 709, in _isnan
if exp == 'n':
RuntimeError: maximum recursion depth exceeded in cmp
>> would it be possible to add support
>> for Array(SelfReference) in a future version of spyne?
>
>
> If you write the test for it, I can implement it.
>
> Best,
> Burak
>
I'm not sure exactly how I would write a test for
Array(SelfReference). Below is my shot at it though.
In test_complex.py, within the TestComplexModel class:
def test_tree_class(self):
class Category(ComplexModel):
category_id = Integer
name = String
children = Array(SelfReference)
parent = Category()
parent.id = 1
parent.name = "Electronics"
parent.children = []
child1 = Category()
child1.id = 2
child1.name = "TVs"
parent.children.append(child1)
child2 = Category()
child2.id = 3
child2.name = "Cameras"
parent.children.append(child2)
assert (len(parent.children) == 2)
assert (isinstance(parent, Category))
assert (isinstance(parent.children[0], Category))
assert (isinstance(parent.children[1], Category))
The asserts probably aren't really needed. If the code doesn't die, I
don't think those asserts could ever fail.
Thanks again for the help,
Ken
More information about the Soap
mailing list