Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate library/http.cookies #1014

Open
wants to merge 3 commits into
base: 3.13
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 116 additions & 19 deletions library/http.cookies.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgstr ""
"Project-Id-Version: Python 3.13\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-14 00:14+0000\n"
"PO-Revision-Date: 2016-11-19 00:31+0000\n"
"PO-Revision-Date: 2024-12-24 18:49+0800\n"
"Last-Translator: Liang-Bo Wang <me@liang2.tw>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
"tw)\n"
Expand All @@ -32,6 +32,9 @@ msgid ""
"string-only cookies, and provides an abstraction for having any serializable "
"data-type as cookie value."
msgstr ""
":mod:`http.cookies` 模組定義了 cookie 概念的抽象化的類別,cookie 是一種 HTTP "
"狀態管理機制。它支援簡單的純字串 cookie,也提供了將任何可序列化的資料型別作"
"為 cookie 值的抽象化。"

#: ../../library/http.cookies.rst:19
msgid ""
Expand All @@ -42,30 +45,39 @@ msgid ""
"comes to cookie handling. As a result, this module now uses parsing rules "
"that are a bit less strict than they once were."
msgstr ""
"此模組原先嚴格遵循了 :rfc:`2109` 和 :rfc:`2068` 規範所描述的剖析規則。自從發"
"現 MSIE 3.0x 並不遵循這些規範所描述的字元規則,許多當前的瀏覽器和伺服器也在處"
"理 cookie 時放寬了剖析規則。因此,此模組現在使用的剖析規則比之前的更為寬鬆。"

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

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

#: ../../library/http.cookies.rst:36
msgid ""
"On encountering an invalid cookie, :exc:`CookieError` is raised, so if your "
"cookie data comes from a browser you should always prepare for invalid data "
"and catch :exc:`CookieError` on parsing."
msgstr ""
"當遇到無效的 cookie 時,會引發 :exc:`CookieError`,因此如果你的 cookie 資料來"
"自瀏覽器,在剖析時你應該總是為無效資料作準備並捕捉 :exc:`CookieError`。"

#: ../../library/http.cookies.rst:43
msgid ""
"Exception failing because of :rfc:`2109` invalidity: incorrect attributes, "
"incorrect :mailheader:`Set-Cookie` header, etc."
msgstr ""
"因為不符合 :rfc:`2109` 而引發的例外:不正確的屬性、不正確的 :mailheader:`Set-"
"Cookie` 標頭等。"

#: ../../library/http.cookies.rst:49
msgid ""
Expand All @@ -74,10 +86,12 @@ msgid ""
"value, the value is first converted to a :class:`Morsel` containing the key "
"and the value."
msgstr ""
"這個類別是一個類似字典的物件,其中的鍵是字串,而值則是 :class:`Morsel` 實例。"
"請注意,當設定鍵的值時,值會先被轉換為一個包含該鍵和值的 :class:`Morsel`。"

#: ../../library/http.cookies.rst:53
msgid "If *input* is given, it is passed to the :meth:`load` method."
msgstr ""
msgstr "如果有給定 *input*,它會被傳遞給 :meth:`load` 方法。"

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

#: ../../library/http.cookies.rst:66
msgid "Module :mod:`http.cookiejar`"
Expand All @@ -97,14 +115,16 @@ msgid ""
"HTTP cookie handling for web *clients*. The :mod:`http.cookiejar` and :mod:"
"`http.cookies` modules do not depend on each other."
msgstr ""
"用於網路\\ *用戶端*\\ 的 HTTP cookie 處理。:mod:`http.cookiejar` 和 :mod:"
"`http.cookies` 模組互不相依。"

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

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

#: ../../library/http.cookies.rst:77
msgid "Cookie Objects"
Expand All @@ -116,19 +136,26 @@ msgid ""
"``real_value`` can be any type. This method does no decoding in :class:"
"`BaseCookie` --- it exists so it can be overridden."
msgstr ""
"從字串表示回傳 ``(real_value, coded_value)`` 的元組。``real_value`` 可以是任"
"何型別。此方法在 :class:`BaseCookie` 中不做解碼 --- 它存在以便可以被覆寫。"

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

#: ../../library/http.cookies.rst:94
msgid ""
"In general, it should be the case that :meth:`value_encode` and :meth:"
"`value_decode` are inverses on the range of *value_decode*."
msgstr ""
"一般來說,:meth:`value_encode` 和 :meth:`value_decode` 應該在 *value_decode* "
"的範圍內是互逆的 (inverse)。"

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

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

#: ../../library/http.cookies.rst:111 ../../library/http.cookies.rst:207
#: ../../library/http.cookies.rst:215
msgid "The meaning for *attrs* is the same as in :meth:`output`."
msgstr ""
msgstr "*attrs* 的意義與 :meth:`output` 裡的相同。"

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

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

#: ../../library/http.cookies.rst:131
msgid "Abstract a key/value pair, which has some :rfc:`2109` attributes."
msgstr ""
msgstr "抽象化一個鍵 / 值對,它有一些 :rfc:`2109` 屬性。"

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

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

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

