Skip to content

Commit 059c1dd

Browse files
committed
Translate library/http.cookies
1 parent e7b5675 commit 059c1dd

File tree

1 file changed

+115
-17
lines changed

1 file changed

+115
-17
lines changed

library/http.cookies.po

+115-17
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ msgid ""
3232
"string-only cookies, and provides an abstraction for having any serializable "
3333
"data-type as cookie value."
3434
msgstr ""
35+
":mod:`http.cookies` 模組定義了抽象 HTTP 狀態管理機制 (state management "
36+
"mechanism) 的類別,它支援簡單的字串僅有的 cookie,並為 cookie 值提供了抽象。"
3537

3638
#: ../../library/http.cookies.rst:19
3739
msgid ""
@@ -42,30 +44,39 @@ msgid ""
4244
"comes to cookie handling. As a result, this module now uses parsing rules "
4345
"that are a bit less strict than they once were."
4446
msgstr ""
47+
"此模組原先絕對遵循了 :rfc:`2109` 和 :rfc:`2068` 規範所描述的解析規則。後來發"
48+
"現 MSIE 3.0x 並不遵循這些規範所描述的字元規則,許多當前的瀏覽器和伺服器也在處"
49+
"理 cookie 時有放逐解析規則。因此,此模組現在使用的解析規則比它之前更輕鬆。"
4550

4651
#: ../../library/http.cookies.rst:26
4752
msgid ""
4853
"The character set, :data:`string.ascii_letters`, :data:`string.digits` and "
4954
"``!#$%&'*+-.^_`|~:`` denote the set of valid characters allowed by this "
5055
"module in a cookie name (as :attr:`~Morsel.key`)."
5156
msgstr ""
57+
"此模組在 cookie 名稱(:attr:`~Morsel.key`)中允許的有效字元為 :data:`string."
58+
"ascii_letters`、:data:`string.digits` 和 ``!#$%&'*+-.^_`|~``。"
5259

5360
#: ../../library/http.cookies.rst:30
5461
msgid "Allowed ':' as a valid cookie name character."
55-
msgstr ""
62+
msgstr "允許 ':' 作為有效的 cookie 名稱字元。"
5663

5764
#: ../../library/http.cookies.rst:36
5865
msgid ""
5966
"On encountering an invalid cookie, :exc:`CookieError` is raised, so if your "
6067
"cookie data comes from a browser you should always prepare for invalid data "
6168
"and catch :exc:`CookieError` on parsing."
6269
msgstr ""
70+
"當遇到無效的 cookie 時,將引發 :exc:`CookieError`,因此如果你的 cookie 資料來"
71+
"自瀏覽器,你應該總是準備面臨無效的資料並捕捉 :exc:`CookieError`。"
6372

6473
#: ../../library/http.cookies.rst:43
6574
msgid ""
6675
"Exception failing because of :rfc:`2109` invalidity: incorrect attributes, "
6776
"incorrect :mailheader:`Set-Cookie` header, etc."
6877
msgstr ""
78+
"因為 :rfc:`2109` 無效而引發的例外:不正確的屬性、不正確的 :mailheader:`Set-"
79+
"Cookie` 標頭等。"
6980

7081
#: ../../library/http.cookies.rst:49
7182
msgid ""
@@ -74,10 +85,12 @@ msgid ""
7485
"value, the value is first converted to a :class:`Morsel` containing the key "
7586
"and the value."
7687
msgstr ""
88+
"這個類別是一個字典式物件,其中的鍵是字串,而值則是 :class:`Morsel` 物件。請注"
89+
"意,當設定鍵時,值會先被轉換為一個包含鍵和值的 :class:`Morsel`。"
7790

7891
#: ../../library/http.cookies.rst:53
7992
msgid "If *input* is given, it is passed to the :meth:`load` method."
80-
msgstr ""
93+
msgstr "如果 *input* 被提供,它會被傳遞給 :meth:`load` 方法。"
8194

8295
#: ../../library/http.cookies.rst:58
8396
msgid ""
@@ -87,6 +100,10 @@ msgid ""
87100
"SimpleCookie` calls the builtin :func:`str` to convert the value to a "
88101
"string. Values received from HTTP are kept as strings."
89102
msgstr ""
103+
"這個類別繼承自 :class:`BaseCookie` 並覆寫了 :meth:`~BaseCookie.value_decode` "
104+
"和 :meth:`~BaseCookie.value_encode`。:class:`!SimpleCookie` 支援字串作為 "
105+
"cookie 值。當設定值時,:class:`!SimpleCookie` 會呼叫內建的 :func:`str` 來將值"
106+
"轉換為字串。從 HTTP 接收的值會保持為字串。"
90107

