@@ -25,7 +25,7 @@ msgstr ""
2525
2626#: ../../howto/cporting.rst:7
2727msgid "Porting Extension Modules to Python 3"
28- msgstr ""
28+ msgstr "将扩展模块移植到 Python 3 "
2929
3030#: ../../howto/cporting.rst:0
3131msgid "author"
@@ -47,36 +47,39 @@ msgid ""
4747" obvious on the C level. This document endeavors to document "
4848"incompatibilities and how they can be worked around."
4949msgstr ""
50+ "尽管更改 C-API 并不是 Python 3 的目标之一,但许多 Python 级别的更改使得 Python 2 的 API "
51+ "无法完整实现。实际上,一些变化如 :func:`int` 和 :func:`long` 的统一在 C "
52+ "级别更明显。本文档致力于记录不兼容性以及如何解决这些问题。"
5053
5154#: ../../howto/cporting.rst:23
5255msgid "Conditional compilation"
53- msgstr ""
56+ msgstr "条件编译 "
5457
5558#: ../../howto/cporting.rst:25
5659msgid ""
5760"The easiest way to compile only some code for Python 3 is to check if "
5861":c:macro:`PY_MAJOR_VERSION` is greater than or equal to 3. ::"
59- msgstr ""
62+ msgstr "仅编译 Python 3 的一些代码的最简单方法是检查 :c:macro:`PY_MAJOR_VERSION` 是否大于或等于3。 :: "
6063
6164#: ../../howto/cporting.rst:32
6265msgid ""
6366"API functions that are not present can be aliased to their equivalents "
6467"within conditional blocks."
65- msgstr ""
68+ msgstr "不存在的 API 函数可以在条件块中别名为它们的等价物。 "
6669
6770#: ../../howto/cporting.rst:37
6871msgid "Changes to Object APIs"
69- msgstr ""
72+ msgstr "对象API的更改 "
7073
7174#: ../../howto/cporting.rst:39
7275msgid ""
7376"Python 3 merged together some types with similar functions while cleanly "
7477"separating others."
75- msgstr ""
78+ msgstr "Python 3 将一些具有类似功能的类型合并在一起,同时干净地分离了其他类型。 "
7679
7780#: ../../howto/cporting.rst:44
7881msgid "str/unicode Unification"
79- msgstr ""
82+ msgstr "str/unicode 统一 "
8083
8184#: ../../howto/cporting.rst:46
8285msgid ""
@@ -92,10 +95,18 @@ msgid ""
9295"Python 2. The following example shows best practices with regards to "
9396":c:type:`PyUnicode`, :c:type:`PyString`, and :c:type:`PyBytes`. ::"
9497msgstr ""
98+ "Python 3 的 :func:`str` 类型相当于 Python 2 的 :func:`unicode` ; C函数被称为 "
99+ "``PyUnicode_*`` 。旧的 8 位字符串类型变为 :func:`bytes` ,其中 C 函数称为 ``PyBytes_*`` 。 "
100+ "Python 2.6 及更高版本提供了一个兼容性头文件 :file:`bytesobject.h` ,将 ``PyBytes`` 名称映射到 "
101+ "``PyString`` 。 为了保持与 Python 3 的最佳兼容性, :c:type:`PyUnicode` 应该用于文本数据,并且 "
102+ ":c:type:`PyBytes` 用于二进制数据。同样重要的是要记住 :c:type:`pyBytes` 和 Python 3中的 "
103+ ":c:type:`PyUnicode` 不可互换,如 :c:type:`PyString` 和 :c:type:`PyUnicode` 在 Python"
104+ " 2 以下中示例显示了以下方面的最佳实践 :c:type:`PyUnicode` 、 :c:type:`PyString` 和 "
105+ ":c:type:`PyBytes` 。::"
95106
96107#: ../../howto/cporting.rst:95
97108msgid "long/int Unification"
98- msgstr ""
109+ msgstr "long/int 统一 "
99110
100111#: ../../howto/cporting.rst:97
101112msgid ""
@@ -104,10 +115,13 @@ msgid ""
104115"Python 2 was removed. In the C-API, ``PyInt_*`` functions are replaced by "
105116"their ``PyLong_*`` equivalents."
106117msgstr ""
118+ "Python 3 只有一个整数类型, :func:`int` 。但它实际上对应于Python 2 :func:`long` 类型 —— 删除了 "
119+ "Python 2 中使用的 :func:`int` 类型。在 C-API 中, ``PyInt_*`` 函数被它们等价的 ``PyLong_*`` "
120+ "替换。"
107121
108122#: ../../howto/cporting.rst:104
109123msgid "Module initialization and state"
110- msgstr ""
124+ msgstr "模块初始化和状态 "
111125
112126#: ../../howto/cporting.rst:106
113127msgid ""
@@ -117,10 +131,13 @@ msgid ""
117131"correctly in both Python 2 and Python 3 is tricky. The following simple "
118132"example demonstrates how. ::"
119133msgstr ""
134+ "Python 3 有一个改进的扩展模块初始化系统。(参见 :pep:`3121` "
135+ "。)而不是将模块状态存储在全局变量中,它们应该存储在特定于解释器的结构中。创建在 Python 2 和 Python 3 "
136+ "中正确运行的模块非常棘手。以下简单示例演示了如何操作。::"
120137
121138#: ../../howto/cporting.rst:197
122139msgid "CObject replaced with Capsule"
123- msgstr ""
140+ msgstr "CObject 替换为 Capsule "
124141
125142#: ../../howto/cporting.rst:199
126143msgid ""
@@ -131,6 +148,10 @@ msgid ""
131148"relied on undefined behavior in C. (For further reading on the rationale "
132149"behind Capsules, please see :issue:`5630`.)"
133150msgstr ""
151+ ":c:type:`Capsule` 对象是在 Python 3.1 和 2.7 中引入的,用于替换 :c:type:`CObject` 。 "
152+ "CObject 是有用的,但是 :c:type:`CObject` API 是有问题的:它不允许区分有效的 CObject ,这导致不匹配的 "
153+ "CObject 使解释器崩溃,并且它的一些 API 依赖于 C 中的未定义行为。有关 Capsule 背后的基本原理的进一步阅读,请参阅 "
154+ ":issue:`5630` 。)"
134155
135156#: ../../howto/cporting.rst:206
136157msgid ""
@@ -142,6 +163,10 @@ msgid ""
142163"support both CObjects and Capsules. (Note that Python 3.0 is no longer "
143164"supported, and it is not recommended for production use.)"
144165msgstr ""
166+ "如果你当前正在使用 CObject ,并且想要迁移到 3.1 或更高版本,则需要切换到 Capsules 。 :c:type:`CObject` 在 "
167+ "3.1 和 2.7 中已弃用,在 Python 3.2 中已完全删除。如果你只支持 2.7 或 3.1 及以上,你可以简单地切换到 "
168+ ":c:type:`Capsule` 。如果你需要支持 Python 3.0 或早于 2.7 的 Python 版本,则必须同时支持 CObject 和 "
169+ "Capsule 。(请注意,不再支持 Python 3.0 ,不建议将其用于生产用途。)"
145170
146171#: ../../howto/cporting.rst:216
147172msgid ""
@@ -151,6 +176,9 @@ msgid ""
151176"automatically use Capsules in versions of Python with Capsules, and switch "
152177"to CObjects when Capsules are unavailable."
153178msgstr ""
179+ "以下示例头文件 :file:`capsulethunk.h` 可以为你解决问题。只需针对 :c:type:`Capsule` API "
180+ "编写代码,并在以下文件后包含此头文件 :file:`Python.h` 。你的代码将自动在带有 Capsule 的 Python 版本中使用 "
181+ "Capsules ,并在 Capsule 不可用时切换到 CObjects 。"
154182
155183#: ../../howto/cporting.rst:223
156184msgid ""
@@ -160,21 +188,26 @@ msgid ""
160188":file:`capsulethunk.h` behave slightly differently from real Capsules. "
161189"Specifically:"
162190msgstr ""
191+ ":file:`capsulethunk.h` 使用 CObject 模拟 Capsules 。 但是, :c:type:`CObject` "
192+ "没有提供存储胶囊的“名称”的地方。因此,模拟 :c:type:`Capsule` 对象由 :file:`capsulethunk.h` "
193+ "创建,其行为与真实 Capsule 略有不同。特别地:"
163194
164195#: ../../howto/cporting.rst:228
165196msgid "The name parameter passed in to :c:func:`PyCapsule_New` is ignored."
166- msgstr ""
197+ msgstr "传递给 :c:func:`PyCapsule_New` 的 name 参数被忽略。 "
167198
168199#: ../../howto/cporting.rst:230
169200msgid ""
170201"The name parameter passed in to :c:func:`PyCapsule_IsValid` and "
171202":c:func:`PyCapsule_GetPointer` is ignored, and no error checking of the name"
172203" is performed."
173204msgstr ""
205+ "传入以下命令的 name 参数 :c:func:`PyCapsule_IsValid` 和 :c:func:`PyCapsule_GetPointer`"
206+ " 被忽略,并且不执行错误检查。"
174207
175208#: ../../howto/cporting.rst:234
176209msgid ":c:func:`PyCapsule_GetName` always returns NULL."
177- msgstr ""
210+ msgstr ":c:func:`PyCapsule_GetName` 总是返回 NULL 。 "
178211
179212#: ../../howto/cporting.rst:236
180213msgid ""
@@ -184,21 +217,27 @@ msgid ""
184217"If this is inconvenient, feel free to modify your local copy as you see "
185218"fit.)"
186219msgstr ""
220+ ":c:func:`PyCapsule_SetName` 总是引发异常并返回失败。(由于无法在 CObject 中存储名称,因此 "
221+ ":c:func:`PyCapsule_SetName` 的明显失败被认为优于静默失败。如果这样不方便,请随意根据需要修改本地副本。)"
187222
188223#: ../../howto/cporting.rst:243
189224msgid ""
190225"You can find :file:`capsulethunk.h` in the Python source distribution as "
191226":source:`Doc/includes/capsulethunk.h`. We also include it here for your "
192227"convenience:"
193228msgstr ""
229+ "你可以在 Python 源代码分发中的 :source:`Doc/includes/capsulethunk.h` 找到 "
230+ ":file:`capsulethunk.h` 。为方便起见,我们还将其包含在此处:"
194231
195232#: ../../howto/cporting.rst:252
196233msgid "Other options"
197- msgstr ""
234+ msgstr "其他选项 "
198235
199236#: ../../howto/cporting.rst:254
200237msgid ""
201238"If you are writing a new extension module, you might consider `Cython "
202239"<http://cython.org/>`_. It translates a Python-like language to C. The "
203240"extension modules it creates are compatible with Python 3 and Python 2."
204241msgstr ""
242+ "如果你正在编写新的扩展模块,你可能会考虑 `Cython <http://cython.org/>`_ 。 它将类似 Python 的语言转换为 C "
243+ "。它创建的扩展模块与 Python 3 和 Python 2 兼容。"
0 commit comments