#: ../../library/http.cookies.rst:154
msgid "The keys are case-insensitive and their default value is ``''``."
msgstr ""
msgstr "鍵不區分大小寫,其預設值為 ``''``。"

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

#: ../../library/http.cookies.rst:160
msgid ""
"Attributes :attr:`~Morsel.key`, :attr:`~Morsel.value` and :attr:`~Morsel."
"coded_value` are read-only. Use :meth:`~Morsel.set` for setting them."
msgstr ""
"屬性 :attr:`~Morsel.key`、:attr:`~Morsel.value` 和 :attr:`~Morsel."
"coded_value` 是唯讀的。請使用 :meth:`~Morsel.set` 來設定它們。"

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

#: ../../library/http.cookies.rst:171
msgid "The value of the cookie."
msgstr ""
msgstr "cookie 的值。"

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

#: ../../library/http.cookies.rst:181
msgid "The name of the cookie."
msgstr ""
msgstr "cookie 的名稱。"

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

#: ../../library/http.cookies.rst:191
msgid "Whether *K* is a member of the set of keys of a :class:`Morsel`."
msgstr ""
msgstr "*K* 是否為 :class:`Morsel` 的鍵集合中的成員。"

#: ../../library/http.cookies.rst:196
msgid ""
Expand All @@ -239,43 +282,52 @@ msgid ""
"given, in which case it should be a list of attributes to use. *header* is "
"by default ``\"Set-Cookie:\"``."
msgstr ""
"回傳適合作為 HTTP 標頭傳送的 Morsel 的字串表示。預設會包含所有屬性,除非有給"
"定 *attrs*,在此情況下,它應該是一個要使用的屬性的串列。預設的 *header* 是 "
"``\"Set-Cookie:\"``。"

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

#: ../../library/http.cookies.rst:212
msgid ""
"Return a string representing the Morsel, without any surrounding HTTP or "
"JavaScript."
msgstr ""
msgstr "回傳表示 Morsel 的字串,不包含周圍任何的 HTTP 或 JavaScript。"

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

#: ../../library/http.cookies.rst:224
msgid "an error is raised for invalid keys."
msgstr ""
msgstr "對於無效的鍵會引發錯誤。"

#: ../../library/http.cookies.rst:230
msgid "Return a shallow copy of the Morsel object."
msgstr ""
msgstr "回傳 Morsel 物件的淺層複製。"

#: ../../library/http.cookies.rst:232
msgid "return a Morsel object instead of a dict."
msgstr ""
msgstr "回傳 Morsel 物件而不是字典。"

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

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

#: ../../library/http.cookies.rst:249
msgid ""
Expand Down Expand Up @@ -335,3 +387,48 @@ msgid ""
"Set-Cookie: number=7\n"
"Set-Cookie: string=seven"
msgstr ""
">>> from http import cookies\n"
">>> C = cookies.SimpleCookie()\n"
">>> C[\"fig\"] = \"newton\"\n"
">>> C[\"sugar\"] = \"wafer\"\n"
">>> print(C) # 產生 HTTP 標頭\n"
"Set-Cookie: fig=newton\n"
"Set-Cookie: sugar=wafer\n"
">>> print(C.output()) # 同上\n"
"Set-Cookie: fig=newton\n"
"Set-Cookie: sugar=wafer\n"
">>> C = cookies.SimpleCookie()\n"
">>> C[\"rocky\"] = \"road\"\n"
">>> C[\"rocky\"][\"path\"] = \"/cookie\"\n"
">>> print(C.output(header=\"Cookie:\"))\n"
"Cookie: rocky=road; Path=/cookie\n"
">>> print(C.output(attrs=[], header=\"Cookie:\"))\n"
"Cookie: rocky=road\n"
">>> C = cookies.SimpleCookie()\n"
">>> C.load(\"chips=ahoy; vienna=finger\") # 從字串(HTTP 標頭)載入\n"
">>> print(C)\n"
"Set-Cookie: chips=ahoy\n"
"Set-Cookie: vienna=finger\n"
">>> C = cookies.SimpleCookie()\n"
">>> C.load('keebler=\"E=everybody; L=\\\\\"Loves\\\\\"; fudge=\\\\012;\";')\n"
">>> print(C)\n"
"Set-Cookie: keebler=\"E=everybody; L=\\\"Loves\\\"; fudge=\\012;\"\n"
">>> C = cookies.SimpleCookie()\n"
">>> C[\"oreo\"] = \"doublestuff\"\n"
">>> C[\"oreo\"][\"path\"] = \"/\"\n"
">>> print(C)\n"
"Set-Cookie: oreo=doublestuff; Path=/\n"
">>> C = cookies.SimpleCookie()\n"
">>> C[\"twix\"] = \"none for you\"\n"
">>> C[\"twix\"].value\n"
"'none for you'\n"
">>> C = cookies.SimpleCookie()\n"
">>> C[\"number\"] = 7 # 等同於 C[\"number\"] = str(7)\n"
">>> C[\"string\"] = \"seven\"\n"
">>> C[\"number\"].value\n"
"'7'\n"
">>> C[\"string\"].value\n"
"'seven'\n"
">>> print(C)\n"
"Set-Cookie: number=7\n"
"Set-Cookie: string=seven"