How to use the spyne.Application function in spyne

To help you get started, we’ve selected a few spyne examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Linutronix / elbe / elbepack / daemons / soap / __init__.py View on Github external
from elbepack.projectmanager import ProjectManager

from .esoap import ESoap

try:
    from spyne import Application
    from spyne.protocol.soap import Soap11
    from spyne.server.wsgi import WsgiApplication
except ImportError as e:
    print("failed to import spyne", file=sys.stderr)
    print("please install python(3)-spyne", file=sys.stderr)
    sys.exit(20)



class EsoapApp(Application):
    def __init__(self, *args, **kargs):
        Application.__init__(self, *args, **kargs)
        self.pm = ProjectManager("/var/cache/elbe")


class MySession (SessionMiddleware, SimplePlugin):
    def __init__(self, app, pm, engine):
        self.pm = pm
        SessionMiddleware.__init__(self, app)

        SimplePlugin.__init__(self, engine)
        self.subscribe()

    def stop(self):
        self.pm.stop()
github arskom / spyne / examples / sql_crud_simple.py View on Github external
class UserDefinedContext(object):
    def __init__(self):
        self.session = Session()


def _on_method_call(ctx):
    ctx.udc = UserDefinedContext()

def _on_method_return_object(ctx):
    ctx.udc.session.commit()

def _on_method_context_closed(ctx):
    if ctx.udc is not None:
        ctx.udc.session.close()

application = Application([TCrudService(User, 'user')],
                                    tns='spyne.examples.sql_crud',
                                    in_protocol=HttpRpc(validator='soft'),
                                    out_protocol=YamlDocument())

application.event_manager.add_listener('method_call', _on_method_call)
application.event_manager.add_listener('method_return_object',
                                                      _on_method_return_object)
application.event_manager.add_listener("method_context_closed",
                                                      _on_method_context_closed)


if __name__ == '__main__':
    from wsgiref.simple_server import make_server

    wsgi_app = WsgiApplication(application)
    server = make_server('127.0.0.1', 8000, wsgi_app)
github arskom / spyne / examples / multiple_protocols / server.py View on Github external
rest = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=HttpRpc())

    xml = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=XmlDocument())

    soap = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=Soap11())

    html = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=HtmlMicroFormat())

    png = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=PngClock())

    svg = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=SvgClock())

    json = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=JsonDocument())

    jsoni = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=JsonDocument(ignore_wrappers=False))

    jsonl = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=JsonDocument(complex_as=list))

    jsonil = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(),
        out_protocol=JsonDocument(ignore_wrappers=False, complex_as=list))

    msgpack_obj = Application([MultiProtService], tns=tns,
github abilian / olapy / olapy / core / services / xmla.py View on Github external
def get_spyne_app(discover_request_hanlder, execute_request_hanlder):
    """
    :return: spyne  Application
    """
    return Application(
        [XmlaProviderService],
        "urn:schemas-microsoft-com:xml-analysis",
        in_protocol=XmlaSoap11(validator="soft"),
        out_protocol=XmlaSoap11(validator="soft"),
        config={
            "discover_request_hanlder": discover_request_hanlder,
            "execute_request_hanlder": execute_request_hanlder,
        },
github arskom / spyne / examples / multiple_protocols / server.py View on Github external
png = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=PngClock())

    svg = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=SvgClock())

    json = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=JsonDocument())

    jsoni = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=JsonDocument(ignore_wrappers=False))

    jsonl = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=JsonDocument(complex_as=list))

    jsonil = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(),
        out_protocol=JsonDocument(ignore_wrappers=False, complex_as=list))

    msgpack_obj = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=MessagePackDocument())

    msgpack_rpc = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=MessagePackRpc())

    yaml = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=YamlDocument())

    dyn = Application([DynProtService], tns=tns,
        in_protocol=HttpRpc(validator='soft'), out_protocol=HttpRpc())

    DynProtService.protocols = {
github abilian / olapy / micro_bench / __init__.py View on Github external
def main():
    file = open('bench_result' +
                str(datetime.datetime.now().strftime("%Y-%m-%d-%H-%M")), 'w')
    gen = CubeGen(number_dimensions=3, rows_length=1000, columns_length=5)
    gen.generate_csv(gen.generate_cube(3, 1000))
    XmlaProviderService.discover_tools.change_catalogue(CUBE_NAME)
    mbench = MicBench()

    file.write("Benchmarks are made with cpu :\n")
    file.write(cpuinfo.get_cpu_info()['brand'] + "\n\n")

    application = Application(
        [XmlaProviderService],
        'urn:schemas-microsoft-com:xml-analysis',
        in_protocol=Soap11(validator='soft'),
        out_protocol=Soap11(validator='soft'))
    wsgi_application = WsgiApplication(application)
    server = WSGIServer(application=wsgi_application, host=HOST, port=PORT)
    server.start()

    provider = xmla.XMLAProvider()
    conn = provider.connect(location=server.url)

    t = PrettyTable(['Query', 'olapy execution time'])

    cmd = """
            SELECT
            FROM [""" + CUBE_NAME + """]
github arskom / spyne / examples / multiple_protocols / server.py View on Github external
in_protocol=HttpRpc(), out_protocol=JsonDocument())

    jsoni = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=JsonDocument(ignore_wrappers=False))

    jsonl = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=JsonDocument(complex_as=list))

    jsonil = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(),
        out_protocol=JsonDocument(ignore_wrappers=False, complex_as=list))

    msgpack_obj = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=MessagePackDocument())

    msgpack_rpc = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=MessagePackRpc())

    yaml = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=YamlDocument())

    dyn = Application([DynProtService], tns=tns,
        in_protocol=HttpRpc(validator='soft'), out_protocol=HttpRpc())

    DynProtService.protocols = {
        'json': Tsetprot(JsonDocument(dyn)),
        'xml': Tsetprot(XmlDocument(dyn)),
        'yaml': Tsetprot(YamlDocument(dyn)),
        'soap': Tsetprot(Soap11(dyn)),
        'html': Tsetprot(HtmlMicroFormat(dyn)),
        'png': Tsetprot(PngClock(dyn)),
        'svg': Tsetprot(SvgClock(dyn)),
github arskom / spyne / examples / existing_api.py View on Github external
# `a` and `b` arguments and not the `self` argument.
    randint = srpc(M(Integer), M(Integer), _returns=Integer,
                                               _args=('a', 'b'))(random.randint)

    # We need the _args argument here because `getrandbits` is a builtin, which
    # means it's not ready for introspection.
    randbits = srpc(M(UnsignedInteger), _returns=UnsignedInteger,
                                               _args=('k',))(random.getrandbits)


if __name__=='__main__':
    from wsgiref.simple_server import make_server

    logging.basicConfig(level=logging.DEBUG)

    application = Application([RandomService], 'spyne.examples.hello.http',
             in_protocol=HttpRpc(validator='soft'), out_protocol=HttpRpc())

    server = make_server('127.0.0.1', 8000, WsgiApplication(application))

    logging.info("listening to http://127.0.0.1:8000")
    logging.info("wsdl is at: http://localhost:8000/?wsdl")

    server.serve_forever()
github arskom / spyne / examples / multiple_protocols / server.py View on Github external
html = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=HtmlMicroFormat())

    png = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=PngClock())

    svg = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=SvgClock())

    json = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=JsonDocument())

    jsoni = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=JsonDocument(ignore_wrappers=False))

    jsonl = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=JsonDocument(complex_as=list))

    jsonil = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(),
        out_protocol=JsonDocument(ignore_wrappers=False, complex_as=list))

    msgpack_obj = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=MessagePackDocument())

    msgpack_rpc = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=MessagePackRpc())

    yaml = Application([MultiProtService], tns=tns,
        in_protocol=HttpRpc(), out_protocol=YamlDocument())

    dyn = Application([DynProtService], tns=tns,
github arskom / spyne / examples / log.py View on Github external
class SomeService(Service):
    @rpc()
    def server_exception(ctx):
        raise Exception("boo!")

    @rpc()
    def server_fault(ctx):
        raise Fault("Server", "boo and you know it!")

    @rpc()
    def client_fault(ctx):
        raise Fault("Client", "zzzz...")


server = NullServer(Application([SomeService], 'spyne.examples.logging'))


if __name__ == "__main__":
    import logging
    logging.basicConfig(level=logging.DEBUG)

    logging.info(G("all fault tracebacks are logged"))
    logging.getLogger('spyne.application').setLevel(logging.DEBUG)

    try:
        server.service.server_exception()
    except:
        pass
    try:
        server.service.server_fault()
    except: