@@ -96,7 +96,7 @@ msgid ""
96
96
"pyc` files."
97
97
msgstr ""
98
98
"Python 有另一個比較原始的序列化模組叫 :mod:`marshal`,不過其設計目的是為了支"
99
- "援 Python 的預編譯功能 :file:`.pyc` 運作 。總地來說,沒事不要用 :mod:"
99
+ "援 Python 的預編譯功能 :file:`.pyc` 的運作 。總地來說,沒事不要用 :mod:"
100
100
"`marshal`。"
101
101
102
102
#: ../../library/pickle.rst:57
@@ -194,7 +194,7 @@ msgstr ""
194
194
"JSON 具有高互通性(interoperability)且在 Python 以外的環境也被大量利用,但 "
195
195
"pickle 只能在 Python 內使用。"
196
196
197
- # Skylull: [t ]
197
+ # Skylull: [T ]
198
198
# introspection -> 自省
199
199
# introspection facilities -> 自省措施
200
200
# 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 ""
323
323
"版本 5 的協定在 Python 3.8 被新增。現在能支援帶外資料(Out-of-band data)並加"
324
324
"速帶內資料的處理速度。請參閱 :pep:`574` 以了解第 5 版協定改進的細節。"
325
325
326
- # SkyLull: [t ]
326
+ # SkyLull: [T ]
327
327
# persistent -> 持久
328
328
# data persistent -> 資料持久化
329
329
# https://zh.wikipedia.org/zh-
@@ -637,7 +637,7 @@ msgstr ""
637
637
msgid "See :ref:`pickle-persistent` for details and examples of uses."
638
638
msgstr "關於細節與用法範例請見 :ref:`pickle-persistent`。"
639
639
640
- # SkyLull: [t ]
640
+ # SkyLull: [T ]
641
641
# dispatch table -> 調度表
642
642
# https://zh.wiktionary.org/zh-hant/dispatch_table
643
643
# reduce -> 縮減
@@ -857,8 +857,9 @@ msgstr ""
857
857
":class:`PickleBuffer` 物件僅能由 5 版或以上的 pickle 協定進行封裝。該物件亦能"
858
858
"被作為帶外資料來進行:ref:`帶外資料序列化 <pickle-oob>`"
859
859
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
862
863
# C-contiguous, Fortran-contiguous: https://stackoverflow.com/a/26999092
863
864
#: ../../library/pickle.rst:480
864
865
msgid ""
@@ -994,13 +995,15 @@ msgstr ""
994
995
995
996
#: ../../library/pickle.rst:553
996
997
msgid "Pickling Class Instances"
997
- msgstr ""
998
+ msgstr "Pickling 類別實例 "
998
999
999
1000
#: ../../library/pickle.rst:557
1000
1001
msgid ""
1001
1002
"In this section, we describe the general mechanisms available to you to "
1002
1003
"define, customize, and control how class instances are pickled and unpickled."
1003
1004
msgstr ""
1005
+ "在這一個章節,我們會講述如何封裝或拆封一個物件實例的相關機制,以方便你進行自"
1006
+ "訂。"
1004
1007
1005
1008
#: ../../library/pickle.rst:560
1006
1009
msgid ""
@@ -1011,12 +1014,17 @@ msgid ""
1011
1014
"creates an uninitialized instance and then restores the saved attributes. "
1012
1015
"The following code shows an implementation of this behaviour::"
1013
1016
msgstr ""
1017
+ "大部分的實例不需要額外的程式碼就已經是可封裝的了。在這樣的預設狀況中,pickle "
1018
+ "模組透過自省機制來取得類別及其實例的屬性。當類別實例被拆封時,其 :meth:"
1019
+ "`~object.__init__` 方法通常*不會*被呼叫。預設行為首先會建立一個未初始化的實"
1020
+ "例,然後還原紀錄中的屬性。以下程式碼的實作展示了前述行為::"
1014
1021
1015
1022
#: ../../library/pickle.rst:575
1016
1023
msgid ""
1017
1024
"Classes can alter the default behaviour by providing one or several special "
1018
1025
"methods:"
1019
1026
msgstr ""
1027
+ "被封裝的目標類別可以提供一個或數個下列特殊方法來改變 pickle 的預設行為:"
1020
1028
1021
1029
#: ../../library/pickle.rst:580
1022
1030
msgid ""
@@ -1027,36 +1035,48 @@ msgid ""
1027
1035
"dictionary of named arguments for constructing the object. Those will be "
1028
1036
"passed to the :meth:`__new__` method upon unpickling."
1029
1037
msgstr ""
1038
+ "在第 2 版協定或更新的版本中,有實作 :meth:`__getnewargs_ex__` 方法的類別,可"
1039
+ "以決定在拆封時要傳遞給 :meth:`__new__` 方法的值。該方法必須回傳一個 ``(args, "
1040
+ "kwargs)`` 的組合,其中 *args* 是一個位置引數的元組(tuple),*kwargs* 是一個"
1041
+ "用於建構物件的命名引數字典。這些資訊將在拆封時傳遞給 :meth:`__new__` 方法。"
1030
1042
1031
1043
#: ../../library/pickle.rst:588
1032
1044
msgid ""
1033
1045
"You should implement this method if the :meth:`__new__` method of your class "
1034
1046
"requires keyword-only arguments. Otherwise, it is recommended for "
1035
1047
"compatibility to implement :meth:`__getnewargs__`."
1036
1048
msgstr ""
1049
+ "如果目標類別的方法 :meth:`__new__` 需要僅限關鍵字的參數時,你應該實作此方法。"
1050
+ "否則,為了提高相容性,建議你改為實作 :meth:`__getnewargs__`。"
1037
1051
1038
1052
#: ../../library/pickle.rst:592
1039
1053
msgid ":meth:`__getnewargs_ex__` is now used in protocols 2 and 3."
1040
- msgstr ""
1054
+ msgstr "在第 2、3 版的協定中現在改為使用 :meth:`__getnewargs_ex__`。 "
1041
1055
1042
1056
#: ../../library/pickle.rst:598
1043
1057
msgid ""
1044
1058
"This method serves a similar purpose as :meth:`__getnewargs_ex__`, but "
1045
1059
"supports only positional arguments. It must return a tuple of arguments "
1046
1060
"``args`` which will be passed to the :meth:`__new__` method upon unpickling."
1047
1061
msgstr ""
1062
+ "此方法與 :meth:`__getnewargs_ex__` 的目的一樣,但僅支援位置參數。它必須回傳一"
1063
+ "個由傳入引數所組成的元組(tuple)``args``,這些引數會在拆封時傳遞給 :meth:"
1064
+ "`__new__` 方法。"
1048
1065
1049
1066
#: ../../library/pickle.rst:602
1050
1067
msgid ""
1051
1068
":meth:`__getnewargs__` will not be called if :meth:`__getnewargs_ex__` is "
1052
1069
"defined."
1053
1070
msgstr ""
1071
+ "當有定義 :meth:`__getnewargs_ex__` 的時候便不會呼叫 :meth:`__getnewargs__`。"
1054
1072
1055
1073
#: ../../library/pickle.rst:605
1056
1074
msgid ""
1057
1075
"Before Python 3.6, :meth:`__getnewargs__` was called instead of :meth:"
1058
1076
"`__getnewargs_ex__` in protocols 2 and 3."
1059
1077
msgstr ""
1078
+ "在 Python 3.6 之前、版本 2 和版本 3 的協定中,會呼叫 :meth:`__getnewargs__` "
1079
+ "而非 :meth:`__getnewargs_ex__`。"
1060
1080
1061
1081
#: ../../library/pickle.rst:612
1062
1082
msgid ""
@@ -1065,18 +1085,25 @@ msgid ""
1065
1085
"pickled as the contents for the instance, instead of a default state. There "
1066
1086
"are several cases:"
1067
1087
msgstr ""
1088
+ "目標類別可以透過覆寫方法 :meth:`__getstate__` 進一步影響其實例被封裝的方式。"
1089
+ "封裝時,呼叫該方法所返回的物件將作為該實例的內容被封裝、而非一個預設狀態。以"
1090
+ "下列出幾種預設狀態:"
1068
1091
1069
1092
#: ../../library/pickle.rst:617
1070
1093
msgid ""
1071
1094
"For a class that has no instance :attr:`~object.__dict__` and no :attr:"
1072
1095
"`~object.__slots__`, the default state is ``None``."
1073
1096
msgstr ""
1097
+ "沒有 :attr:`~object.__dict__` 和 :attr:`~object.__slots__` 實例的類別,其預設"
1098
+ "狀態為 ``None``。"
1074
1099
1075
1100
#: ../../library/pickle.rst:620
1076
1101
msgid ""
1077
1102
"For a class that has an instance :attr:`~object.__dict__` and no :attr:"
1078
1103
"`~object.__slots__`, the default state is ``self.__dict__``."
1079
1104
msgstr ""
1105
+ "有 :attr:`~object.__dict__` 實例、但沒有 :attr:`~object.__slots__` 實例的類"
1106
+ "別,其預設狀態為 ``self.__dict__``。"
1080
1107
1081
1108
#: ../../library/pickle.rst:623
1082
1109
msgid ""
@@ -1085,6 +1112,10 @@ msgid ""
1085
1112
"``self.__dict__``, and a dictionary mapping slot names to slot values. Only "
1086
1113
"slots that have a value are included in the latter."
1087
1114
msgstr ""
1115
+ "有 :attr:`~object.__dict__` 和 :attr:`~object.__slots__` 實例的類別,其預設狀"
1116
+ "態是一個含有兩個字典的元組(tuple),該二字典分別為 ``self.__dict__`` 本身,"
1117
+ "和紀錄欄位(slot)名稱和值對應關係的字典(只有含有值的欄位(slot)會被紀錄其"
1118
+ "中)。"
1088
1119
1089
1120
#: ../../library/pickle.rst:629
1090
1121
msgid ""
@@ -1093,12 +1124,15 @@ msgid ""
1093
1124
"``None`` and whose second item is a dictionary mapping slot names to slot "
1094
1125
"values described in the previous bullet."
1095
1126
msgstr ""
1127
+ "沒有 :attr:`~object.__dict__` 但有 :attr:`~object.__slots__` 實例的類別,其預"
1128
+ "設狀態是一個二元組(tuple),元組中的第一個值是 ``None``,第二個值則是紀錄欄"
1129
+ "位(slot)名稱和值對應關係的字典(與前一項提到的字典是同一個)。"
1096
1130
1097
1131
#: ../../library/pickle.rst:634
1098
1132
msgid ""
1099
1133
"Added the default implementation of the ``__getstate__()`` method in the :"
1100
1134
"class:`object` class."
1101
- msgstr ""
1135
+ msgstr "在 :class:`object` 類別中增加預設的 ``__getstate__()`` 實作。 "
1102
1136
1103
1137
#: ../../library/pickle.rst:641
1104
1138
msgid ""
@@ -1107,19 +1141,26 @@ msgid ""
1107
1141
"state object to be a dictionary. Otherwise, the pickled state must be a "
1108
1142
"dictionary and its items are assigned to the new instance's dictionary."
1109
1143
msgstr ""
1144
+ "在拆封時,如果類別定義了 :meth:`__setstate__`,則會使用拆封後的狀態呼叫它。在"
1145
+ "這種情況下,紀錄狀態的物件不需要是字典(dictionary)。否則,封裝時的狀態紀錄"
1146
+ "必須是一個字典,其紀錄的項目將被賦值給新實例的字典。"
1110
1147
1111
1148
#: ../../library/pickle.rst:648
1112
1149
msgid ""
1113
1150
"If :meth:`__reduce__` returns a state with value ``None`` at pickling, the :"
1114
1151
"meth:`__setstate__` method will not be called upon unpickling."
1115
1152
msgstr ""
1153
+ "如果 :meth:`__reduce__` 在封裝時返回了 ``None`` 狀態,則拆封時就不會去呼叫 :"
1154
+ "meth:`__setstate__`。"
1116
1155
1117
1156
#: ../../library/pickle.rst:652
1118
1157
msgid ""
1119
1158
"Refer to the section :ref:`pickle-state` for more information about how to "
1120
1159
"use the methods :meth:`~object.__getstate__` and :meth:`~object."
1121
1160
"__setstate__`."
1122
1161
msgstr ""
1162
+ "參閱 :ref:`pickle-state` 以了解 :meth:`~object.__getstate__` 和 :meth:"
1163
+ "`~object.__setstate__` 的使用方法。"
1123
1164
1124
1165
#: ../../library/pickle.rst:657
1125
1166
msgid ""
@@ -1130,6 +1171,10 @@ msgid ""
1130
1171
"such an invariant, as :meth:`~object.__init__` is not called when unpickling "
1131
1172
"an instance."
1132
1173
msgstr ""
1174
+ "在拆封時,某些方法如 :meth:`~object.__getattr__`、:meth:`~object."
1175
+ "__getattribute__` 或 :meth:`~object.__setattr__` 可能會在建立實例時被呼叫。如"
1176
+ "果這些方法依賴了某些實例內部的不變性,則應實作 :meth:`~object.__new__` 以建立"
1177
+ "此不變性,因為在拆封實例時不會呼叫 :meth:`~object.__init__`。"
1133
1178
1134
1179
#: ../../library/pickle.rst:666
1135
1180
msgid ""
0 commit comments