From roberto.maurizzi at gmail.com Tue Jul 21 03:49:02 2015 From: roberto.maurizzi at gmail.com (Roberto Maurizzi) Date: Tue, 21 Jul 2015 07:49:02 +0400 Subject: [spyne] Again, Factory with deepcopy? Message-ID: Hello all, a few months ago I wrote here about an issue I was having with the "class generator" pattern Spyne requires when a service needs to be exposed with multiple protocols (i.e SOAP and JSON). I though that simply "deepcopying" my ServiceBase-derived class was going to be OK... but it turns out that deepcopy can't copy classes but only instanced objects: class A(): pass B = A id(B) 140476831964600 C = copy.deepcopy(A) id(C) 140476831964600 The funny part is that the service was working correctly, apparently, serving both SOAP and JSON: I didn't test it extensively, but calling a SOAP method and then the same as JSON was part of my standard development tests. I found out the problem when I needed to add user verification: I used a message header with username and password for SOAP, registring the header only for my SOAP class, with the plan to add HTTP based authentication for JSON... but then JSON stopped working because it required 'username' and 'password' parameters in its HTTP GET... not nice :-) A quick check showed the issue: all the classes are the same, so the Service.event_manager..add_listener added my header-checking code for all the different protocols... On StackExchange I found the suggested method to 'deepcopy' a class is to create a new class that subclasses it without changes, but we can't do that with Spyne due to how its 'magic' works :-) My only issue with this is that, "since nested classes are rarely used in Python", Sphinx can't extract the documentation from the class nested inside the generator function: since this documentation is the protocol implementation, I'd really like to be able to extract it from the sources automatically. I was wondering if anyone ever had this problem and found a simple workaround, maybe using some Python technique I still don't know about (the less simple 'workaround' is is to patch Sphinx's autodoc so that it can recursively explore functions for inner members documentation, but right now it might take a while for me to be able to do that). Thank you! Roberto Maurizzi -------------- next part -------------- An HTML attachment was scrubbed... URL: From burak.arslan at arskom.com.tr Tue Jul 28 13:32:41 2015 From: burak.arslan at arskom.com.tr (Burak Arslan) Date: Tue, 28 Jul 2015 16:32:41 +0300 Subject: [spyne] Again, Factory with deepcopy? In-Reply-To: References: Message-ID: <55B78479.9030308@arskom.com.tr> Hello, Sorry for the late reply. On 07/21/15 06:49, Roberto Maurizzi wrote: > Hello all, > > a few months ago I wrote here about an issue I was having with the > "class generator" pattern Spyne requires when a service needs to be > exposed with multiple protocols (i.e SOAP and JSON). > > I though that simply "deepcopying" my ServiceBase-derived class was > going to be OK... but it turns out that deepcopy can't copy classes > but only instanced objects: > > class A(): > pass > > B = A > id(B) > 140476831964600 > > C = copy.deepcopy(A) > id(C) > 140476831964600 Ah. Interesting. Ok I added this bug to 2.12 milestone: https://github.com/arskom/spyne/milestones/2.12 In the mean time try to add docs to the factory function instead of the service class itself and set service class doc manually. off the top of my head: def SomeServiceFactory(): """Some doc""" class SomeService(ServiceBase): @rpc def some_service(ctx): # etc... SomeService.__doc__ = SomeServiceFactory.__doc__ return SomeService Best, Burak -------------- next part -------------- An HTML attachment was scrubbed... URL: