我有一个可以工作的web.py应用程序和一个可以工作的Spyne应用程序。当与某个url匹配时,我想向spyne应用程序发出web.py路由请求。
我尝试了一个包装器as per web.py docs,但是没有成功。
在myspyne.py中:
import logging
logging.basicConfig(level=logging.DEBUG)
from spyne.application import Application
from spyne.decorator import srpc
from spyne.service import ServiceBase
from spyne.model.primitive import Integer
from spyne.model.primitive import Unicode
from spyne.model.complex import Iterable
from spyne.protocol.soap import Soap11
class HelloWorldService(ServiceBase):
@srpc(Unicode, Integer, _returns=Iterable(Unicode))
def say_hello(name, times):
for i in range(times):
yield 'Hello, %s' % name
application = Application([HelloWorldService],
tns='my.custom.ns',
in_protocol=Soap11(validator='lxml'),
out_protocol=Soap11())在myweb.py中:
urls = (
'/', 'index',
'/myspyne/(.*)', myspyne.application, # this does not work
)
class index:
def GET(self):
return "hello"
app = web.application(urls, globals(), autoreload=False)
application = app.wsgifunc()
if __name__ == '__main__':
app.run()发布于 2013-07-20 19:07:01
您需要实现一个web.py传输,或者找到一种从web.py公开wsgi应用程序的方法。您链接的文档非常旧(对我来说似乎是几十年前的事了:)。
我完全没有使用web.py的经验。但基于该文档的web.py部分,这是可行的:
def start_response(status, headers):
web.ctx.status = status
for header, value in headers:
web.header(header, value)
class WebPyTransport(WsgiApplication):
"""Class for web.py """
def GET(self):
response = self(web.ctx.environ, start_response)
return render("\n".join(response))
def POST(self):
response = self(web.ctx.environ, start_response)
return render("\n".join(response))使用此命令,您可以使用:
application = Application(...)
webpy_app = WebPyTransport(application)所以urls变成了:
urls = (
'/', 'index',
'/myspyne/(.*)', myspyne.webpy_app,
)我希望这能有所帮助。
https://stackoverflow.com/questions/17758063
复制相似问题