WSGI:start_response函数的用途是什么 [英] WSGI: what's the purpose of start_response function

查看:582
本文介绍了WSGI:start_response函数的用途是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否提供 WSGI

Could you supply a real-life example of WSGI start_response function? (Web-server provides that function to wsgi application)

我不明白介绍start_response目的.

(我已经阅读了10篇关于WSGI标准的相同文章.他们都说"WSGI标准是...",没有一个人说"以此方式设计WSGI .. .":()

(I've read like 10 identical texts about the WSGI standard. They all say "WSGI standard is..." None of them says "WSGI is designed this way in order to..." :()

推荐答案

您能否提供WSGI start_response()函数的真实示例?

Could you supply a real-life example of WSGI start_response() function?

好吧,在 mod_wsgi start_response()函数. code.google.com/p/modwsgi/source/browse/mod_wsgi/mod_wsgi.c#2678> mod_wgsi.c

Well, the start_response() function for mod_wsgi is defined on line 2678 of mod_wgsi.c

他们都没有说"WSGI的设计目的是为了……"

None of them says "WSGI is designed this way in order to..."

PEP3333 .浏览网络签名邮件列表档案,我发现

There doesn't seem to be much rationale for this aspect of WSGI's design in PEP3333. Looking through the web-sig mailing list archives, I came across this message...

前段时间,我反对删除start_response的决定 下一版本WSGI的功能,将以下事实作为依据 没有start_callable,异步扩展是不可能的 支持.

Some time ago I objected the decision to remove start_response function from next version WSGI, using as rationale the fact that without start_callable, asynchronous extension are impossible to support.

现在我发现删除start_response也会使 无法支持协程(或至少一些协程) 用法).

Now I have found that removing start_response will also make impossible to support coroutines (or, at least, some coroutines usage).

[...]

...这为实现这一部分的原理开了很长的篇幅,也许值得一读.

...which started a long thread about the rationale for this part of the implementation which might be worth a read.

如果您真的想知道WSGI界面这方面的起源,则必须阅读此更高版本的草案于2004年8月发布.

If you really want to know the origins of this aspect of the WSGI interface, you'll have to read a lot of the messages between this initial draft in December 2003, and this later draft in August 2004.

更新

那将与其他协议兼容吗?

How would that be compatible with that other protocol?

我不太清楚你的意思.忽略所有早期草案,可以以两种不同方式使用WSGI 1.x接口.

I'm not quite sure what you mean. Ignoring all the early drafts, the WSGI 1.x interface can be used in two different ways.

不推荐使用"的方法是...

The 'deprecated' method is...

def application(environ, start_response):
    write = start_response(status, headers)
    write('content block 1')
    write('content block 2')
    write('content block 3')
    return None

...并且推荐"方法是...

...and the 'recommended' method is...

def application(environ, start_response):
    start_response(status, headers)
    return ['content block 1',
            'content block 2',
            'content block 3']

大概,您可以同时使用...

Presumably, you could use both, with...

def application(environ, start_response):
    write = start_response(status, headers)
    write('content block 1')
    return ['content block 2',
            'content block 3']

...但是结果可能是不确定的.

...but the resulting behavior may be undefined.

通过此博客文章的外观,新的WSGI 2.x方法被认为是...

By the looks of this blog post, the new WSGI 2.x method being considered is...

def application(environ):
    return (status,
            headers,
            ['content block 1',
             'content block 2',
             'content block 3'])

...这消除了start_response()可调用项,并且显然消除了write()可调用项,但是没有迹象表明何时(或什至)这有可能取代WSGI 1.x.

...which eliminates the start_response() callable, and, obviously, the write() callable, but there's no indication as to when (or even if) this is likely to supercede WSGI 1.x.

这篇关于WSGI:start_response函数的用途是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