SHARE
TWEET

Spyne multiple inheritance sample

a guest Jun 10th, 2014 254 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import logging
  2. from uuid import uuid4
  3. from spyne.application import Application
  4. from spyne.decorator import rpc
  5. from spyne.protocol.json import JsonDocument
  6. from spyne.protocol.http import HttpRpc
  7. from spyne.service import ServiceBase
  8. from spyne.model.primitive import String, Integer, Uuid, Unicode
  9. from spyne.model.complex import ComplexModel
  10. from spyne.server.wsgi import WsgiApplication
  11.  
  12.  
  13.  
  14. class BaseOne(ComplexModel):
  15.         requestId = Uuid
  16.  
  17. class BaseTwo(ComplexModel):
  18.         unitType = Unicode
  19.         unitValue = Unicode
  20.  
  21. class InheritedResponse(BaseOne):
  22.         something = String
  23.         poetic = String
  24.  
  25. class DualInheritedResponse(BaseOne, BaseTwo):
  26.         anotherField = Unicode
  27.  
  28. ########################
  29. class CascadedA(BaseTwo):
  30.         firstChild = Unicode
  31.  
  32. class CascadedB(CascadedA):
  33.         lastChild = Unicode
  34.  
  35.  
  36. class DemoService(ServiceBase):
  37.         @rpc(Integer, _returns=DualInheritedResponse)
  38.         def DemoFunction(ctx, number):
  39.                 response = DualInheritedResponse()
  40.                 response.requestId = uuid4()
  41.                 response.something = 'The Glasgow opening'
  42.                 response.poetic = 'revolutionized checkers'
  43.                 response.anotherField = 'Test'
  44.                 return response
  45.  
  46.         @rpc(Integer, _returns=lastChild)
  47.         def DemoFunctionEx(ctx, number):
  48.  
  49.                 response = CascadedB()
  50.                 response.unitType = 'type'
  51.                 response.unitValue = 'value'
  52.                 response.firstChild = 'The Glasgow opening'
  53.                 response.lastChild = 'revolutionized checkers'
  54.                 return response
  55.  
  56.  
  57.  
  58.  
  59.  
  60. if __name__ == '__main__':
  61.         from wsgiref.simple_server import make_server
  62.         logging.basicConfig(level=logging.DEBUG)
  63.  
  64.         application = Application([DemoService], 'SpyneDemo.http',
  65.                                 in_protocol=JsonDocument(validator='soft'),
  66.                                 out_protocol=JsonDocument(ignore_wrappers=True),
  67.                 )
  68.  
  69.         wsgi_application = WsgiApplication(application)
  70.  
  71.         server = make_server('', 8000, wsgi_application) #any interface
  72.  
  73.         logging.info("listening at all interfaces on port 8000")
  74.         logging.info("wsdl is at: http://ANY:8000/?wsdl")
  75.  
  76.         server.serve_forever()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top