@@ -32,6 +32,8 @@ msgid ""
32
32
"string-only cookies, and provides an abstraction for having any serializable "
33
33
"data-type as cookie value."
34
34
msgstr ""
35
+ ":mod:`http.cookies` 模組定義了抽象 HTTP 狀態管理機制 (state management "
36
+ "mechanism) 的類別,它支援簡單的字串僅有的 cookie,並為 cookie 值提供了抽象。"
35
37
36
38
#: ../../library/http.cookies.rst:19
37
39
msgid ""
@@ -42,30 +44,39 @@ msgid ""
42
44
"comes to cookie handling. As a result, this module now uses parsing rules "
43
45
"that are a bit less strict than they once were."
44
46
msgstr ""
47
+ "此模組原先絕對遵循了 :rfc:`2109` 和 :rfc:`2068` 規範所描述的解析規則。後來發"
48
+ "現 MSIE 3.0x 並不遵循這些規範所描述的字元規則,許多當前的瀏覽器和伺服器也在處"
49
+ "理 cookie 時有放逐解析規則。因此,此模組現在使用的解析規則比它之前更輕鬆。"
45
50
46
51
#: ../../library/http.cookies.rst:26
47
52
msgid ""
48
53
"The character set, :data:`string.ascii_letters`, :data:`string.digits` and "
49
54
"``!#$%&'*+-.^_`|~:`` denote the set of valid characters allowed by this "
50
55
"module in a cookie name (as :attr:`~Morsel.key`)."
51
56
msgstr ""
57
+ "此模組在 cookie 名稱(:attr:`~Morsel.key`)中允許的有效字元為 :data:`string."
58
+ "ascii_letters`、:data:`string.digits` 和 ``!#$%&'*+-.^_`|~``。"
52
59
53
60
#: ../../library/http.cookies.rst:30
54
61
msgid "Allowed ':' as a valid cookie name character."
55
- msgstr ""
62
+ msgstr "允許 ':' 作為有效的 cookie 名稱字元。 "
56
63
57
64
#: ../../library/http.cookies.rst:36
58
65
msgid ""
59
66
"On encountering an invalid cookie, :exc:`CookieError` is raised, so if your "
60
67
"cookie data comes from a browser you should always prepare for invalid data "
61
68
"and catch :exc:`CookieError` on parsing."
62
69
msgstr ""
70
+ "當遇到無效的 cookie 時,將引發 :exc:`CookieError`,因此如果你的 cookie 資料來"
71
+ "自瀏覽器,你應該總是準備面臨無效的資料並捕捉 :exc:`CookieError`。"
63
72
64
73
#: ../../library/http.cookies.rst:43
65
74
msgid ""
66
75
"Exception failing because of :rfc:`2109` invalidity: incorrect attributes, "
67
76
"incorrect :mailheader:`Set-Cookie` header, etc."
68
77
msgstr ""
78
+ "因為 :rfc:`2109` 無效而引發的例外:不正確的屬性、不正確的 :mailheader:`Set-"
79
+ "Cookie` 標頭等。"
69
80
70
81
#: ../../library/http.cookies.rst:49
71
82
msgid ""
@@ -74,10 +85,12 @@ msgid ""
74
85
"value, the value is first converted to a :class:`Morsel` containing the key "
75
86
"and the value."
76
87
msgstr ""
88
+ "這個類別是一個字典式物件,其中的鍵是字串,而值則是 :class:`Morsel` 物件。請注"
89
+ "意,當設定鍵時,值會先被轉換為一個包含鍵和值的 :class:`Morsel`。"
77
90
78
91
#: ../../library/http.cookies.rst:53
79
92
msgid "If *input* is given, it is passed to the :meth:`load` method."
80
- msgstr ""
93
+ msgstr "如果 *input* 被提供,它會被傳遞給 :meth:`load` 方法。 "
81
94
82
95
#: ../../library/http.cookies.rst:58
83
96
msgid ""
@@ -87,6 +100,10 @@ msgid ""
87
100
"SimpleCookie` calls the builtin :func:`str` to convert the value to a "
88
101
"string. Values received from HTTP are kept as strings."
89
102
msgstr ""
103
+ "這個類別繼承自 :class:`BaseCookie` 並覆寫了 :meth:`~BaseCookie.value_decode` "
104
+ "和 :meth:`~BaseCookie.value_encode`。:class:`!SimpleCookie` 支援字串作為 "
105
+ "cookie 值。當設定值時,:class:`!SimpleCookie` 會呼叫內建的 :func:`str` 來將值"
106
+ "轉換為字串。從 HTTP 接收的值會保持為字串。"
90
107
91
108
#: ../../library/http.cookies.rst:66
92
109
msgid "Module :mod:`http.cookiejar`"
@@ -97,14 +114,16 @@ msgid ""
97
114
"HTTP cookie handling for web *clients*. The :mod:`http.cookiejar` and :mod:"
98
115
"`http.cookies` modules do not depend on each other."
99
116
msgstr ""
117
+ "用於 *網路客戶端* 的 HTTP cookie 處理。:mod:`http.cookiejar` 和 :mod:`http."
118
+ "cookies` 模組不相依。"
100
119
101
120
#: ../../library/http.cookies.rst:70
102
121
msgid ":rfc:`2109` - HTTP State Management Mechanism"
103
- msgstr ""
122
+ msgstr ":rfc:`2109` - HTTP 狀態管理機制 "
104
123
105
124
#: ../../library/http.cookies.rst:71
106
125
msgid "This is the state management specification implemented by this module."
107
- msgstr ""
126
+ msgstr "這是這個模組實作的狀態管理規範。 "
108
127
109
128
#: ../../library/http.cookies.rst:77
110
129
msgid "Cookie Objects"
@@ -116,19 +135,27 @@ msgid ""
116
135
"``real_value`` can be any type. This method does no decoding in :class:"
117
136
"`BaseCookie` --- it exists so it can be overridden."
118
137
msgstr ""
138
+ "從字串表示法回傳 ``(real_value, coded_value)`` 的元組。``real_value`` 可以是"
139
+ "任何類型。此方法在 :class:`BaseCookie` 中不會進行解碼 --- 它存在以便可以被覆"
140
+ "寫。"
119
141
120
142
#: ../../library/http.cookies.rst:89
121
143
msgid ""
122
144
"Return a tuple ``(real_value, coded_value)``. *val* can be any type, but "
123
145
"``coded_value`` will always be converted to a string. This method does no "
124
146
"encoding in :class:`BaseCookie` --- it exists so it can be overridden."
125
147
msgstr ""
148
+ "回傳一個元組 ``(real_value, coded_value)``。*val* 可以是任何類型,但 "
149
+ "``coded_value`` 會總是轉換為字串。此方法在 :class:`BaseCookie` 中不做編碼 "
150
+ "--- 它存在以便可以被覆寫。"
126
151
127
152
#: ../../library/http.cookies.rst:94
128
153
msgid ""
129
154
"In general, it should be the case that :meth:`value_encode` and :meth:"
130
155
"`value_decode` are inverses on the range of *value_decode*."
131
156
msgstr ""
157
+ "一般來說,:meth:`value_encode` 和 :meth:`value_decode` 應該是在 "
158
+ "*value_decode* 的範圍內的逆函式。"
132
159
133
160
#: ../../library/http.cookies.rst:100
134
161
msgid ""
@@ -137,24 +164,31 @@ msgid ""
137
164
"method. *sep* is used to join the headers together, and is by default the "
138
165
"combination ``'\\ r\\ n'`` (CRLF)."
139
166
msgstr ""
167
+ "回傳一個適合作為 HTTP 標頭的字串表示。*attrs* 和 *header* 會傳送給每個 :"
168
+ "class:`Morsel` 的 :meth:`~Morsel.output` 方法。*sep* 用來連結標頭,預設為 "
169
+ "``\\\\ r\\\\ n``(CRLF)。"
140
170
141
171
#: ../../library/http.cookies.rst:108
142
172
msgid ""
143
173
"Return an embeddable JavaScript snippet, which, if run on a browser which "
144
174
"supports JavaScript, will act the same as if the HTTP headers was sent."
145
175
msgstr ""
176
+ "回傳一個可嵌入的 JavaScript 片段,如果在支援 JavaScript 的瀏覽器上執行,它的"
177
+ "行為會與如果 HTTP 標頭被傳送的情況相同。"
146
178
147
179
#: ../../library/http.cookies.rst:111 ../../library/http.cookies.rst:207
148
180
#: ../../library/http.cookies.rst:215
149
181
msgid "The meaning for *attrs* is the same as in :meth:`output`."
150
- msgstr ""
182
+ msgstr "*attrs* 的意義與 :meth:`output` 相同。 "
151
183
152
184
#: ../../library/http.cookies.rst:116
153
185
msgid ""
154
186
"If *rawdata* is a string, parse it as an ``HTTP_COOKIE`` and add the values "
155
187
"found there as :class:`Morsel`\\ s. If it is a dictionary, it is equivalent "
156
188
"to::"
157
189
msgstr ""
190
+ "如果 *rawdata* 是字串,則將其解析為 ``HTTP_COOKIE``,並將在其中找到的值當作 :"
191
+ "class:`Morsel`\\ s 新增。如果它是一個字典,則等同於: ::"
158
192
159
193
#: ../../library/http.cookies.rst:119
160
194
msgid ""
@@ -170,67 +204,76 @@ msgstr "Morsel 物件"
170
204
171
205
#: ../../library/http.cookies.rst:131
172
206
msgid "Abstract a key/value pair, which has some :rfc:`2109` attributes."
173
- msgstr ""
207
+ msgstr "抽象一個 key/value 對,它有一些 :rfc:`2109` 屬性。 "
174
208
175
209
#: ../../library/http.cookies.rst:133
176
210
msgid ""
177
211
"Morsels are dictionary-like objects, whose set of keys is constant --- the "
178
212
"valid :rfc:`2109` attributes, which are:"
179
213
msgstr ""
214
+ "Morsels 是一種類似字典的物件,其鍵的集合是固定的 --- 有效的 :rfc:`2109` 屬"
215
+ "性,它們是:"
180
216
181
217
#: ../../library/http.cookies.rst:146
182
218
msgid ""
183
219
"The attribute :attr:`httponly` specifies that the cookie is only transferred "
184
220
"in HTTP requests, and is not accessible through JavaScript. This is intended "
185
221
"to mitigate some forms of cross-site scripting."
186
222
msgstr ""
223
+ "屬性 :attr:`httponly` 指定 cookie 僅在 HTTP 請求中傳輸,而不可通過 "
224
+ "JavaScript 存取。這是為了減輕某些形式的跨網站腳本攻擊。"
187
225
188
226
#: ../../library/http.cookies.rst:150
189
227
msgid ""
190
228
"The attribute :attr:`samesite` specifies that the browser is not allowed to "
191
229
"send the cookie along with cross-site requests. This helps to mitigate CSRF "
192
230
"attacks. Valid values for this attribute are \" Strict\" and \" Lax\" ."
193
231
msgstr ""
232
+ "屬性 :attr:`samesite` 指定瀏覽器不能將 Cookie 與跨網站請求一起傳送。這有助於"
233
+ "減輕 CSRF 攻擊。此屬性的有效值為 \" Strict\" 和 \" Lax\" 。"
194
234
195
235
#: ../../library/http.cookies.rst:154
196
236
msgid "The keys are case-insensitive and their default value is ``''``."
197
- msgstr ""
237
+ msgstr "鍵的大小寫不敏感,其預設值為 ``''``。 "
198
238
199
239
#: ../../library/http.cookies.rst:156
200
240
msgid ""
201
241
":meth:`!__eq__` now takes :attr:`~Morsel.key` and :attr:`~Morsel.value` into "
202
242
"account."
203
243
msgstr ""
244
+ ":meth:`!__eq__` 現在會考慮 :attr:`~Morsel.key` 和 :attr:`~Morsel.value`。"
204
245
205
246
#: ../../library/http.cookies.rst:160
206
247
msgid ""
207
248
"Attributes :attr:`~Morsel.key`, :attr:`~Morsel.value` and :attr:`~Morsel."
208
249
"coded_value` are read-only. Use :meth:`~Morsel.set` for setting them."
209
250
msgstr ""
251
+ "屬性 :attr:`~Morsel.key`、:attr:`~Morsel.value` 和 :attr:`~Morsel."
252
+ "coded_value` 為只讀。請使用 :meth:`~Morsel.set` 來設定它們。"
210
253
211
254
#: ../../library/http.cookies.rst:165
212
255
msgid "Added support for the :attr:`samesite` attribute."
213
256
msgstr "新增 :attr:`samesite` 屬性的支援"
214
257
215
258
#: ../../library/http.cookies.rst:171
216
259
msgid "The value of the cookie."
217
- msgstr ""
260
+ msgstr "cookie 的值。 "
218
261
219
262
#: ../../library/http.cookies.rst:176
220
263
msgid "The encoded value of the cookie --- this is what should be sent."
221
- msgstr ""
264
+ msgstr "cookie 的編碼值 --- 這是應該被傳送的值。 "
222
265
223
266
#: ../../library/http.cookies.rst:181
224
267
msgid "The name of the cookie."
225
- msgstr ""
268
+ msgstr "cookie 的名稱。 "
226
269
227
270
#: ../../library/http.cookies.rst:186
228
271
msgid "Set the *key*, *value* and *coded_value* attributes."
229
- msgstr ""
272
+ msgstr "設定 *key*、*value* 和 *coded_value* 屬性。 "
230
273
231
274
#: ../../library/http.cookies.rst:191
232
275
msgid "Whether *K* is a member of the set of keys of a :class:`Morsel`."
233
- msgstr ""
276
+ msgstr "*K* 是 :class:`Morsel` 的鍵集中的成員嗎? "
234
277
235
278
#: ../../library/http.cookies.rst:196
236
279
msgid ""
@@ -239,43 +282,52 @@ msgid ""
239
282
"given, in which case it should be a list of attributes to use. *header* is "
240
283
"by default ``\" Set-Cookie:\" ``."
241
284
msgstr ""
285
+ "回傳 Morsel 的字串表示,適合作為 HTTP 標頭。預設會包含所有屬性,除非 *attrs* "
286
+ "被提供,在此情況下,它應該是一個屬性清單,用來選擇要使用的屬性。預設的 "
287
+ "*header* 是 ``\" Set-Cookie:\" ``。"
242
288
243
289
#: ../../library/http.cookies.rst:204
244
290
msgid ""
245
291
"Return an embeddable JavaScript snippet, which, if run on a browser which "
246
292
"supports JavaScript, will act the same as if the HTTP header was sent."
247
293
msgstr ""
294
+ "回傳一個可嵌入的 JavaScript 片段,如果在支援 JavaScript 的瀏覽器上執行,它的"
295
+ "行為與如果 HTTP 標頭被傳送的情況相同。"
248
296
249
297
#: ../../library/http.cookies.rst:212
250
298
msgid ""
251
299
"Return a string representing the Morsel, without any surrounding HTTP or "
252
300
"JavaScript."
253
- msgstr ""
301
+ msgstr "回傳 Morsel 的字串表示,不包含任何 HTTP 或 JavaScript。 "
254
302
255
303
#: ../../library/http.cookies.rst:220
256
304
msgid ""
257
305
"Update the values in the Morsel dictionary with the values in the dictionary "
258
306
"*values*. Raise an error if any of the keys in the *values* dict is not a "
259
307
"valid :rfc:`2109` attribute."
260
308
msgstr ""
309
+ "更新 Morsel 字典中的值為 *values* 字典中的值。如果 *values* 字典中的任何鍵不"
310
+ "是有效的 :rfc:`2109` 屬性,則引發錯誤。"
261
311
262
312
#: ../../library/http.cookies.rst:224
263
313
msgid "an error is raised for invalid keys."
264
- msgstr ""
314
+ msgstr "對於無效的 key 會引發錯誤。 "
265
315
266
316
#: ../../library/http.cookies.rst:230
267
317
msgid "Return a shallow copy of the Morsel object."
268
- msgstr ""
318
+ msgstr "回傳 Morsel 物件的淺複製。 "
269
319
270
320
#: ../../library/http.cookies.rst:232
271
321
msgid "return a Morsel object instead of a dict."
272
- msgstr ""
322
+ msgstr "回傳 Morsel 物件而不是 dict。 "
273
323
274
324
#: ../../library/http.cookies.rst:238
275
325
msgid ""
276
326
"Raise an error if key is not a valid :rfc:`2109` attribute, otherwise behave "
277
327
"the same as :meth:`dict.setdefault`."
278
328
msgstr ""
329
+ "如果 key 不是一個有效的 :rfc:`2109` 屬性,則引發錯誤,否則行為與 :meth:`dict."
330
+ "setdefault` 相同。"
279
331
280
332
#: ../../library/http.cookies.rst:245
281
333
msgid "Example"
@@ -284,7 +336,7 @@ msgstr "範例"
284
336
#: ../../library/http.cookies.rst:247
285
337
msgid ""
286
338
"The following example demonstrates how to use the :mod:`http.cookies` module."
287
- msgstr ""
339
+ msgstr "以下範例示範如何使用 :mod:`http.cookies` 模組。 "
288
340
289
341
#: ../../library/http.cookies.rst:249
290
342
msgid ""
@@ -335,3 +387,49 @@ msgid ""
335
387
"Set-Cookie: number=7\n"
336
388
"Set-Cookie: string=seven"
337
389
msgstr ""
390
+ ">>> from http import cookies\n"
391
+ ">>> C = cookies.SimpleCookie()\n"
392
+ ">>> C[\" fig\" ] = \" newton\" \n"
393
+ ">>> C[\" sugar\" ] = \" wafer\" \n"
394
+ ">>> print(C) # generate HTTP headers\n"
395
+ "Set-Cookie: fig=newton\n"
396
+ "Set-Cookie: sugar=wafer\n"
397
+ ">>> print(C.output()) # same thing\n"
398
+ "Set-Cookie: fig=newton\n"
399
+ "Set-Cookie: sugar=wafer\n"
400
+ ">>> C = cookies.SimpleCookie()\n"
401
+ ">>> C[\" rocky\" ] = \" road\" \n"
402
+ ">>> C[\" rocky\" ][\" path\" ] = \" /cookie\" \n"
403
+ ">>> print(C.output(header=\" Cookie:\" ))\n"
404
+ "Cookie: rocky=road; Path=/cookie\n"
405
+ ">>> print(C.output(attrs=[], header=\" Cookie:\" ))\n"
406
+ "Cookie: rocky=road\n"
407
+ ">>> C = cookies.SimpleCookie()\n"
408
+ ">>> C.load(\" chips=ahoy; vienna=finger\" ) # load from a string (HTTP "
409
+ "header)\n"
410
+ ">>> print(C)\n"
411
+ "Set-Cookie: chips=ahoy\n"
412
+ "Set-Cookie: vienna=finger\n"
413
+ ">>> C = cookies.SimpleCookie()\n"
414
+ ">>> C.load('keebler=\" E=everybody; L=\\\\\" Loves\\\\\" ; fudge=\\\\ 012;\" ;')\n"
415
+ ">>> print(C)\n"
416
+ "Set-Cookie: keebler=\" E=everybody; L=\\\" Loves\\\" ; fudge=\\ 012;\" \n"
417
+ ">>> C = cookies.SimpleCookie()\n"
418
+ ">>> C[\" oreo\" ] = \" doublestuff\" \n"
419
+ ">>> C[\" oreo\" ][\" path\" ] = \" /\" \n"
420
+ ">>> print(C)\n"
421
+ "Set-Cookie: oreo=doublestuff; Path=/\n"
422
+ ">>> C = cookies.SimpleCookie()\n"
423
+ ">>> C[\" twix\" ] = \" none for you\" \n"
424
+ ">>> C[\" twix\" ].value\n"
425
+ "'none for you'\n"
426
+ ">>> C = cookies.SimpleCookie()\n"
427
+ ">>> C[\" number\" ] = 7 # equivalent to C[\" number\" ] = str(7)\n"
428
+ ">>> C[\" string\" ] = \" seven\" \n"
429
+ ">>> C[\" number\" ].value\n"
430
+ "'7'\n"
431
+ ">>> C[\" string\" ].value\n"
432
+ "'seven'\n"
433
+ ">>> print(C)\n"
434
+ "Set-Cookie: number=7\n"
435
+ "Set-Cookie: string=seven"
0 commit comments