10
10
# jaystone776 <1732865113@qq.com>, 2021
11
11
# Heyi Tang <tangheyi.09@gmail.com>, 2021
12
12
# Nyuan Zhang, 2022
13
- # Freesand Leo <yuqinju@163.com>, 2024
13
+ # Freesand Leo <yuqinju@163.com>, 2025
14
14
#
15
15
#, fuzzy
16
16
msgid ""
@@ -19,7 +19,7 @@ msgstr ""
19
19
"Report-Msgid-Bugs-To : \n "
20
20
"POT-Creation-Date : 2024-12-27 14:16+0000\n "
21
21
"PO-Revision-Date : 2021-06-28 00:57+0000\n "
22
- "Last-Translator : Freesand Leo <yuqinju@163.com>, 2024 \n "
22
+ "Last-Translator : Freesand Leo <yuqinju@163.com>, 2025 \n "
23
23
"Language-Team : Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n "
24
24
"MIME-Version : 1.0\n "
25
25
"Content-Type : text/plain; charset=UTF-8\n "
@@ -453,6 +453,15 @@ msgid ""
453
453
" with cm:\n"
454
454
" # Do something"
455
455
msgstr ""
456
+ "def myfunction(arg, ignore_exceptions=False):\n"
457
+ " if ignore_exceptions:\n"
458
+ " # 使用 suppress 来忽略所有异常。\n"
459
+ " cm = contextlib.suppress(Exception)\n"
460
+ " else:\n"
461
+ " # 不忽略任何异常,cm 将没有影响。\n"
462
+ " cm = contextlib.nullcontext()\n"
463
+ " with cm:\n"
464
+ " # 执行某些操作"
456
465
457
466
#: ../../library/contextlib.rst:245
458
467
msgid "An example using *enter_result*::"
@@ -471,6 +480,16 @@ msgid ""
471
480
" with cm as file:\n"
472
481
" # Perform processing on the file"
473
482
msgstr ""
483
+ "def process_file(file_or_path):\n"
484
+ " if isinstance(file_or_path, str):\n"
485
+ " # If string, open file\n"
486
+ " cm = open(file_or_path)\n"
487
+ " else:\n"
488
+ " # 调用方要负责关闭文件\n"
489
+ " cm = nullcontext(file_or_path)\n"
490
+ "\n"
491
+ " with cm as file:\n"
492
+ " # 在文件上执行处理"
474
493
475
494
#: ../../library/contextlib.rst:258
476
495
msgid ""
@@ -492,6 +511,16 @@ msgid ""
492
511
" async with cm as session:\n"
493
512
" # Send http requests with session"
494
513
msgstr ""
514
+ "async def send_http(session=None):\n"
515
+ " if not session:\n"
516
+ " # 如果没有 http 会话,则使用 aiohttp 创建它\n"
517
+ " cm = aiohttp.ClientSession()\n"
518
+ " else:\n"
519
+ " # 调用方要负责关闭会话\n"
520
+ " cm = nullcontext(session)\n"
521
+ "\n"
522
+ " async with cm as session:\n"
523
+ " # 使用会话发送 http 请求"
495
524
496
525
#: ../../library/contextlib.rst:274
497
526
msgid ":term:`asynchronous context manager` support was added."
@@ -529,6 +558,13 @@ msgid ""
529
558
"with suppress(FileNotFoundError):\n"
530
559
" os.remove('someotherfile.tmp')"
531
560
msgstr ""
561
+ "from contextlib import suppress\n"
562
+ "\n"
563
+ "with suppress(FileNotFoundError):\n"
564
+ " os.remove('somefile.tmp')\n"
565
+ "\n"
566
+ "with suppress(FileNotFoundError):\n"
567
+ " os.remove('someotherfile.tmp')"
532
568
533
569
#: ../../library/contextlib.rst:301
534
570
msgid "This code is equivalent to::"
@@ -546,6 +582,15 @@ msgid ""
546
582
"except FileNotFoundError:\n"
547
583
" pass"
548
584
msgstr ""
585
+ "try:\n"
586
+ " os.remove('somefile.tmp')\n"
587
+ "except FileNotFoundError:\n"
588
+ " pass\n"
589
+ "\n"
590
+ "try:\n"
591
+ " os.remove('someotherfile.tmp')\n"
592
+ "except FileNotFoundError:\n"
593
+ " pass"
549
594
550
595
#: ../../library/contextlib.rst:313 ../../library/contextlib.rst:362
551
596
#: ../../library/contextlib.rst:372 ../../library/contextlib.rst:389
@@ -599,6 +644,9 @@ msgid ""
599
644
" help(pow)\n"
600
645
"s = f.getvalue()"
601
646
msgstr ""
647
+ "with redirect_stdout(io.StringIO()) as f:\n"
648
+ " help(pow)\n"
649
+ "s = f.getvalue()"
602
650
603
651
#: ../../library/contextlib.rst:345
604
652
msgid ""
@@ -702,6 +750,16 @@ msgid ""
702
750
" print('Finishing')\n"
703
751
" return False"
704
752
msgstr ""
753
+ "from contextlib import ContextDecorator\n"
754
+ "\n"
755
+ "class mycontext(ContextDecorator):\n"
756
+ " def __enter__(self):\n"
757
+ " print('Starting')\n"
758
+ " return self\n"
759
+ "\n"
760
+ " def __exit__(self, *exc):\n"
761
+ " print('Finishing')\n"
762
+ " return False"
705
763
706
764
#: ../../library/contextlib.rst:418 ../../library/contextlib.rst:490
707
765
msgid "The class can then be used like this::"
@@ -725,6 +783,21 @@ msgid ""
725
783
"The bit in the middle\n"
726
784
"Finishing"
727
785
msgstr ""
786
+ ">>> @mycontext()\n"
787
+ "... def function():\n"
788
+ "... print('The bit in the middle')\n"
789
+ "...\n"
790
+ ">>> function()\n"
791
+ "Starting\n"
792
+ "The bit in the middle\n"
793
+ "Finishing\n"
794
+ "\n"
795
+ ">>> with mycontext():\n"
796
+ "... print('The bit in the middle')\n"
797
+ "...\n"
798
+ "Starting\n"
799
+ "The bit in the middle\n"
800
+ "Finishing"
728
801
729
802
#: ../../library/contextlib.rst:436
730
803
msgid ""
@@ -738,6 +811,9 @@ msgid ""
738
811
" with cm():\n"
739
812
" # Do stuff"
740
813
msgstr ""
814
+ "def f():\n"
815
+ " with cm():\n"
816
+ " # 执行操作"
741
817
742
818
#: ../../library/contextlib.rst:442
743
819
msgid "``ContextDecorator`` lets you instead write::"
@@ -749,6 +825,9 @@ msgid ""
749
825
"def f():\n"
750
826
" # Do stuff"
751
827
msgstr ""
828
+ "@cm()\n"
829
+ "def f():\n"
830
+ " # 执行操作"
752
831
753
832
#: ../../library/contextlib.rst:448
754
833
msgid ""
0 commit comments