91108
#: ../../library/http.cookies.rst:66
92109
msgid "Module :mod:`http.cookiejar`"
@@ -97,14 +114,16 @@ msgid ""
97114
"HTTP cookie handling for web *clients*. The :mod:`http.cookiejar` and :mod:"
98115
"`http.cookies` modules do not depend on each other."
99116
msgstr ""
117+
"用於 *網路客戶端* 的 HTTP cookie 處理。:mod:`http.cookiejar` 和 :mod:`http."
118+
"cookies` 模組不相依。"
100119

101120
#: ../../library/http.cookies.rst:70
102121
msgid ":rfc:`2109` - HTTP State Management Mechanism"
103-
msgstr ""
122+
msgstr ":rfc:`2109` - HTTP 狀態管理機制"
104123

105124
#: ../../library/http.cookies.rst:71
106125
msgid "This is the state management specification implemented by this module."
107-
msgstr ""
126+
msgstr "這是這個模組實作的狀態管理規範。"
108127

109128
#: ../../library/http.cookies.rst:77
110129
msgid "Cookie Objects"
@@ -116,19 +135,27 @@ msgid ""
116135
"``real_value`` can be any type. This method does no decoding in :class:"
117136
"`BaseCookie` --- it exists so it can be overridden."
118137
msgstr ""
138+
"從字串表示法回傳 ``(real_value, coded_value)`` 的元組。``real_value`` 可以是"
139+
"任何類型。此方法在 :class:`BaseCookie` 中不會進行解碼 --- 它存在以便可以被覆"
140+
"寫。"
119141

120142
#: ../../library/http.cookies.rst:89
121143
msgid ""
122144
"Return a tuple ``(real_value, coded_value)``. *val* can be any type, but "
123145
"``coded_value`` will always be converted to a string. This method does no "
124146
"encoding in :class:`BaseCookie` --- it exists so it can be overridden."
125147
msgstr ""
148+
"回傳一個元組 ``(real_value, coded_value)``。*val* 可以是任何類型,但 "
149+
"``coded_value`` 會總是轉換為字串。此方法在 :class:`BaseCookie` 中不做編碼 "
150+
"--- 它存在以便可以被覆寫。"
126151

127152
#: ../../library/http.cookies.rst:94
128153
msgid ""
129154
"In general, it should be the case that :meth:`value_encode` and :meth:"
130155
"`value_decode` are inverses on the range of *value_decode*."
131156
msgstr ""
157+
"一般來說,:meth:`value_encode` 和 :meth:`value_decode` 應該是在 "
158+
"*value_decode* 的範圍內的逆函式。"
132159

133160
#: ../../library/http.cookies.rst:100
134161
msgid ""
@@ -137,24 +164,31 @@ msgid ""
137164
"method. *sep* is used to join the headers together, and is by default the "
138165
"combination ``'\\r\\n'`` (CRLF)."
139166
msgstr ""
167+
"回傳一個適合作為 HTTP 標頭的字串表示。*attrs* 和 *header* 會傳送給每個 :"
168+
"class:`Morsel` 的 :meth:`~Morsel.output` 方法。*sep* 用來連結標頭,預設為 "
169+
"``\\\\r\\\\n``(CRLF)。"
140170

141171
#: ../../library/http.cookies.rst:108
142172
msgid ""
143173
"Return an embeddable JavaScript snippet, which, if run on a browser which "
144174
"supports JavaScript, will act the same as if the HTTP headers was sent."
145175
msgstr ""
176+
"回傳一個可嵌入的 JavaScript 片段,如果在支援 JavaScript 的瀏覽器上執行,它的"
177+
"行為會與如果 HTTP 標頭被傳送的情況相同。"
146178

147179
#: ../../library/http.cookies.rst:111 ../../library/http.cookies.rst:207
148180
#: ../../library/http.cookies.rst:215
149181
msgid "The meaning for *attrs* is the same as in :meth:`output`."
150-
msgstr ""
182+
msgstr "*attrs* 的意義與 :meth:`output` 相同。"
151183

152184
#: ../../library/http.cookies.rst:116
153185
msgid ""
154186
"If *rawdata* is a string, parse it as an ``HTTP_COOKIE`` and add the values "
155187
"found there as :class:`Morsel`\\ s. If it is a dictionary, it is equivalent "
156188
"to::"
157189
msgstr ""
190+
"如果 *rawdata* 是字串,則將其解析為 ``HTTP_COOKIE``,並將在其中找到的值當作 :"
191+
"class:`Morsel`\\ s 新增。如果它是一個字典,則等同於: ::"
158192

159193
#: ../../library/http.cookies.rst:119
160194
msgid ""
@@ -170,67 +204,76 @@ msgstr "Morsel 物件"
170204

171205
#: ../../library/http.cookies.rst:131
172206
msgid "Abstract a key/value pair, which has some :rfc:`2109` attributes."
173-
msgstr ""
207+
msgstr "抽象一個 key/value 對,它有一些 :rfc:`2109` 屬性。"
174208

175209
#: ../../library/http.cookies.rst:133
176210
msgid ""
177211
"Morsels are dictionary-like objects, whose set of keys is constant --- the "
178212
"valid :rfc:`2109` attributes, which are:"
179213
msgstr ""
214+
"Morsels 是一種類似字典的物件,其鍵的集合是固定的 --- 有效的 :rfc:`2109` 屬"
215+
"性,它們是:"
180216

181217
#: ../../library/http.cookies.rst:146
182218
msgid ""
183219
"The attribute :attr:`httponly` specifies that the cookie is only transferred "
184220
"in HTTP requests, and is not accessible through JavaScript. This is intended "
185221
"to mitigate some forms of cross-site scripting."
186222
msgstr ""
223+
"屬性 :attr:`httponly` 指定 cookie 僅在 HTTP 請求中傳輸,而不可通過 "
224+
"JavaScript 存取。這是為了減輕某些形式的跨網站腳本攻擊。"
187225

188226
#: ../../library/http.cookies.rst:150
189227
msgid ""
190228
"The attribute :attr:`samesite` specifies that the browser is not allowed to "
191229
"send the cookie along with cross-site requests. This helps to mitigate CSRF "
192230
"attacks. Valid values for this attribute are \"Strict\" and \"Lax\"."
193231
msgstr ""
232+
"屬性 :attr:`samesite` 指定瀏覽器不能將 Cookie 與跨網站請求一起傳送。這有助於"
233+
"減輕 CSRF 攻擊。此屬性的有效值為 \"Strict\"\"Lax\"。"
194234

195235
#: ../../library/http.cookies.rst:154
196236
msgid "The keys are case-insensitive and their default value is ``''``."
197-
msgstr ""
237+
msgstr "鍵的大小寫不敏感,其預設值為 ``''``。"
198238

199239
#: ../../library/http.cookies.rst:156
200240
msgid ""
201241
":meth:`!__eq__` now takes :attr:`~Morsel.key` and :attr:`~Morsel.value` into "
202242
"account."
203243
msgstr ""
244+
":meth:`!__eq__` 現在會考慮 :attr:`~Morsel.key` 和 :attr:`~Morsel.value`。"
204245

205246
#: ../../library/http.cookies.rst:160
206247
msgid ""
207248
"Attributes :attr:`~Morsel.key`, :attr:`~Morsel.value` and :attr:`~Morsel."
208249
"coded_value` are read-only. Use :meth:`~Morsel.set` for setting them."
209250
msgstr ""
251+
"屬性 :attr:`~Morsel.key`、:attr:`~Morsel.value` 和 :attr:`~Morsel."
252+
"coded_value` 為只讀。請使用 :meth:`~Morsel.set` 來設定它們。"
210253

211254
#: ../../library/http.cookies.rst:165
212255
msgid "Added support for the :attr:`samesite` attribute."
213256
msgstr "新增 :attr:`samesite` 屬性的支援"
214257

215258
#: ../../library/http.cookies.rst:171
216259
msgid "The value of the cookie."
217-
msgstr ""
260+
msgstr "cookie 的值。"
218261

219262
#: ../../library/http.cookies.rst:176
220263
msgid "The encoded value of the cookie --- this is what should be sent."
221-
msgstr ""
264+
msgstr "cookie 的編碼值 --- 這是應該被傳送的值。"
222265

