@@ -182,11 +182,11 @@ msgstr "一个简单的示例:"
182182msgid ""
183183"Return a context manager that closes *thing* upon completion of the block. "
184184"This is basically equivalent to::"
185- msgstr "返回一个在语句块执行完成时关闭 *things* 的上下文管理器。这基本上等价于: :: "
185+ msgstr "返回一个在语句块执行完成时关闭 *things* 的上下文管理器。这基本上等价于:"
186186
187187#: ../../library/contextlib.rst:144
188188msgid "And lets you write code like this::"
189- msgstr "并允许你编写这样的代码: :: "
189+ msgstr "并允许你编写这样的代码:"
190190
191191#: ../../library/contextlib.rst:153
192192msgid ""
@@ -203,7 +203,7 @@ msgid ""
203203"optional context manager, for example::"
204204msgstr ""
205205"返回一个从 ``__enter__`` 返回 *enter_result* "
206- "的上下文管理器,除此之外不执行任何操作。它旨在用于可选上下文管理器的一种替代,例如::: "
206+ "的上下文管理器,除此之外不执行任何操作。它旨在用于可选上下文管理器的一种替代,例如:"
207207
208208#: ../../library/contextlib.rst:175
209209msgid "An example using *enter_result*::"
@@ -232,41 +232,43 @@ msgstr "例如::"
232232
233233#: ../../library/contextlib.rst:212
234234msgid "This code is equivalent to::"
235- msgstr ""
235+ msgstr "这段代码等价于: "
236236
237237#: ../../library/contextlib.rst:224 ../../library/contextlib.rst:263
238238#: ../../library/contextlib.rst:273
239239msgid "This context manager is :ref:`reentrant <reentrant-cms>`."
240- msgstr ""
240+ msgstr "该上下文管理器是 :ref:`reentrant <reentrant-cms>` 。 "
241241
242242#: ../../library/contextlib.rst:231
243243msgid ""
244244"Context manager for temporarily redirecting :data:`sys.stdout` to another "
245245"file or file-like object."
246- msgstr ""
246+ msgstr "用于将 :data:`sys.stdout` 临时重定向到一个文件或类文件对象的上下文管理器。 "
247247
248248#: ../../library/contextlib.rst:234
249249msgid ""
250250"This tool adds flexibility to existing functions or classes whose output is "
251251"hardwired to stdout."
252- msgstr ""
252+ msgstr "该工具给已有的将输出硬编码写到 stdout 的函数或类提供了额外的灵活性。 "
253253
254254#: ../../library/contextlib.rst:237
255255msgid ""
256256"For example, the output of :func:`help` normally is sent to *sys.stdout*. "
257257"You can capture that output in a string by redirecting the output to an "
258258":class:`io.StringIO` object::"
259259msgstr ""
260+ "例如, :func:`help` 通常把输出写到 *sys.stdout* 。你可以通过重定向到一个 :class:`io.StringIO` "
261+ "来捕获该输出到一个字符串中。"
260262
261263#: ../../library/contextlib.rst:246
262264msgid ""
263265"To send the output of :func:`help` to a file on disk, redirect the output to"
264266" a regular file::"
265- msgstr ""
267+ msgstr "如果要把 :func:`help` 的输出写到磁盘上的一个文件,重定向该输出到一个常规文件: "
266268
267269#: ../../library/contextlib.rst:253
268270msgid "To send the output of :func:`help` to *sys.stderr*::"
269- msgstr ""
271+ msgstr "如果要把 :func:`help` 的输出写到 *sys.stderr* : "
270272
271273#: ../../library/contextlib.rst:258
272274msgid ""
@@ -275,30 +277,36 @@ msgid ""
275277"applications. It also has no effect on the output of subprocesses. However, "
276278"it is still a useful approach for many utility scripts."
277279msgstr ""
280+ "需要注意的点在于, :data:`sys.stdout` "
281+ "的全局副作用意味着此上下文管理器不适合在库代码和大多数多线程应用程序中使用。它对子进程的输出没有影响。不过对于许多工具脚本而言,它仍然是一个有用的方法。"
278282
279283#: ../../library/contextlib.rst:270
280284msgid ""
281285"Similar to :func:`~contextlib.redirect_stdout` but redirecting "
282286":data:`sys.stderr` to another file or file-like object."
283287msgstr ""
288+ "与 :func:`~contextlib.redirect_stdout` 类似,不过是将 :data:`sys.stderr` "
289+ "重定向到一个文件或类文件对象。"
284290
285291#: ../../library/contextlib.rst:280
286292msgid ""
287293"A base class that enables a context manager to also be used as a decorator."
288- msgstr ""
294+ msgstr "一个使上下文管理器能用作装饰器的基类。 "
289295
290296#: ../../library/contextlib.rst:282
291297msgid ""
292298"Context managers inheriting from ``ContextDecorator`` have to implement "
293299"``__enter__`` and ``__exit__`` as normal. ``__exit__`` retains its optional "
294300"exception handling even when used as a decorator."
295301msgstr ""
302+ "与往常一样,继承自 ``ContextDecorator`` 的上下文管理器必须实现 ``__enter__`` 与 ``__exit__`` "
303+ "。即使用作装饰器, ``__exit__`` 依旧会保持可能的异常处理。"
296304
297305#: ../../library/contextlib.rst:286
298306msgid ""
299307"``ContextDecorator`` is used by :func:`contextmanager`, so you get this "
300308"functionality automatically."
301- msgstr ""
309+ msgstr "``ContextDecorator`` 被用在 :func:`contextmanager` 中,因此你自然获得了这项功能。 "
302310
303311#: ../../library/contextlib.rst:289
304312msgid "Example of ``ContextDecorator``::"
@@ -308,17 +316,17 @@ msgstr "``ContextDecorator`` 的示例::"
308316msgid ""
309317"This change is just syntactic sugar for any construct of the following "
310318"form::"
311- msgstr ""
319+ msgstr "这个改动只是针对如下形式的一个语法糖: "
312320
313321#: ../../library/contextlib.rst:324
314322msgid "``ContextDecorator`` lets you instead write::"
315- msgstr ""
323+ msgstr "``ContextDecorator`` 使得你可以这样改写: "
316324
317325#: ../../library/contextlib.rst:330
318326msgid ""
319327"It makes it clear that the ``cm`` applies to the whole function, rather than"
320328" just a piece of it (and saving an indentation level is nice, too)."
321- msgstr ""
329+ msgstr "这能清楚地表明, ``cm`` 作用于整个函数,而不仅仅是函数的一部分(同时也能保持不错的缩进层级)。 "
322330
323331#: ../../library/contextlib.rst:333
324332msgid ""
0 commit comments