From d3826beea4ee156fc38e460874b0697c896c5aac Mon Sep 17 00:00:00 2001 From: mindihx Date: Mon, 23 Dec 2024 16:27:53 +0800 Subject: [PATCH] Translate library/http.cookies --- library/http.cookies.po | 132 ++++++++++++++++++++++++++++++++++------ 1 file changed, 115 insertions(+), 17 deletions(-) diff --git a/library/http.cookies.po b/library/http.cookies.po index 283f303aa9..7c170d45c2 100644 --- a/library/http.cookies.po +++ b/library/http.cookies.po @@ -32,6 +32,8 @@ msgid "" "string-only cookies, and provides an abstraction for having any serializable " "data-type as cookie value." msgstr "" +":mod:`http.cookies` 模組定義了抽象 HTTP 狀態管理機制 (state management " +"mechanism) 的類別,它支援簡單的字串僅有的 cookie,並為 cookie 值提供了抽象。" #: ../../library/http.cookies.rst:19 msgid "" @@ -42,6 +44,9 @@ 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 "" @@ -49,10 +54,12 @@ msgid "" "``!#$%&'*+-.^_`|~:`` denote the set of valid characters allowed by this " "module in a cookie name (as :attr:`~Morsel.key`)." msgstr "" +"此模組在 cookie 名稱(:attr:`~Morsel.key`)中允許的有效字元為 :data:`string." +"ascii_letters`、:data:`string.digits` 和 ``!#$%&'*+-.^_`|~``。" #: ../../library/http.cookies.rst:30 msgid "Allowed ':' as a valid cookie name character." -msgstr "" +msgstr "允許 ':' 作為有效的 cookie 名稱字元。" #: ../../library/http.cookies.rst:36 msgid "" @@ -60,12 +67,16 @@ msgid "" "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 "" @@ -74,10 +85,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 "" @@ -87,6 +100,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`" @@ -97,14 +114,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" @@ -116,6 +135,9 @@ 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 "" @@ -123,12 +145,17 @@ msgid "" "``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* 的範圍內的逆函式。" #: ../../library/http.cookies.rst:100 msgid "" @@ -137,17 +164,22 @@ 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 "" @@ -155,6 +187,8 @@ msgid "" "found there as :class:`Morsel`\\ s. If it is a dictionary, it is equivalent " "to::" msgstr "" +"如果 *rawdata* 是字串,則將其解析為 ``HTTP_COOKIE``,並將在其中找到的值當作 :" +"class:`Morsel`\\ s 新增。如果它是一個字典,則等同於: ::" #: ../../library/http.cookies.rst:119 msgid "" @@ -170,13 +204,15 @@ msgstr "Morsel 物件" #: ../../library/http.cookies.rst:131 msgid "Abstract a key/value pair, which has some :rfc:`2109` attributes." -msgstr "" +msgstr "抽象一個 key/value 對,它有一些 :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 "" +"Morsels 是一種類似字典的物件,其鍵的集合是固定的 --- 有效的 :rfc:`2109` 屬" +"性,它們是:" #: ../../library/http.cookies.rst:146 msgid "" @@ -184,6 +220,8 @@ msgid "" "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 "" @@ -191,22 +229,27 @@ msgid "" "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." @@ -214,23 +257,23 @@ 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 "" @@ -239,18 +282,23 @@ msgid "" "given, in which case it should be a list of attributes to use. *header* is " "by default ``\"Set-Cookie:\"``." msgstr "" +"回傳 Morsel 的字串表示,適合作為 HTTP 標頭。預設會包含所有屬性,除非 *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 "" @@ -258,24 +306,28 @@ msgid "" "*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 "對於無效的 key 會引發錯誤。" #: ../../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 物件而不是 dict。" #: ../../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 "" +"如果 key 不是一個有效的 :rfc:`2109` 屬性,則引發錯誤,否則行為與 :meth:`dict." +"setdefault` 相同。" #: ../../library/http.cookies.rst:245 msgid "Example" @@ -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 "" @@ -335,3 +387,49 @@ 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) # generate HTTP headers\n" +"Set-Cookie: fig=newton\n" +"Set-Cookie: sugar=wafer\n" +">>> print(C.output()) # same thing\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\") # load from a string (HTTP " +"header)\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 # equivalent to 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"