Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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):
- unitType = Unicode
- unitValue = Unicode
- class InheritedResponse(BaseOne):
- something = String
- poetic = String
- class DualInheritedResponse(BaseOne, BaseTwo):
- anotherField = Unicode
- ########################
- 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=lastChild)
- 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=JsonDocument(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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement