`
angeloce
  • 浏览: 71761 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

PEP333 wsgi规范1.0不靠谱翻译稿(3)

阅读更多

environ变量

 

 The environ dictionary is required to contain these CGI environment variables, as defined by the Common Gateway Interface specification [2]. The following variables must be present, unless their value would be an empty string, in which case they may be omitted, except as otherwise noted below.

environ字典需要包含这些CGI环境变量, 作为对通用接口规范的定义.下面这些变量必须存在在字典中, 除非它们的值是空字符串, 它们被忽略掉.

 

REQUEST_METHOD
The HTTP request method, such as "GET" or "POST". This cannot ever be an empty string, and so is always required.

 

HTTP请求方法,诸如 GET 或 POST.不能写成空字符串,当然也是必需的.


SCRIPT_NAME
The initial portion of the request URL's "path" that corresponds to the application object, so that the application knows its virtual "location". This may be an empty string, if the application corresponds to the "root" of the server.

 

相对于应用对象请求的URL地址的初始部分, 以使得应用程序知道请求的虚拟地址.这个可以是空字符串, 如果应用位置在服务端的根目录地址.


PATH_INFO
The remainder of the request URL's "path", designating the virtual "location" of the request's target within the application. This may be an empty string, if the request URL targets the application root and does not have a trailing slash.

 

请求URL地址的剩余部分, 指示请求应用目标的虚拟位置. 这个可以是空字符串, 如果请求目标位应用的根目录并且结尾没有反斜杠.


QUERY_STRING
The portion of the request URL that follows the "?", if any. May be empty or absent.

 

在"?"后面的请求URL部分.可以为空或者省略掉.


CONTENT_TYPE
The contents of any Content-Type fields in the HTTP request. May be empty or absent.

 

HTTP请求中所有Content-Type字段的内容. 可以为空或省略.


CONTENT_LENGTH
The contents of any Content-Length fields in the HTTP request. May be empty or absent.

 

HTTP请求中所有Content-Length 字段的内容. 可以为空或省略.


SERVER_NAME, SERVER_PORT
When combined with SCRIPT_NAME and PATH_INFO, these variables can be used to complete the URL. Note, however, that HTTP_HOST, if present, should be used in preference to SERVER_NAME for reconstructing the request URL. See the URL Reconstruction section below for more detail. SERVER_NAME and SERVER_PORT can never be empty strings, and so are always required.

 

在连接SCRIPT_NAME 和PATH_INFO时,这两个变量可以用来完成整个URL. 请注意, 如果HTTP_HOST存在, 应该优先于使用它而不是SERVER_NAME来重建URL. 更多细节请参见下面的 URL Reconstruction 章节. 这两个变量都不能为空, 当然也是必需的.


SERVER_PROTOCOL
The version of the protocol the client used to send the request. Typically this will be something like "HTTP/1.0" or "HTTP/1.1" and may be used by the application to determine how to treat any HTTP request headers. (This variable should probably be called REQUEST_PROTOCOL, since it denotes the protocol used in the request, and is not necessarily the protocol that will be used in the server's response. However, for compatibility with CGI we have to keep the existing name.)

 

客户端发送请求使用的协议版本. 通常这是些类似 "HTTP/1.0" 或 "HTTP/1.1"的东西, 可能会使应用程序来决定如果处理每个HTTP请求头.(这个变量或许应该叫做REQUEST_PROTOCOL, 因为它指的是请求的协议, 不一定代表服务端响应的协议. 然而为了兼容CGI我们必须保留这个名字.)


HTTP_ Variables
Variables corresponding to the client-supplied HTTP request headers (i.e., variables whose names begin with "HTTP_"). The presence or absence of these variables should correspond with the presence or absence of the appropriate HTTP header in the request.

 

与客户端支持的HTTP请求头一致的变量.(也就是以"HTTP_"开头命名的变量.)这些变量是否出现都要与HTTP请求头中的变量保持一致.

 

A server or gateway should attempt to provide as many other CGI variables as are applicable. In addition, if SSL is in use, the server or gateway should also provide as many of the Apache SSL environment variables [5] as are applicable, such as HTTPS=on and SSL_PROTOCOL. Note, however, that an application that uses any CGI variables other than the ones listed above are necessarily non-portable to web servers that do not support the relevant extensions. (For example, web servers that do not publish files will not be able to provide a meaningful DOCUMENT_ROOT or PATH_TRANSLATED.)

 

A WSGI-compliant server or gateway should document what variables it provides, along with their definitions as appropriate. Applications should check for the presence of any variables they require, and have a fallback plan in the event such a variable is absent.

 

Note: missing variables (such as REMOTE_USER when no authentication has occurred) should be left out of the environ dictionary. Also note that CGI-defined variables must be strings, if they are present at all. It is a violation of this specification for a CGI variable's value to be of any type other than str.

 

服务端应该尝试提供其他合适的CGI变量.如果使用了SSL, 也应该提供合适的Apache SSL环境变量, 例如 HTTPS=on 和 SSL_PROTOCOL. 然而请注意, 使用了除上述之外其他CGI两边的应用程序对于不支持相关扩展的web服务器来说是不可移植过来的.(例如, 一个不能发布文件的web服务器不可能提供有意义的DOCUMENT_ROOT 或 PATH_TRANSLATED 变量.)

 

一个遵守WSGI协议的服务端应该记录它会提供什么变量. 应用程序应该检查它需要的变量是否都存在, 如果缺少了某个变量应该有 后备的 方法.

 

注意: 缺失的变量(例如没有发生认证的REMOTE_USER变量)应该从字典中忽略掉. 而且要注意 CGI定义的变量如果存在就一定是个字符串. 它违反了 CGI变量可以是任何类型(不一定要是字符串)的规定.

 
In addition to the CGI-defined variables, the environ dictionary may also contain arbitrary operating-system "environment variables", and must contain the following WSGI-defined variables:

 

除了CGI定义的变量外, environ字典可以包括操作系统的环境变量, 但必须包括下列WSGI定义的变量:

 

wsgi.version

The tuple (1,0), representing WSGI version 1.0.

 

元祖 (1,0), 表示WSGI的版本是1.0

 

wsgi.url_scheme

A string representing the "scheme" portion of the URL at which the application is being invoked. Normally, this will have the value "http" or "https", as appropriate.

 

表示哪个应用会被调用在URL的 "scheme"部分的字符串.通常,  应该是"http" 或"https".

 

wsgi.input

An input stream (file-like object) from which the HTTP request body can be read. (The server or gateway may perform reads on-demand as requested by the application, or it may pre- read the client's request body and buffer it in-memory or on disk, or use any other technique for providing such an input stream, according to its preference.)

 

一个HTTP请求体能读出的输入流(类文件对象).(服务端可能等待应用程序请求再执行读出, 或者提前读出并缓存在内存或硬盘上, 或使用其它技术来提供类似的输入流.)

 

wsgi.errors

An output stream (file-like object) to which error output can be written, for the purpose of recording program or other errors in a standardized and possibly centralized location. This should be a "text mode" stream; i.e., applications should use "\n" as a line ending, and assume that it will be converted to the correct line ending by the server/gateway.

 

For many servers, wsgi.errors will be the server's main error log. Alternatively, this may be sys.stderr, or a log file of some sort. The server's documentation should include an explanation of how to configure this or where to find the recorded output. A server or gateway may supply different error streams to different applications, if this is desired.

 

一个输出流(类文件对象), 错误输出可以使用写人到 记录程序或者其它标准和可能的中央位置错误.(-_-#).这应该是个文本模式流; 例如, 应用程序应该使用"\n"作为行结尾, 并且可以假设它会被服务端转换为正确的行结尾.

 

对于大多数服务器, wsgi.errors是服务器主要的异常日志. 或者可以是sys.stderr或其他种类的log文件. 服务器文档应该包括如何配置这个或在哪里找到记录输出的说明.如果需要, 服务端应该提供不同的异常流到不同的应用中.

 

wsgi.multithread

This value should evaluate true if the application object may be simultaneously invoked by another thread in the same process, and should evaluate false otherwise.

 

如果应用程序可以同时被相同进程的不同现成调用, 这个值应该写为True, 否则写为False.

 

wsgi.multiprocess

This value should evaluate true if an equivalent application object may be simultaneously invoked by another process, and should evaluate false otherwise.

 

如果同一个应用程序可以同时被不同进程调用, 写为True, 否则写为False.

 

wsgi.run_once

This value should evaluate true if the server or gateway expects (but does not guarantee!) that the application will only be invoked this one time during the life of its containing process. Normally, this will only be true for a gateway based on CGI (or something similar).

 

如果服务端期望(但不保证)应用程序在该进程期内仅被调用一次, 该值写为True.通常,对于建在CGI(或类似)的网关该值总为True.

 

Finally, the environ dictionary may also contain server-defined variables. These variables should be named using only lower-case letters, numbers, dots, and underscores, and should be prefixed with a name that is unique to the defining server or gateway. For example, mod_python might define variables with names like mod_python.some_variable.

 

最后, environ字典可以包含某些服务器自定义的变量. 这些变量应该使用lower-case形式命名,包括字符,数字,小数点和下划线,并且应该使用能唯一定义服务端的名字作为前缀.例如,mod_python可以定义一个像 mod_python.some_variable名字的变量.

 

 

 

 

 

 

 

 

 

 

 

分享到:
评论
1 楼 simomo 2011-02-16  
一直在找wsgi是如何将客户端发来的request传递给django的,看了你的翻译才知道是env参数中的wsgi.input的值

多谢啦

相关推荐

    Python PEP8 编码规范中文版.pdf

    PEP8 规范也提供了忽略规则的建议,例如当遵循这份指南之后代码的可读性变差,或者与周围的代码保持一致(也可能出于历史原因),或者代码需要兼容不支持编码规范建议的老版本 Python。 结语 PEP8 编码规范中文版...

    Python PEP8 编码规范中文版

    最后,PEP8规范也指出,如果遵循规范导致代码可读性变差,或者与周围的代码不一致,或者与老版本Python的兼容性有问题时,可以适当忽略某些规则。在这些情况下,最重要的是保持代码的清晰可读,以及与团队内部的风格...

    PEP8Python 编码规范

    PEP8是关于Python编码风格的规范,而如何将英文文档转成中文应当是遵循翻译原则和文档规范的问题。所以,正确理解这部分内容应该是:PEP8指导如何书写整洁的Python代码,并且在必要时如何将文档和注释用中文书写,...

    Python PEP8编码规范中文版

    PEP8编码规范,全称为“Style Guide for Python Code”,是由Python社区制定的一套编程风格指南,旨在提高Python代码的可读性和一致性。自2001年首版发布以来,经过多次修订和完善,PEP8已成为Python编程中普遍遵循...

    Python PEP8 编码规范中文版.zip

    **Python PEP 8编码规范中文版** Python PEP 8是Python编程语言的官方风格指南,由Guido van Rossum(Python之父)在2001年提出。PEP 8全称为"Python Enhancement Proposal 8",是Python社区广泛接受的代码风格指南...

    PEP8Python编码规范.pdf

    "PEP8 Python 编码规范" PEP8 是 Python 官方提供的一份编码规范指南,旨在提高 Python 代码的可读性、可维护性和可重用性。本文档将对 PEP8 中的各种规范进行详细解释和总结。 缩进和换行 PEP8 规定使用 4 个...

    PEP8代码规范

    ### PEP8代码规范详解 #### 一、引言 PEP8,即Python Enhancement Proposal 8,是一份详尽的文档,旨在规定Python代码的编写标准与规范。PEP8由Guido van Rossum等人制定,其核心目标是通过一系列明确的规则提升...

    python PEP8 编码规范总结

    参照https://legacy.python.org/dev/peps/pep-0008/官方文档简单总结了python编程过程中应当遵守的编码规范,比如函数的命名、变量的命名等(PEP8编码规范)。

    python pep8编码规范

    ### Python PEP8编码规范详解 #### 一、引言 PEP 8,全称为“Python Code Style Guide”,是Python官方推荐的编程规范指南。它由Python之父Guido van Rossum与其他开发者共同制定,并于2001年7月5日首次发布。PEP ...

    PEP8 Python编码规范

    PEP8是Python编程语言的官方编码规范,它由Python的核心开发者Guido van Rossum、Barry Warsaw和Nick Coghlan等人撰写和维护,最初于2001年发布。PEP是Python Enhancement Proposals的缩写,意为Python增强提案。PEP...

    Python编程规范PEP8.pdf

    3. 编程推荐:PEP8还推荐一些编程实践,如减少代码中的缩进层级,避免过长的行宽(建议不超过79字符),使用空格而非制表符(tab)进行缩进,以及在行尾保持空格的一致性等。这些推荐有助于提高代码的整体可读性和...

    PEP8编码规范(中文)

    ### PEP8编码规范中文详解 #### 一、引言 PEP8 是 Python 编程语言中的一个重要标准,它提供了官方推荐的代码格式化规范。PEP8 的全称是“Python Enhancement Proposal 8”,它由 Guido van Rossum 和 Barry ...

    cpp-Meinheld是一个高性能的异步WSGIWeb服务器

    **PEP3333**,也被称为“WSGI v1.0”,是由Mark Ramm和Ian Bicking共同提出的,对PEP333进行了更新,以适应Python 3的特性,例如Unicode字符串的处理。PEP3333不仅保持了与PEP333的兼容性,还增加了一些改进,如明确...

    Python_PEP8_代码规范.pdf

    ### Python PEP8 代码规范详解 #### 一、引言 本文档旨在提供一份详细的指南,帮助开发者理解和遵循Python编程语言中广泛接受的最佳实践——PEP8代码规范。PEP8是Python Enhancement Proposal(Python改进提案)的...

    PEP5小学英语五年级下册课文及翻译.pdf

    PEP5小学英语五年级下册课文及翻译.pdf

    PythonPEP8编码规范中文版--高清.rar

    **Python PEP 8编码规范中文版** Python PEP 8是Python编程语言的官方编码风格指南,由Guido van Rossum(Python之父)在2001年提出,旨在提升代码的可读性和一致性。这个规范对于任何Python开发者来说都极其重要,...

Global site tag (gtag.js) - Google Analytics