请问在 eurasia 3.1 中如何混用 httpserver 和 wsgiserver 呢?

11 views
Skip to first unread message

bawbaw hu

unread,
Dec 12, 2010, 4:32:18 AM12/12/10
to eurasi...@googlegroups.com
 之前的 eurasia 3.0 有个范例是 在 httpserver 中用个 wsgi 对像转换成 httpserver handle ,请问eurasia 3.1 中如何操作呢?

沈崴

unread,
Dec 12, 2010, 7:15:39 AM12/12/10
to eurasia-users
3.1 中没有对应的接口,到 wsgi 的转换可以这么写:

from weakref import proxy
def handler(httpfile):
env = httpfile.environ
env['wsgi.input'] = proxy(httpfile)
def start_response(status, headers, exc_info=None):
if exc_info:
try:
if httpfile.headers_sent:
raise exc_info[0], exc_info[1], exc_info[2]
finally:
exc_info = None
elif httpfile.headers_sent:
raise AssertionError('headers already set')
httpfile.start_response(status, headers)
return httpfile.sendall
for data in app(env, start_response):
if data:
httpfile.sendall(data)
httpfile.close()

Zoom.Quiet

unread,
Dec 12, 2010, 8:10:42 AM12/12/10
to eurasi...@googlegroups.com
什么情景中需要这种转换呢?
如果是通用的,增补到文档中哈,
如果不是,增补到 特技列表中哈...

> --
> 您收到此邮件是因为您订阅了 Google 网上论坛的“eurasia-users”论坛。
> 要向此网上论坛发帖,请发送电子邮件至 eurasi...@googlegroups.com
> 要取消订阅此网上论坛,请发送电子邮件至 eurasia-user...@googlegroups.com
> 若有更多问题,请通过 http://groups.google.com/group/eurasia-users?hl=zh-CN 访问此网上论坛。
>
>

--
人生苦短, Pythonic!
俺: http://about.me/zoom.quiet
开: http://code.ijinshan.com/
豆: http://www.douban.com/group/zoomquiet
书: http://code.google.com/p/openbookproject
蟒: http://code.google.com/p/kcpycamp/wiki/PythoniCamp

bawbaw hu

unread,
Dec 12, 2010, 8:35:10 AM12/12/10
to eurasi...@googlegroups.com

想在某一 path 下使用 wsgi 的服务如 phprpc 、hprose,其它path 例如 /crossdomain.xml 时,使用httpserver
这样子有办法使用沈大那段吗?

沈崴

unread,
Dec 12, 2010, 7:41:01 PM12/12/10
to eurasia-users
看来这种需求还是需要的,准备加进代码。

On 12月12日, 下午1时35分, bawbaw hu <bawbaw...@gmail.com> wrote:
> 想在某一 path 下使用 wsgi 的服务如 phprpc 、hprose,其它path 例如 /crossdomain.xml
> 时,使用httpserver
> 这样子有办法使用沈大那段吗?

沈崴

unread,
Dec 31, 2010, 4:02:14 AM12/31/10
to eurasia-users
eurasia 现已对此类需求提供支持。

新增的接口是 wsgi(app) 返回一个普通的 http handler。

from eurasia.web import httpserver, wsgi, mainloop
def app(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['hello world!']

def handler(httpfile):
wsgihandler = wsgi(app)
wsgihandler(httpfile)

httpd = httpserver(':8080', handler)
httpd.start()
mainloop()

请重新下载快照,或者从 3.1 的 svn 更新。

文档 wsgiserver 一节已随之更新。

bawbaw hu

unread,
Jan 4, 2011, 9:38:30 PM1/4/11
to eurasi...@googlegroups.com
测试后好用的,谢谢沈大

Reply all
Reply to author
Forward
0 new messages