11# SOME DESCRIPTIVE TITLE.
2- # Copyright (C) 2001-2018 , Python Software Foundation
2+ # Copyright (C) 2001-2019 , Python Software Foundation
33# This file is distributed under the same license as the Python package.
44# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
55#
8899# Tony Tong <[email protected] >, 20181010# ww song <[email protected] >, 201811+ # gashero liu <[email protected] >, 20191112#
1213#, fuzzy
1314msgid ""
1415msgstr ""
1516"Project-Id-Version : Python 3.7\n "
1617"Report-Msgid-Bugs-To : \n "
17- "POT-Creation-Date : 2018-11 -01 09:38 +0900\n "
18+ "POT-Creation-Date : 2019-01 -01 10:14 +0900\n "
1819"PO-Revision-Date : 2017-02-16 17:42+0000\n "
19- "Last-Translator : ww song <sww4718168 @gmail.com>, 2018 \n "
20+ "Last-Translator : gashero liu <harry.python @gmail.com>, 2019 \n "
2021"Language-Team : Chinese (China) (https://www.transifex.com/python-doc/teams/5390/zh_CN/)\n "
2122"MIME-Version : 1.0\n "
2223"Content-Type : text/plain; charset=UTF-8\n "
@@ -26,15 +27,15 @@ msgstr ""
2627
2728#: ../../extending/extending.rst:8
2829msgid "Extending Python with C or C++"
29- msgstr ""
30+ msgstr "使用C/C++扩展Python "
3031
3132#: ../../extending/extending.rst:10
3233msgid ""
3334"It is quite easy to add new built-in modules to Python, if you know how to "
3435"program in C. Such :dfn:`extension modules` can do two things that can't be"
3536" done directly in Python: they can implement new built-in object types, and "
3637"they can call C library functions and system calls."
37- msgstr ""
38+ msgstr "如果你会用C,实现Python嵌入模块很简单。利用扩展模块可做很多Python不方便做的事情,他们可以直接调用C库和系统调用。 "
3839
3940#: ../../extending/extending.rst:15
4041msgid ""
@@ -43,12 +44,14 @@ msgid ""
4344" aspects of the Python run-time system. The Python API is incorporated in a"
4445" C source file by including the header ``\" Python.h\" ``."
4546msgstr ""
47+ "为了支持扩展,Python API定义了一系列函数、宏和变量,提供了对Python运行时系统的访问支持。Python的C API由C源码组成,并包含 "
48+ "\" Python.h\" 头文件。"
4649
4750#: ../../extending/extending.rst:20
4851msgid ""
4952"The compilation of an extension module depends on its intended use as well "
5053"as on your system setup; details are given in later chapters."
51- msgstr ""
54+ msgstr "编写扩展模块与你的系统相关,下面会详解。 "
5255
5356#: ../../extending/extending.rst:25
5457msgid ""
@@ -65,7 +68,7 @@ msgstr ""
6568
6669#: ../../extending/extending.rst:40
6770msgid "A Simple Example"
68- msgstr ""
71+ msgstr "一个简单的例子 "
6972
7073#: ../../extending/extending.rst:42
7174msgid ""
@@ -82,17 +85,17 @@ msgid ""
8285"is called ``spam``, the C file containing its implementation is called "
8386":file:`spammodule.c`; if the module name is very long, like ``spammify``, "
8487"the module name can be just :file:`spammify.c`.)"
85- msgstr ""
88+ msgstr "一个C扩展模块的文件名可以直接是 模块名.c 或者是 模块名module.c 。第一行应该导入头文件: "
8689
8790#: ../../extending/extending.rst:58
8891msgid "The first line of our file can be::"
89- msgstr ""
92+ msgstr "文件的第一行应该是: "
9093
9194#: ../../extending/extending.rst:62
9295msgid ""
9396"which pulls in the Python API (you can add a comment describing the purpose "
9497"of the module and a copyright notice if you like)."
95- msgstr ""
98+ msgstr "这会导入Python API (你可以添加注释来描述模块的目标和版权提示)。 "
9699
97100#: ../../extending/extending.rst:67
98101msgid ""
@@ -113,13 +116,18 @@ msgid ""
113116"file does not exist on your system, it declares the functions "
114117":c:func:`malloc`, :c:func:`free` and :c:func:`realloc` directly."
115118msgstr ""
119+ "所有用户可见的符号都定义自爱 :file:`Python.h` 中,并拥有前缀 ``Py`` 或 ``PY`` "
120+ ",除了那些已经定义在i包准头文件的。为了方便,以及为了让Python解释器应用广泛, ``Python.h`` 也包含了少量标准头文件: "
121+ "``<stdio.h>`` , ``<string.h>`` , ``<errno.h>`` ,和 ``<stdlib.h>`` "
122+ "。如果后面的头文件在你的系统上不存在,还会直接声明函数 :c:func:`malloc` , :c:func:`free` 和 "
123+ ":c:func:`realloc` 。"
116124
117125#: ../../extending/extending.rst:79
118126msgid ""
119127"The next thing we add to our module file is the C function that will be "
120128"called when the Python expression ``spam.system(string)`` is evaluated "
121129"(we'll see shortly how it ends up being called)::"
122- msgstr ""
130+ msgstr "下面添加C代码到扩展模块,当调用 \" spam.system(string) \" 时会做出响应: "
123131
124132#: ../../extending/extending.rst:95
125133msgid ""
@@ -128,6 +136,8 @@ msgid ""
128136"the C function. The C function always has two arguments, conventionally "
129137"named *self* and *args*."
130138msgstr ""
139+ "有个直接翻译参数列表的方法(例如单独的 ``“ls-l\" ``)到要传递给C函数的参数。C函数总是有两个参数,通常名字是 *self* 和 *args*"
140+ " 。"
131141
132142#: ../../extending/extending.rst:100
133143msgid ""
@@ -146,6 +156,9 @@ msgid ""
146156"determine the required types of the arguments as well as the types of the C "
147157"variables into which to store the converted values. More about this later."
148158msgstr ""
159+ "args "
160+ "参数是一个指向Python的tuple对象的指针,包含参数。每个tuple子项对应一个调用参数。这些参数也全都是Python对象,所以需要先转换成C值。函数"
161+ " :c:func:`PyArg_ParseTuple()` 检查参数类型并转换成C值。它使用模板字符串检测需要的参数类型。细节在后面讲。"
149162
150163#: ../../extending/extending.rst:112
151164msgid ""
@@ -156,10 +169,12 @@ msgid ""
156169"the calling function can return *NULL* immediately (as we saw in the "
157170"example)."
158171msgstr ""
172+ ":c:func:`PyArg_ParseTuple` "
173+ "正常返回非零,并已经按照提供的地址存入了各个变量值。如果出错(零)则应该让函数返回NULL以通知解释器出错(有如例子中看到的)。"
159174
160175#: ../../extending/extending.rst:122
161176msgid "Intermezzo: Errors and Exceptions"
162- msgstr ""
177+ msgstr "关于错误和异常 "
163178
164179#: ../../extending/extending.rst:124
165180msgid ""
@@ -180,7 +195,7 @@ msgstr ""
180195msgid ""
181196"The Python API defines a number of functions to set various types of "
182197"exceptions."
183- msgstr ""
198+ msgstr "Python API中定义了一些函数来设置这些变量。 "
184199
185200#: ../../extending/extending.rst:137
186201msgid ""
@@ -190,6 +205,8 @@ msgid ""
190205"indicates the cause of the error and is converted to a Python string object "
191206"and stored as the \" associated value\" of the exception."
192207msgstr ""
208+ "最常用的就是 :c:func:`PyErr_SetString` 。参数是异常对象和C字符串。异常对象一般由像 "
209+ "PyExc_ZeroDivisionError 这样的对象来预定义。C字符串指明异常原因,并最终存储在异常的第一个参数里面。"
193210
194211#: ../../extending/extending.rst:143
195212msgid ""
@@ -200,6 +217,9 @@ msgid ""
200217"and its associated value. You don't need to :c:func:`Py_INCREF` the objects"
201218" passed to any of these functions."
202219msgstr ""
220+ "另一个有用的函数是 :c:func:`PyErr_SetFromErrno` ,仅接受一个异常对象,异常描述包含在全局变量 "
221+ ":c:data:`errno` 中。最通用的函数还是 :c:func:`PyErr_SetObject` "
222+ ",包含两个参数,分别为异常对象和异常描述。你不需要使用 :c:func:`Py_INCREF` 来增加传递到其他函数的参数对象的引用计数。"
203223
204224#: ../../extending/extending.rst:150
205225msgid ""
@@ -209,6 +229,8 @@ msgid ""
209229":c:func:`PyErr_Occurred` to see whether an error occurred in a function "
210230"call, since you should be able to tell from the return value."
211231msgstr ""
232+ "你可以通过 :c:func:`PyErr_Occurred` 获知当前异常,返回当前异常对象,如果确实没有则为 *NULL* "
233+ "。一般来说,你在调用函数时不需要调用 :c:func:`PyErr_Occurred` 检查是否发生了异常,你可以直接检查返回值。"
212234
213235#: ../../extending/extending.rst:156
214236msgid ""
@@ -223,6 +245,9 @@ msgid ""
223245"executing Python code and tries to find an exception handler specified by "
224246"the Python programmer."
225247msgstr ""
248+ "如果调用更下层函数时出错了,那么本函数返回NULL表示错误,并且整个调用栈中只要有一处调用 :c:func:`PyErr_*` 函数设置异常(通常用 "
249+ "*NULL* 或 ``-1`` "
250+ ")就可以。一般来说,首先发现错误的函数应该设置异常。一旦这个错误到达了Python解释器的主循环,则会中断当前执行代码并追究异常。"
226251
227252#: ../../extending/extending.rst:166
228253msgid ""
@@ -232,6 +257,8 @@ msgid ""
232257" can cause information about the cause of the error to be lost: most "
233258"operations can fail for a variety of reasons.)"
234259msgstr ""
260+ "(有一种情况下,模块可能依靠其他 PyErr_*() "
261+ "函数给出更加详细的错误信息,并且是正确的。但是按照一般规则,这并不重要,很多操作都会因为种种原因而挂掉。)"
235262
236263#: ../../extending/extending.rst:172
237264msgid ""
@@ -242,6 +269,8 @@ msgid ""
242269"itself (possibly by trying something else, or pretending nothing went "
243270"wrong)."
244271msgstr ""
272+ "想要忽略这些函数设置的异常,异常情况必须明确的使用 :c:func:`PyErr_Clear` "
273+ "来清除。只有在C代码想要自己处理异常而不是传给解释器时才这么做。(可能想尝试其他的,或假装出错)。"
245274
246275#: ../../extending/extending.rst:178
247276msgid ""
@@ -260,13 +289,15 @@ msgid ""
260289"positive value or zero for success and ``-1`` for failure, like Unix system "
261290"calls."
262291msgstr ""
292+ "还要注意的是 :c:func:`PyArg_ParseTuple` "
293+ "系列函数的异常,返回一个整数状态码是有效的,0是成功,-1是失败,有如Unix系统调用。"
263294
264295#: ../../extending/extending.rst:188
265296msgid ""
266297"Finally, be careful to clean up garbage (by making :c:func:`Py_XDECREF` or "
267298":c:func:`Py_DECREF` calls for objects you have already created) when you "
268299"return an error indicator!"
269- msgstr ""
300+ msgstr "最后,小心垃圾情理,也就是 :c:func:`Py_XDECREF` 和 :c:func:`Py_DECREF` 的调用,会返回的异常。 "
270301
271302#: ../../extending/extending.rst:192
272303msgid ""
@@ -281,13 +312,18 @@ msgid ""
281312" particular range or must satisfy other conditions, "
282313":c:data:`PyExc_ValueError` is appropriate."
283314msgstr ""
315+ "选择抛出哪个异常完全是你的个人爱好了。有一系列的C对象代表了内置Python异常,例如 "
316+ ":c:data:`PyExc_ZeroDivisionError` ,你可以直接使用。当然,你可能选择更合适的异常,不过别使用 "
317+ ":c:data:`PyExc_TypeError` 告知文件打开失败(有个更合适的 :c:data:`PyExc_IOError` "
318+ ")。如果参数列表有误, :c:func:`PyArg_ParseTuple` 通常会抛出 :c:data:`PyExc_TypeError` "
319+ "。如果参数值域有误, PyExc_ValueError 更合适一些。"
284320
285321#: ../../extending/extending.rst:202
286322msgid ""
287323"You can also define a new exception that is unique to your module. For this,"
288324" you usually declare a static object variable at the beginning of your "
289325"file::"
290- msgstr ""
326+ msgstr "你也可以为你的模块定义一个唯一的新异常。需要在文件前部声明一个静态对象变量,如: "
291327
292328#: ../../extending/extending.rst:207
293329msgid ""
@@ -303,6 +339,9 @@ msgid ""
303339"class being :exc:`Exception` (unless another class is passed in instead of "
304340"*NULL*), described in :ref:`bltin-exceptions`."
305341msgstr ""
342+ "注意实际的Python异常名字是 :exc:`spam.error` 。 :c:func:`PyErr_NewException` 函数使用 "
343+ ":exc:`Exception` 为基类创建一个类(除非是使用另外一个类替代 *NULL* )。描述参考 :ref:`bltin-exceptions`"
344+ " 。"
306345
307346#: ../../extending/extending.rst:230
308347msgid ""
@@ -314,22 +353,24 @@ msgid ""
314353"dangling pointer, C code which raises the exception could cause a core dump "
315354"or other unintended side effects."
316355msgstr ""
356+ "同样注意的是创建类保存了 :c:data:`SpamError` 的一个引用,这是有意的。为了防止被垃圾回收掉,否则 "
357+ ":c:data:`SpamError` 随时会成为野指针。"
317358
318359#: ../../extending/extending.rst:237
319360msgid ""
320361"We discuss the use of ``PyMODINIT_FUNC`` as a function return type later in "
321362"this sample."
322- msgstr ""
363+ msgstr "一会讨论 ``PyMODINIT_FUNC`` 作为函数返回类型的用法。 "
323364
324365#: ../../extending/extending.rst:240
325366msgid ""
326367"The :exc:`spam.error` exception can be raised in your extension module using"
327368" a call to :c:func:`PyErr_SetString` as shown below::"
328- msgstr ""
369+ msgstr ":exc:`spam.error` 异常可以在扩展模块中抛出,通过 :c:func:`PyErr_SetString` 函数调用,如下: "
329370
330371#: ../../extending/extending.rst:263
331372msgid "Back to the Example"
332- msgstr ""
373+ msgstr "回到例子 "
333374
334375#: ../../extending/extending.rst:265
335376msgid ""
0 commit comments