From ken.prows at online-rewards.com Tue Jan 8 17:01:24 2013 From: ken.prows at online-rewards.com (Ken Prows) Date: Tue, 8 Jan 2013 11:01:24 -0500 Subject: [Soap-Python] Creating a "Tree" response with spyne Message-ID: Hi, I am trying to create a spyne model with a tree data structure. Basically, this is what I'd like to do: class Category(ComplexModel): category_id = Integer(min_occurs=1, max_occurs=1, nillable=False) name = Unicode(min_occurs=1, max_occurs=1, nillable=False) children = Array(Category) The above obviously doesn't work. However, I noticed that there is a SelfReference data type. So I tried this: class Category(ComplexModel): category_id = Integer(min_occurs=1, max_occurs=1, nillable=False) name = Unicode(min_occurs=1, max_occurs=1, nillable=False) children = Array(SelfReference) But that dies with: File "/Library/Python/2.7/site-packages/spyne-2.10.0-py2.7.egg/spyne/model/complex.py", line 685, in __new__ if serializer.Attributes.max_occurs == 1: AttributeError: type object 'SelfReference' has no attribute 'Attributes' So it looks like SelfReference doesn't work within an Array. Is there any other way to do this? If not, would it be possible to add support for Array(SelfReference) in a future version of spyne? Thanks, Ken From burak.arslan at arskom.com.tr Tue Jan 8 17:13:16 2013 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Tue, 08 Jan 2013 18:13:16 +0200 Subject: [Soap-Python] Creating a "Tree" response with spyne In-Reply-To: References: Message-ID: <50EC459C.3040002@arskom.com.tr> 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? > 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 From ken.prows at online-rewards.com Tue Jan 8 17:54:05 2013 From: ken.prows at online-rewards.com (Ken Prows) Date: Tue, 8 Jan 2013 11:54:05 -0500 Subject: [Soap-Python] Creating a "Tree" response with spyne In-Reply-To: <50EC459C.3040002@arskom.com.tr> References: <50EC459C.3040002@arskom.com.tr> Message-ID: On Tue, Jan 8, 2013 at 11:13 AM, Burak Arslan 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 From burak.arslan at arskom.com.tr Tue Jan 8 18:38:17 2013 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Tue, 08 Jan 2013 19:38:17 +0200 Subject: [Soap-Python] Creating a "Tree" response with spyne In-Reply-To: References: <50EC459C.3040002@arskom.com.tr> Message-ID: <50EC5989.4060604@arskom.com.tr> On 01/08/13 18:54, Ken Prows wrote: > Unfortunately, Category._type_info['children'] = Array(Category) dies with: Hi, Sorry but I can't reproduce this. Here's the test: https://github.com/plq/spyne/commit/b61cdbcec4245381dc9b98cb2db88ccf03298c6f I see that you're running Spyne trunk, (2.10 isn't released yet) can you try this test after either getting the latest code from my fork or reverting back to a stable Spyne? Here are the instructions for testing on a stable Spyne: git clone git://github.com/arskom/spyne cd spyne git checkout spyne-2.9.3 python -c "import spyne; assert spyne.__file__ == 'spyne/__init__.py'" && \ spyne/test/model/test_complex.py TestSelfRefence.test_self_referential_array_workaround Here's what I see: ============== {'Category': {'children': {'Category': [{'children': {}, 'id': 0}, {'children': {}, 'id': 1}]}, 'id': None}} . ---------------------------------------------------------------------- Ran 1 test in 0.001s OK ============== Thanks, Burak -------------- next part -------------- An HTML attachment was scrubbed... URL: From ken.prows at online-rewards.com Tue Jan 8 20:56:36 2013 From: ken.prows at online-rewards.com (Ken Prows) Date: Tue, 8 Jan 2013 14:56:36 -0500 Subject: [Soap-Python] Creating a "Tree" response with spyne In-Reply-To: <50EC5989.4060604@arskom.com.tr> References: <50EC459C.3040002@arskom.com.tr> <50EC5989.4060604@arskom.com.tr> Message-ID: On Tue, Jan 8, 2013 at 12:38 PM, Burak Arslan wrote: > On 01/08/13 18:54, Ken Prows wrote: > > Unfortunately, Category._type_info['children'] = Array(Category) dies with: > > > Hi, > > Sorry but I can't reproduce this. Here's the test: > > https://github.com/plq/spyne/commit/b61cdbcec4245381dc9b98cb2db88ccf03298c6f > > I see that you're running Spyne trunk, (2.10 isn't released yet) can you try > this test after either getting the latest code from my fork or reverting > back to a stable Spyne? > > Here are the instructions for testing on a stable Spyne: > > git clone git://github.com/arskom/spyne > cd spyne > git checkout spyne-2.9.3 > python -c "import spyne; assert spyne.__file__ == 'spyne/__init__.py'" && \ > spyne/test/model/test_complex.py > TestSelfRefence.test_self_referential_array_workaround > > Here's what I see: > > ============== > > {'Category': {'children': {'Category': [{'children': {}, 'id': 0}, > {'children': {}, 'id': 1}]}, > 'id': None}} > . > ---------------------------------------------------------------------- > Ran 1 test in 0.001s > > OK > > ============== > > Thanks, > Burak > Thanks for all your help. I did this and am still getting the same error: $ sudo pip uninstall spyne $ sudo pip install https://github.com/arskom/spyne/tarball/spyne-2.9.3 $ python tree_test.py ... File "/Library/Python/2.7/site-packages/spyne/model/_base.py", line 212, in resolve_namespace not cls.is_default(cls)): File "/Library/Python/2.7/site-packages/spyne/model/primitive.py", line 337, in is_default and cls.Attributes.gt == Decimal.Attributes.gt 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 This is tree_test.py: http://pastebin.com/0gpprG8V Ken From burak.arslan at arskom.com.tr Tue Jan 8 22:51:35 2013 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Tue, 08 Jan 2013 23:51:35 +0200 Subject: [Soap-Python] Creating a "Tree" response with spyne In-Reply-To: References: <50EC459C.3040002@arskom.com.tr> <50EC5989.4060604@arskom.com.tr> Message-ID: <50EC94E7.1090800@arskom.com.tr> On 01/08/13 21:56, Ken Prows wrote: > I did this and am still getting the same error: Hi, I did get to reproduce it this time. This was a serious and obvious bug, I can't believe it went unnoticed all this time :) Fix in trunk. Thanks for your help. Best, Burak From ken.prows at online-rewards.com Wed Jan 9 20:59:26 2013 From: ken.prows at online-rewards.com (Ken Prows) Date: Wed, 9 Jan 2013 14:59:26 -0500 Subject: [Soap-Python] using ?wsdl with WsgiMounter Message-ID: Hello list, I am working on having my service support multiple protocols. To do this I am working off a slightly modified version of this example: https://github.com/arskom/spyne/blob/master/examples/multiple_protocols/server.py Here is my code: http://pastebin.com/Wz02Qbnw When I run this and go to http://127.0.0.1:9910/soap/?wsdl I see this as the application location: I am then pointing the wsdl2java.sh script from the Axis2 project at the wsdl: sh wsdl2java.sh -uri http://127.0.0.1:9910/soap/?wsdl -o ~/Documents/workspace/spyne_test/ -uw The objects that get generated end up trying to contact "http://127.0.0.1:9910soap/" which doesn't work without the "/" between the port and "soap". Did I do something wrong? Thanks in advance!, Ken From burak.arslan at arskom.com.tr Wed Jan 9 23:13:54 2013 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Thu, 10 Jan 2013 00:13:54 +0200 Subject: [Soap-Python] using ?wsdl with WsgiMounter In-Reply-To: References: Message-ID: <50EDEBA2.8090804@arskom.com.tr> Hi Ken, Thanks for finding another bug :) Fix is in the trunk. Best, Burak On 01/09/13 21:59, Ken Prows wrote: > Hello list, > > I am working on having my service support multiple protocols. > To do this I am working off a slightly modified version of this example: > https://github.com/arskom/spyne/blob/master/examples/multiple_protocols/server.py > > Here is my code: http://pastebin.com/Wz02Qbnw > > When I run this and go to http://127.0.0.1:9910/soap/?wsdl I see this > as the application location: > > > > > > > > I am then pointing the wsdl2java.sh script from the Axis2 project at the wsdl: > sh wsdl2java.sh -uri http://127.0.0.1:9910/soap/?wsdl -o > ~/Documents/workspace/spyne_test/ -uw > > The objects that get generated end up trying to contact > "http://127.0.0.1:9910soap/" which doesn't work without the "/" > between the port and "soap". > > Did I do something wrong? > > Thanks in advance!, > Ken > _______________________________________________ > Soap mailing list > Soap at python.org > http://mail.python.org/mailman/listinfo/soap From ken.prows at online-rewards.com Mon Jan 14 23:33:27 2013 From: ken.prows at online-rewards.com (Ken Prows) Date: Mon, 14 Jan 2013 17:33:27 -0500 Subject: [Soap-Python] spyne naming conventions Message-ID: Hello, I am having a lot of fun with spyne. I used to despise having to deal with SOAP, but spyne changed that. (Part of that is also due to the helpfulness of Burak on this list! :) Anyway, I am wondering if there are any naming conventions regarding how to name model classes, fields and methods. Does spyne prefer camelcase or underscores? Most of the examples have methods named with underscores. However, when I get back a JsonDocument response, it seems to expect that the methods were named using camelcase. As an example, I have a method called "catalog_tree." When I get back the response for this method, it looks like: {"catalog_treeResponse": {"catalog_treeResult": { ... }} So I am leaning toward naming my classes/methods using camelcase, and my fields using underscores...unless there are some recommendations regarding this. Thanks!, Ken From burak.arslan at arskom.com.tr Tue Jan 15 01:01:06 2013 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Tue, 15 Jan 2013 02:01:06 +0200 Subject: [Soap-Python] spyne naming conventions In-Reply-To: References: Message-ID: <50F49C42.6010700@arskom.com.tr> Hi Ken, On 01/15/13 00:33, Ken Prows wrote: > Hello, > > I am having a lot of fun with spyne. I used to despise having to deal > with SOAP, but spyne changed that. (Part of that is also due to the > helpfulness of Burak on this list! :) Thanks! I'm also having a lot of fun with Spyne, that may explain why :) 2.10 is going to be huge, I tell you :) > Anyway, I am wondering if there are any naming conventions regarding > how to name model classes, fields and methods. Does spyne prefer > camelcase or underscores? > > Most of the examples have methods named with underscores. However, > when I get back a JsonDocument response, it seems to expect that the > methods were named using camelcase. As an example, I have a method > called "catalog_tree." When I get back the response for this method, > it looks like: > > {"catalog_treeResponse": {"catalog_treeResult": { ... }} > > So I am leaning toward naming my classes/methods using camelcase, and > my fields using underscores...unless there are some recommendations > regarding this. Heh, that does look ugly doesn't it? Well, those prefixes have been the same since as far as I can remember, and I preferred not to touch them, as that'd almost completely change the generated WSDL for no good reason. However, being the kind who can't really stand inconsistencies in my code, this is the first thing my in-house library code does before everything else imports Spyne: try: import spyne.const.suffix spyne.const.suffix.RESPONSE_SUFFIX = "_response" spyne.const.suffix.RESULT_SUFFIX = "_result" spyne.const.suffix.TYPE_SUFFIX = "_type" except ImportError: pass (hmmm. this must be from before I put the setters there. anyway...) See here for details: https://github.com/plq/spyne/blob/master/spyne/const/suffix.py My humble suggestion in this regard would be to do as I do and follow PEP8, but hey, Spyne is your tool as much as it is mine, so it's going to be your decision. Best regards, Burak From ken.prows at online-rewards.com Fri Jan 18 22:19:46 2013 From: ken.prows at online-rewards.com (Ken Prows) Date: Fri, 18 Jan 2013 16:19:46 -0500 Subject: [Soap-Python] spyne - outputting different domains in wsdl Message-ID: Hi, I have another spyne question (big surprise, huh?:) I found out from here [http://www.mail-archive.com/soap at python.org/msg00582.html] that the wsdl file is generated once and then cached. That is nice, of course. My issue is that I want to allow multiple sub-domains to access the same service. Currently, the first sub-domain that hits ?wsdl will cause that particular sub-domain to be embedded in the wsdl's element. Later, when a different sub-domain asks for the ?wsdl, it will incorrectly get the sub-domain from the first request. My attempt to remedy this was to sub-class the Wsdl11 interface class and override the "get_interface_document" method. I wanted to change it so that before returning the cached etree from __wsdl, it would change the soap:address element to be the domain from the current request. There does not seem to be any way to tell the application to use a different interface though. Is there another, more obvious way to solve this? If not, I will likely just modify the source. I wanted to ask here first though. As always, thanks!, Ken From burak.arslan at arskom.com.tr Sat Jan 19 00:10:34 2013 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Sat, 19 Jan 2013 01:10:34 +0200 Subject: [Soap-Python] spyne - outputting different domains in wsdl In-Reply-To: References: Message-ID: <50F9D66A.1070108@arskom.com.tr> On 01/18/13 23:19, Ken Prows wrote: > Later, when a different sub-domain asks for > the ?wsdl, it will incorrectly get the sub-domain from > the first request. Hi Ken, There's not much you can do without patching Spyne there. Did you also stumble upon the thread at http://mail.python.org/pipermail//soap/2012-September/000980.html ? You can implement a similar event. Send a patch my way and we'll talk. Best, Burak From ken.prows at online-rewards.com Sat Jan 19 01:23:05 2013 From: ken.prows at online-rewards.com (Ken Prows) Date: Fri, 18 Jan 2013 19:23:05 -0500 Subject: [Soap-Python] spyne - outputting different domains in wsdl In-Reply-To: References: Message-ID: On Fri, Jan 18, 2013 at 4:19 PM, Ken Prows wrote: > I found out from here > [http://www.mail-archive.com/soap at python.org/msg00582.html] that the > wsdl file is generated once and then cached. That is nice, of course. > My issue is that I want to allow multiple sub-domains to access the > same service. Currently, the first sub-domain that hits ?wsdl will > cause that particular sub-domain to be embedded in the wsdl's > element. Later, when a different sub-domain asks for > the ?wsdl, it will incorrectly get the sub-domain from > the first request. > > My attempt to remedy this was to sub-class the Wsdl11 interface class > and override the "get_interface_document" method. I wanted to change > it so that before returning the cached etree from __wsdl, it would > change the soap:address element to be the domain from the current > request. There does not seem to be any way to tell the application to > use a different interface though. > > Is there another, more obvious way to solve this? If not, I will > likely just modify the source. I wanted to ask here first though. > In the meantime, I ended up hacking it up: https://github.com/xevo/spyne/blob/master/spyne/server/wsgi.py All the changes are in __handle_wsdl_request. I know this only fixes it for the wsdl server type. For now though, it works for me. Ken