@@ -96,7 +96,7 @@ msgid ""
9696"pyc` files."
9797msgstr ""
9898"Python 有另一個比較原始的序列化模組叫 :mod:`marshal`,不過其設計目的是為了支"
99- "援 Python 的預編譯功能 :file:`.pyc` 運作 。總地來說,沒事不要用 :mod:"
99+ "援 Python 的預編譯功能 :file:`.pyc` 的運作 。總地來說,沒事不要用 :mod:"
100100"`marshal`。"
101101
102102#: ../../library/pickle.rst:57
@@ -194,7 +194,7 @@ msgstr ""
194194"JSON 具有高互通性(interoperability)且在 Python 以外的環境也被大量利用,但 "
195195"pickle 只能在 Python 內使用。"
196196
197- # Skylull: [t ]
197+ # Skylull: [T ]
198198# introspection -> 自省
199199# introspection facilities -> 自省措施
200200# https://zh.wikipedia.org/wiki/%E5%86%85%E7%9C%81_(%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%A7%91%E5%AD%A6)
@@ -323,7 +323,7 @@ msgstr ""
323323"版本 5 的協定在 Python 3.8 被新增。現在能支援帶外資料(Out-of-band data)並加"
324324"速帶內資料的處理速度。請參閱 :pep:`574` 以了解第 5 版協定改進的細節。"
325325
326- # SkyLull: [t ]
326+ # SkyLull: [T ]
327327# persistent -> 持久
328328# data persistent -> 資料持久化
329329# https://zh.wikipedia.org/zh-
@@ -637,7 +637,7 @@ msgstr ""
637637msgid "See :ref:`pickle-persistent` for details and examples of uses."
638638msgstr "關於細節與用法範例請見 :ref:`pickle-persistent`。"
639639
640- # SkyLull: [t ]
640+ # SkyLull: [T ]
641641# dispatch table -> 調度表
642642# https://zh.wiktionary.org/zh-hant/dispatch_table
643643# reduce -> 縮減
@@ -857,8 +857,9 @@ msgstr ""
857857":class:`PickleBuffer` 物件僅能由 5 版或以上的 pickle 協定進行封裝。該物件亦能"
858858"被作為帶外資料來進行:ref:`帶外資料序列化 <pickle-oob>`"
859859
860- # SkyLull: [T] oh boy... 好多術語...
861- # format B: https://learn.microsoft.com/zh-tw/dotnet/standard/base-types/standard-numeric-format-strings#BFormatString
860+ # SkyLull: oh boy... 好多術語...
861+ # format B: https://learn.microsoft.com/zh-tw/dotnet/standard/base-
862+ # types/standard-numeric-format-strings#BFormatString
862863# C-contiguous, Fortran-contiguous: https://stackoverflow.com/a/26999092
863864#: ../../library/pickle.rst:480
864865msgid ""
@@ -994,13 +995,15 @@ msgstr ""
994995
995996#: ../../library/pickle.rst:553
996997msgid "Pickling Class Instances"
997- msgstr ""
998+ msgstr "Pickling 類別實例 "
998999
9991000#: ../../library/pickle.rst:557
10001001msgid ""
10011002"In this section, we describe the general mechanisms available to you to "
10021003"define, customize, and control how class instances are pickled and unpickled."
10031004msgstr ""
1005+ "在這一個章節,我們會講述如何封裝或拆封一個物件實例的相關機制,以方便你進行自"
1006+ "訂。"
10041007
10051008#: ../../library/pickle.rst:560
10061009msgid ""
@@ -1011,12 +1014,17 @@ msgid ""
10111014"creates an uninitialized instance and then restores the saved attributes. "
10121015"The following code shows an implementation of this behaviour::"
10131016msgstr ""
1017+ "大部分的實例不需要額外的程式碼就已經是可封裝的了。在這樣的預設狀況中,pickle "
1018+ "模組透過自省機制來取得類別及其實例的屬性。當類別實例被拆封時,其 :meth:"
1019+ "`~object.__init__` 方法通常*不會*被呼叫。預設行為首先會建立一個未初始化的實"
1020+ "例,然後還原紀錄中的屬性。以下程式碼的實作展示了前述行為::"
10141021
10151022#: ../../library/pickle.rst:575
10161023msgid ""
10171024"Classes can alter the default behaviour by providing one or several special "
10181025"methods:"
10191026msgstr ""
1027+ "被封裝的目標類別可以提供一個或數個下列特殊方法來改變 pickle 的預設行為:"
10201028
10211029#: ../../library/pickle.rst:580
10221030msgid ""
@@ -1027,36 +1035,48 @@ msgid ""
10271035"dictionary of named arguments for constructing the object. Those will be "
10281036"passed to the :meth:`__new__` method upon unpickling."
10291037msgstr ""
1038+ "在第 2 版協定或更新的版本中,有實作 :meth:`__getnewargs_ex__` 方法的類別,可"
1039+ "以決定在拆封時要傳遞給 :meth:`__new__` 方法的值。該方法必須回傳一個 ``(args, "
1040+ "kwargs)`` 的組合,其中 *args* 是一個位置引數的元組(tuple),*kwargs* 是一個"
1041+ "用於建構物件的命名引數字典。這些資訊將在拆封時傳遞給 :meth:`__new__` 方法。"
10301042
10311043#: ../../library/pickle.rst:588
10321044msgid ""
10331045"You should implement this method if the :meth:`__new__` method of your class "
10341046"requires keyword-only arguments. Otherwise, it is recommended for "
10351047"compatibility to implement :meth:`__getnewargs__`."
10361048msgstr ""
1049+ "如果目標類別的方法 :meth:`__new__` 需要僅限關鍵字的參數時,你應該實作此方法。"
1050+ "否則,為了提高相容性,建議你改為實作 :meth:`__getnewargs__`。"
10371051
10381052#: ../../library/pickle.rst:592
10391053msgid ":meth:`__getnewargs_ex__` is now used in protocols 2 and 3."
1040- msgstr ""
1054+ msgstr "在第 2、3 版的協定中現在改為使用 :meth:`__getnewargs_ex__`。 "
10411055
10421056#: ../../library/pickle.rst:598
10431057msgid ""
10441058"This method serves a similar purpose as :meth:`__getnewargs_ex__`, but "
10451059"supports only positional arguments. It must return a tuple of arguments "
10461060"``args`` which will be passed to the :meth:`__new__` method upon unpickling."
10471061msgstr ""
1062+ "此方法與 :meth:`__getnewargs_ex__` 的目的一樣,但僅支援位置參數。它必須回傳一"
1063+ "個由傳入引數所組成的元組(tuple)``args``,這些引數會在拆封時傳遞給 :meth:"
1064+ "`__new__` 方法。"
10481065
10491066#: ../../library/pickle.rst:602
10501067msgid ""
10511068":meth:`__getnewargs__` will not be called if :meth:`__getnewargs_ex__` is "
10521069"defined."
10531070msgstr ""
1071+ "當有定義 :meth:`__getnewargs_ex__` 的時候便不會呼叫 :meth:`__getnewargs__`。"
10541072
10551073#: ../../library/pickle.rst:605
10561074msgid ""
10571075"Before Python 3.6, :meth:`__getnewargs__` was called instead of :meth:"
10581076"`__getnewargs_ex__` in protocols 2 and 3."
10591077msgstr ""
1078+ "在 Python 3.6 之前、版本 2 和版本 3 的協定中,會呼叫 :meth:`__getnewargs__` "
1079+ "而非 :meth:`__getnewargs_ex__`。"
10601080
10611081#: ../../library/pickle.rst:612
10621082msgid ""
@@ -1065,18 +1085,25 @@ msgid ""
10651085"pickled as the contents for the instance, instead of a default state. There "
10661086"are several cases:"
10671087msgstr ""
1088+ "目標類別可以透過覆寫方法 :meth:`__getstate__` 進一步影響其實例被封裝的方式。"
1089+ "封裝時,呼叫該方法所返回的物件將作為該實例的內容被封裝、而非一個預設狀態。以"
1090+ "下列出幾種預設狀態:"
10681091
10691092#: ../../library/pickle.rst:617
10701093msgid ""
10711094"For a class that has no instance :attr:`~object.__dict__` and no :attr:"
10721095"`~object.__slots__`, the default state is ``None``."
10731096msgstr ""
1097+ "沒有 :attr:`~object.__dict__` 和 :attr:`~object.__slots__` 實例的類別,其預設"
1098+ "狀態為 ``None``。"
10741099
10751100#: ../../library/pickle.rst:620
10761101msgid ""
10771102"For a class that has an instance :attr:`~object.__dict__` and no :attr:"
10781103"`~object.__slots__`, the default state is ``self.__dict__``."
10791104msgstr ""
1105+ "有 :attr:`~object.__dict__` 實例、但沒有 :attr:`~object.__slots__` 實例的類"
1106+ "別,其預設狀態為 ``self.__dict__``。"
10801107
10811108#: ../../library/pickle.rst:623
10821109msgid ""
@@ -1085,6 +1112,10 @@ msgid ""
10851112"``self.__dict__``, and a dictionary mapping slot names to slot values. Only "
10861113"slots that have a value are included in the latter."
10871114msgstr ""
1115+ "有 :attr:`~object.__dict__` 和 :attr:`~object.__slots__` 實例的類別,其預設狀"
1116+ "態是一個含有兩個字典的元組(tuple),該二字典分別為 ``self.__dict__`` 本身,"
1117+ "和紀錄欄位(slot)名稱和值對應關係的字典(只有含有值的欄位(slot)會被紀錄其"
1118+ "中)。"
10881119
10891120#: ../../library/pickle.rst:629
10901121msgid ""
@@ -1093,12 +1124,15 @@ msgid ""
10931124"``None`` and whose second item is a dictionary mapping slot names to slot "
10941125"values described in the previous bullet."
10951126msgstr ""
1127+ "沒有 :attr:`~object.__dict__` 但有 :attr:`~object.__slots__` 實例的類別,其預"
1128+ "設狀態是一個二元組(tuple),元組中的第一個值是 ``None``,第二個值則是紀錄欄"
1129+ "位(slot)名稱和值對應關係的字典(與前一項提到的字典是同一個)。"
10961130
10971131#: ../../library/pickle.rst:634
10981132msgid ""
10991133"Added the default implementation of the ``__getstate__()`` method in the :"
11001134"class:`object` class."
1101- msgstr ""
1135+ msgstr "在 :class:`object` 類別中增加預設的 ``__getstate__()`` 實作。 "
11021136
11031137#: ../../library/pickle.rst:641
11041138msgid ""
@@ -1107,19 +1141,26 @@ msgid ""
11071141"state object to be a dictionary. Otherwise, the pickled state must be a "
11081142"dictionary and its items are assigned to the new instance's dictionary."
11091143msgstr ""
1144+ "在拆封時,如果類別定義了 :meth:`__setstate__`,則會使用拆封後的狀態呼叫它。在"
1145+ "這種情況下,紀錄狀態的物件不需要是字典(dictionary)。否則,封裝時的狀態紀錄"
1146+ "必須是一個字典,其紀錄的項目將被賦值給新實例的字典。"
11101147
11111148#: ../../library/pickle.rst:648
11121149msgid ""
11131150"If :meth:`__reduce__` returns a state with value ``None`` at pickling, the :"
11141151"meth:`__setstate__` method will not be called upon unpickling."
11151152msgstr ""
1153+ "如果 :meth:`__reduce__` 在封裝時返回了 ``None`` 狀態,則拆封時就不會去呼叫 :"
1154+ "meth:`__setstate__`。"
11161155
11171156#: ../../library/pickle.rst:652
11181157msgid ""
11191158"Refer to the section :ref:`pickle-state` for more information about how to "
11201159"use the methods :meth:`~object.__getstate__` and :meth:`~object."
11211160"__setstate__`."
11221161msgstr ""
1162+ "參閱 :ref:`pickle-state` 以了解 :meth:`~object.__getstate__` 和 :meth:"
1163+ "`~object.__setstate__` 的使用方法。"
11231164
11241165#: ../../library/pickle.rst:657
11251166msgid ""
@@ -1130,6 +1171,10 @@ msgid ""
11301171"such an invariant, as :meth:`~object.__init__` is not called when unpickling "
11311172"an instance."
11321173msgstr ""
1174+ "在拆封時,某些方法如 :meth:`~object.__getattr__`、:meth:`~object."
1175+ "__getattribute__` 或 :meth:`~object.__setattr__` 可能會在建立實例時被呼叫。如"
1176+ "果這些方法依賴了某些實例內部的不變性,則應實作 :meth:`~object.__new__` 以建立"
1177+ "此不變性,因為在拆封實例時不會呼叫 :meth:`~object.__init__`。"
11331178
11341179#: ../../library/pickle.rst:666
11351180msgid ""
0 commit comments