@@ -139,6 +139,10 @@ msgid ""
139139"environment variables set according to the CGI standard). Since it may "
140140"consume standard input, it should be instantiated only once."
141141msgstr ""
142+ "要获取提交的表单数据,请使用 :class:`FieldStorage` 类。 如果表单包含非 ASCII 字符,请使用 *encoding* "
143+ "关键字参数并设置为文档所定义的编码格式值。 它通常包含在 HTML 文档的 HEAD 部分的 META 标签中或者由 :mailheader"
144+ ":`Content-Type` 标头所指明。 这会从标准输入或环境读取表单内容(取决于根据 CGI 标准设置的多个环境变量的值)。 "
145+ "由于它可能会消耗标准输入,它应当只被实例化一次。"
142146
143147#: ../../library/cgi.rst:97
144148msgid ""
@@ -150,13 +154,19 @@ msgid ""
150154"for the optional *keep_blank_values* keyword parameter when creating the "
151155":class:`FieldStorage` instance."
152156msgstr ""
157+ ":class:`FieldStorage` 实例可以像 Python 字典一样来检索。 它允许通过 :keyword:`in` "
158+ "运算符进行成员检测,也支持标准字典方法 :meth:`~dict.keys` 和内置函数 :func:`len`。 "
159+ "包含空字符串的表单字段会被忽略而不会出现在字典中;要保留这样的值,请在创建 :class:`FieldStorage` 实例时为可选的 "
160+ "*keep_blank_values* 关键字形参提供一个真值。"
153161
154162#: ../../library/cgi.rst:105
155163msgid ""
156164"For instance, the following code (which assumes that the :mailheader"
157165":`Content-Type` header and blank line have already been printed) checks that"
158166" the fields ``name`` and ``addr`` are both set to a non-empty string::"
159167msgstr ""
168+ "举例来说,下面的代码(假定 :mailheader:`Content-Type` 标头和空行已经被打印)会检查字段 ``name`` 和 "
169+ "``addr`` 是否均被设为非空字符串::"
160170
161171#: ../../library/cgi.rst:119
162172msgid ""
@@ -167,6 +177,10 @@ msgid ""
167177"returns this string value directly; it also accepts an optional second "
168178"argument as a default to return if the requested key is not present."
169179msgstr ""
180+ "在这里的字段通过 ``form[key]`` 来访问,它们本身就是 :class:`FieldStorage` (或 "
181+ ":class:`MiniFieldStorage`,取决于表单的编码格式) 的实例。 实例的 :attr:`~FieldStorage.value` "
182+ "属性会产生字段的字符串值。 :meth:`~FieldStorage.getvalue` "
183+ "方法直接返回这个字符串;它还接受可选的第二个参数作为当请求的键不存在时要返回的默认值。"
170184
171185#: ../../library/cgi.rst:126
172186msgid ""
@@ -180,6 +194,11 @@ msgid ""
180194" single item case). For example, this code concatenates any number of "
181195"username fields, separated by commas::"
182196msgstr ""
197+ "如果提交的表单数据包含一个以上的同名字段,由 ``form[key]`` 所提取的对象将不是一个 :class:`FieldStorage` 或 "
198+ ":class:`MiniFieldStorage` 实例而是由这种实例组成的列表。 类似地,在这种情况下,``form.getvalue(key)`` "
199+ "将会返回一个字符串列表。 如果你预计到这种可能性(当你的 HTML 表单包含多个同名字段时),请使用 "
200+ ":meth:`~FieldStorage.getlist` 方法,它总是返回一个值的列表(这样你就不需要对只有单个项的情况进行特别处理)。 "
201+ "例如,这段代码拼接了任意数量的 username 字段,以逗号进行分隔::"
183202
184203#: ../../library/cgi.rst:139
185204msgid ""
@@ -193,12 +212,17 @@ msgid ""
193212":class:`FieldStorage` instance (the :func:`~io.RawIOBase.read` and "
194213":func:`~io.IOBase.readline` methods will return bytes)::"
195214msgstr ""
215+ "如果一个字段是代表上传的文件,请通过 :attr:`~FieldStorage.value` 属性访问该值或是通过 "
216+ ":meth:`~FieldStorage.getvalue` 方法以字节形式将整个文件读入内存。 这可能不是你想要的结果。 你可以通过测试 "
217+ ":attr:`~FieldStorage.filename` 属性或 :attr:`~FieldStorage.file` 属性来检测上传的文件。 "
218+ "然后你可以从 :attr:`!file` 属性读取数据,直到它作为 :class:`FieldStorage` 实例的垃圾回收的一部分被自动关闭 "
219+ "(:func:`~io.RawIOBase.read` 和 :func:`~io.IOBase.readline` 方法将返回字节数据)::"
196220
197221#: ../../library/cgi.rst:159
198222msgid ""
199223":class:`FieldStorage` objects also support being used in a :keyword:`with` "
200224"statement, which will automatically close them when done."
201- msgstr ""
225+ msgstr ":class:`FieldStorage` 对象还支持在 :keyword:`with` 语句中使用,该语句结束时将自动关闭它们。 "
202226
203227#: ../../library/cgi.rst:162
204228msgid ""
0 commit comments