我有一个有效的web.py应用程序和一个有效的Spyne应用程序。我想在匹配某个网址时向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())
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()
答案 0 :(得分:1)
您需要实现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,
)
我希望有所帮助。