[spyne] Complex data types and inheritance

Burak Arslan burak.arslan at arskom.com.tr
Thu Jun 19 08:58:03 UTC 2014


On 06/10/14 23:39, Alex Railean wrote:
> Multiple inheritance seems to be the cause.
>
>

Hi Alex,

You won't like this but multiple inheritance is not supposed to work.
The reason your code worked was because the mi check got bypassed. I've
fixed it.

You can share fields with mixins though. I fixed a couple of other
issues with the code you posted and also showed how you can use mixins.

Here are the changes I made:
https://gist.github.com/plq/5c009523aa942212337e/revisions

The final version is also below for completeness.

Best regards,
Burak

=====================

import logging
from uuid import uuid4
from spyne.application import Application
from spyne.decorator import rpc
from spyne.protocol.json import JsonDocument
from spyne.protocol.http import HttpRpc
from spyne.service import ServiceBase
from spyne.model.primitive import String, Integer, Uuid, Unicode
from spyne.model.complex import ComplexModel
from spyne.server.wsgi import WsgiApplication



class BaseOne(ComplexModel):
        requestId = Uuid

class BaseTwo(ComplexModel):
        __mixin__ = True

        unitType = Unicode
        unitValue = Unicode

class InheritedResponse(BaseOne):
        something = String
        poetic = String

class DualInheritedResponse(InheritedResponse, BaseTwo):
        anotherField = Unicode

print DualInheritedResponse.get_flat_type_info(DualInheritedResponse)

########################
class CascadedA(BaseTwo):
        firstChild = Unicode

class CascadedB(CascadedA):
        lastChild = Unicode


class DemoService(ServiceBase):
        @rpc(Integer, _returns=DualInheritedResponse)
        def DemoFunction(ctx, number):
                response = DualInheritedResponse()
                response.requestId = uuid4()
                response.something = 'The Glasgow opening'
                response.poetic = 'revolutionized checkers'
                response.anotherField = 'Test'
                return response

        @rpc(Integer, _returns=CascadedB)
        def DemoFunctionEx(ctx, number):

                response = CascadedB()
                response.unitType = 'type'
                response.unitValue = 'value'
                response.firstChild = 'The Glasgow opening'
                response.lastChild = 'revolutionized checkers'
                return response





if __name__ == '__main__':
        from wsgiref.simple_server import make_server
        logging.basicConfig(level=logging.DEBUG)

        application = Application([DemoService], 'SpyneDemo.http',
                                in_protocol=HttpRpc(validator='soft'),
                                out_protocol=JsonDocument(ignore_wrappers=True),
                )

        wsgi_application = WsgiApplication(application)

        server = make_server('', 8000, wsgi_application) #any interface

        logging.info("listening at all interfaces on port 8000")
        logging.info("wsdl is at: http://ANY:8000/?wsdl")

        server.serve_forever()




More information about the people mailing list