223266
#: ../../library/http.cookies.rst:181
224267
msgid "The name of the cookie."
225-
msgstr ""
268+
msgstr "cookie 的名稱。"
226269

227270
#: ../../library/http.cookies.rst:186
228271
msgid "Set the *key*, *value* and *coded_value* attributes."
229-
msgstr ""
272+
msgstr "設定 *key*、*value* 和 *coded_value* 屬性。"
230273

231274
#: ../../library/http.cookies.rst:191
232275
msgid "Whether *K* is a member of the set of keys of a :class:`Morsel`."
233-
msgstr ""
276+
msgstr "*K* 是 :class:`Morsel` 的鍵集中的成員嗎?"
234277

235278
#: ../../library/http.cookies.rst:196
236279
msgid ""
@@ -239,43 +282,52 @@ msgid ""
239282
"given, in which case it should be a list of attributes to use. *header* is "
240283
"by default ``\"Set-Cookie:\"``."
241284
msgstr ""
285+
"回傳 Morsel 的字串表示,適合作為 HTTP 標頭。預設會包含所有屬性,除非 *attrs* "
286+
"被提供,在此情況下,它應該是一個屬性清單,用來選擇要使用的屬性。預設的 "
287+
"*header* 是 ``\"Set-Cookie:\"``。"
242288

243289
#: ../../library/http.cookies.rst:204
244290
msgid ""
245291
"Return an embeddable JavaScript snippet, which, if run on a browser which "
246292
"supports JavaScript, will act the same as if the HTTP header was sent."
247293
msgstr ""
294+
"回傳一個可嵌入的 JavaScript 片段,如果在支援 JavaScript 的瀏覽器上執行,它的"
295+
"行為與如果 HTTP 標頭被傳送的情況相同。"
248296

249297
#: ../../library/http.cookies.rst:212
250298
msgid ""
251299
"Return a string representing the Morsel, without any surrounding HTTP or "
252300
"JavaScript."
253-
msgstr ""
301+
msgstr "回傳 Morsel 的字串表示,不包含任何 HTTP 或 JavaScript。"
254302

255303
#: ../../library/http.cookies.rst:220
256304
msgid ""
257305
"Update the values in the Morsel dictionary with the values in the dictionary "
258306
"*values*. Raise an error if any of the keys in the *values* dict is not a "
259307
"valid :rfc:`2109` attribute."
260308
msgstr ""
309+
"更新 Morsel 字典中的值為 *values* 字典中的值。如果 *values* 字典中的任何鍵不"
310+
"是有效的 :rfc:`2109` 屬性,則引發錯誤。"
261311

262312
#: ../../library/http.cookies.rst:224
263313
msgid "an error is raised for invalid keys."
264-
msgstr ""
314+
msgstr "對於無效的 key 會引發錯誤。"
265315

266316
#: ../../library/http.cookies.rst:230
267317
msgid "Return a shallow copy of the Morsel object."
268-
msgstr ""
318+
msgstr "回傳 Morsel 物件的淺複製。"
269319

270320
#: ../../library/http.cookies.rst:232
271321
msgid "return a Morsel object instead of a dict."
272-
msgstr ""
322+
msgstr "回傳 Morsel 物件而不是 dict。"
273323

274324
#: ../../library/http.cookies.rst:238
275325
msgid ""
276326
"Raise an error if key is not a valid :rfc:`2109` attribute, otherwise behave "
277327
"the same as :meth:`dict.setdefault`."
278328
msgstr ""
329+
"如果 key 不是一個有效的 :rfc:`2109` 屬性,則引發錯誤,否則行為與 :meth:`dict."
330+
"setdefault` 相同。"
279331

280332
#: ../../library/http.cookies.rst:245
281333
msgid "Example"
@@ -284,7 +336,7 @@ msgstr "範例"
284336
#: ../../library/http.cookies.rst:247
285337
msgid ""
286338
"The following example demonstrates how to use the :mod:`http.cookies` module."
287-
msgstr ""
339+
msgstr "以下範例示範如何使用 :mod:`http.cookies` 模組。"
288340

289341
#: ../../library/http.cookies.rst:249
290342
msgid ""
@@ -335,3 +387,49 @@ msgid ""
335387
"Set-Cookie: number=7\n"
336388
"Set-Cookie: string=seven"
337389
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

Comments
 (0)