Skip to content

Instantly share code, notes, and snippets.

@plq
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plq/5c009523aa942212337e to your computer and use it in GitHub Desktop.
Save plq/5c009523aa942212337e to your computer and use it in GitHub Desktop.
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()
$ curl -s http://localhost:8000/DemoFunction | python -m json.tool
{
"anotherField": "Test",
"poetic": "revolutionized checkers",
"requestId": "b0742d38-f959-4ac7-a74a-6a92fc6e8d33",
"something": "The Glasgow opening"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment