[spyne] python exec function doesn't work in module spyne

hou zhehao zhehao.hou at outlook.com
Thu Aug 2 08:33:02 UTC 2018


Dear list:
       I tried to set up a web service, via which the user give a block of python code, and the service feed something back, but it seems the python function exec doesn't work in spyne, here is my code:

#!/usr/bin/env`` python

# encoding: utf8



import logging

logging.basicConfig(level=logging.DEBUG)

from spyne.decorator import srpc

from spyne import Application, rpc, ServiceBase, \

    Integer, Unicode

from spyne import Iterable

from spyne.protocol.http import HttpRpc

from spyne.protocol.json import JsonDocument

from spyne.server.wsgi import WsgiApplication





class Test(ServiceBase):

    @rpc(Integer, _returns=Iterable(Unicode))

    def say_hello(self, times):

        for i in range(times):

            yield "say hello."

            print(i)



    @rpc(Unicode, _returns=Unicode)

    def execcodes(ctx, codes):

        exec(codes)

        print('|'.join(locals())

        print('|'.join(globals())



if __name__ == '__main__':

    from wsgiref.simple_server import make_server

    logging.basicConfig(level=logging.DEBUG)



    application = Application([Test], 'spyne.examples.hello.http',



                            in_protocol=HttpRpc(validator='soft'),



                            out_protocol=JsonDocument(ignore_wrappers=True),

                            )



    wsgi_application = WsgiApplication(application)



    server = make_server('0.0.0.0', 22346, wsgi_application)



    logging.info("listening to http://127.0.0.1:22346")

    logging.info("wsdl is at: http://localhost:22346/?wsdl")



    server.serve_forever()


I trigger the function execcodes by 127.0.0.1:22346/Test?execcodes='a=1\nb=2\nprint(a+b)\n',  there was no error about exec raised, but there was also no print in logging, and I can't find a and b in both locals and globals, so i'm confused whether my codes executed? if it is executed, where can I find the variables?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.spyne.io/archives/people/attachments/20180802/c3cb4b8c/attachment.html>


More information about the people mailing list