Last active
August 29, 2015 14:02
-
-
Save plq/5c009523aa942212337e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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