@@ -332,7 +332,7 @@ msgstr "这能清楚地表明, ``cm`` 作用于整个函数,而不仅仅是
332332msgid ""
333333"Existing context managers that already have a base class can be extended by "
334334"using ``ContextDecorator`` as a mixin class::"
335- msgstr ""
335+ msgstr "现有的上下文管理器即使已经有基类,也可以使用 ``ContextDecorator`` 作为混合类进行扩展: "
336336
337337#: ../../library/contextlib.rst:346
338338msgid ""
@@ -341,19 +341,21 @@ msgid ""
341341"statements. If this is not the case, then the original construct with the "
342342"explicit :keyword:`!with` statement inside the function should be used."
343343msgstr ""
344+ "由于被装饰的函数必须能够被多次调用,因此对应的上下文管理器必须支持在多个 :keyword:`with` "
345+ "语句中使用。如果不是这样,则应当使用原来的具有显式 :keyword:`!with` 语句的形式使用该上下文管理器。"
344346
345347#: ../../library/contextlib.rst:356
346348msgid ""
347349"A context manager that is designed to make it easy to programmatically "
348350"combine other context managers and cleanup functions, especially those that "
349351"are optional or otherwise driven by input data."
350- msgstr ""
352+ msgstr "该上下文管理器的设计目标是使得在编码中组合其他上下文管理器和清理函数更加容易,尤其是那些可选的或由输入数据驱动的上下文管理器。 "
351353
352354#: ../../library/contextlib.rst:360
353355msgid ""
354356"For example, a set of files may easily be handled in a single with statement"
355357" as follows::"
356- msgstr ""
358+ msgstr "例如,通过一个如下的 with 语句可以很容易处理一组文件: "
357359
358360#: ../../library/contextlib.rst:369
359361msgid ""
@@ -362,13 +364,15 @@ msgid ""
362364"at the end of a :keyword:`with` statement). Note that callbacks are *not* "
363365"invoked implicitly when the context stack instance is garbage collected."
364366msgstr ""
367+ "每个实例维护一个注册了一组回调的栈,这些回调在实例关闭时以相反的顺序被调用(显式或隐式地在 :keyword:`with` "
368+ "语句的末尾)。请注意,当一个栈实例被垃圾回收时,这些回调将 *不会* 被隐式调用。"
365369
366370#: ../../library/contextlib.rst:374
367371msgid ""
368372"This stack model is used so that context managers that acquire their "
369373"resources in their ``__init__`` method (such as file objects) can be handled"
370374" correctly."
371- msgstr ""
375+ msgstr "通过使用这个基于栈的模型,那些通过 ``__init__`` 方法获取资源的上下文管理器(如文件对象)能够被正确处理。 "
372376
373377#: ../../library/contextlib.rst:378
374378msgid ""
@@ -379,6 +383,8 @@ msgid ""
379383"exception, then outer callbacks will be passed arguments based on that "
380384"updated state."
381385msgstr ""
386+ "由于注册的回调函数是按照与注册相反的顺序调用的,因此最终的行为就像多个嵌套的 :keyword:`with` "
387+ "语句用在这些注册的回调函数上。这个行为甚至扩展到了异常处理:如果内部的回调函数抑制或替换了异常,则外部回调收到的参数是基于该更新后的状态得到的。"
382388
383389#: ../../library/contextlib.rst:385
384390msgid ""
@@ -387,6 +393,8 @@ msgid ""
387393"foundation for higher level context managers that manipulate the exit stack "
388394"in application specific ways."
389395msgstr ""
396+ "这是一个相对底层的 "
397+ "API,它负责正确处理栈里回调退出时依次展开的细节。它为相对高层的上下文管理器提供了一个合适的基础,使得它能根据应用程序的需求使用特定方式操作栈。"
390398
391399#: ../../library/contextlib.rst:394
392400msgid ""
0 commit comments