-
-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathcontextlib.po
More file actions
1975 lines (1802 loc) · 78.1 KB
/
contextlib.po
File metadata and controls
1975 lines (1802 loc) · 78.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001-2017, Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2017.
#
msgid ""
msgstr ""
"Project-Id-Version: Python 3.6\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-04-17 23:44+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Dong-gweon Oh <flowdas@gmail.com>\n"
"Language-Team: Korean (https://python.flowdas.com)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.17.0\n"
#: ../../library/contextlib.rst:2
msgid ""
":mod:`!contextlib` --- Utilities for :keyword:`!with`\\ -statement "
"contexts"
msgstr ":mod:`!contextlib` --- :keyword:`!with` 문 컨텍스트를 위한 유틸리티"
#: ../../library/contextlib.rst:7
msgid "**Source code:** :source:`Lib/contextlib.py`"
msgstr "**소스 코드:** :source:`Lib/contextlib.py`"
#: ../../library/contextlib.rst:11
msgid ""
"This module provides utilities for common tasks involving the "
":keyword:`with` statement. For more information see also "
":ref:`typecontextmanager` and :ref:`context-managers`."
msgstr ""
"이 모듈은 :keyword:`with` 문이 수반되는 일반적인 작업을 위한 유틸리티를 제공합니다. 자세한 정보는 "
":ref:`typecontextmanager` 과 :ref:`context-managers`\\도 참조하십시오."
#: ../../library/contextlib.rst:17
msgid "Utilities"
msgstr "유틸리티"
#: ../../library/contextlib.rst:19
msgid "Functions and classes provided:"
msgstr "제공되는 함수와 클래스:"
#: ../../library/contextlib.rst:23
msgid ""
"An :term:`abstract base class` for classes that implement "
":meth:`object.__enter__` and :meth:`object.__exit__`. A default "
"implementation for :meth:`object.__enter__` is provided which returns "
"``self`` while :meth:`object.__exit__` is an abstract method which by "
"default returns ``None``. See also the definition of "
":ref:`typecontextmanager`."
msgstr ""
":meth:`object.__enter__`\\와 :meth:`object.__exit__`\\를 구현하는 클래스의 "
":term:`추상 베이스 클래스 <abstract base class>`. ``self``\\를 반환하는 "
":meth:`object.__enter__`\\의 기본 구현이 제공되지만 :meth:`object.__exit__`\\는 기본적으로"
" ``None``\\을 반환하는 추상 메서드입니다. :ref:`typecontextmanager` 의 정의도 참조하십시오."
#: ../../library/contextlib.rst:34
msgid ""
"An :term:`abstract base class` for classes that implement "
":meth:`object.__aenter__` and :meth:`object.__aexit__`. A default "
"implementation for :meth:`object.__aenter__` is provided which returns "
"``self`` while :meth:`object.__aexit__` is an abstract method which by "
"default returns ``None``. See also the definition of :ref:`async-context-"
"managers`."
msgstr ""
":meth:`object.__aenter__`\\와 :meth:`object.__aexit__`\\를 구현하는 클래스의 "
":term:`추상 베이스 클래스 <abstract base class>`. ``self``\\를 반환하는 "
":meth:`object.__aenter__`\\의 기본 구현이 제공되지만 :meth:`object.__aexit__`\\는 "
"기본적으로 ``None``\\을 반환하는 추상 메서드입니다. :ref:`async-context-managers`\\의 정의도 "
"참조하십시오."
#: ../../library/contextlib.rst:46
msgid ""
"This function is a :term:`decorator` that can be used to define a factory"
" function for :keyword:`with` statement context managers, without needing"
" to create a class or separate :meth:`~object.__enter__` and "
":meth:`~object.__exit__` methods."
msgstr ""
"이 함수는 클래스나 별도의 :meth:`~object.__enter__`\\와 :meth:`~object.__exit__` 메서드를"
" 작성할 필요 없이, :keyword:`with` 문 컨텍스트 관리자를 위한 팩토리 함수를 정의하는 데 사용할 수 있는 "
":term:`데코레이터 <decorator>`\\입니다."
#: ../../library/contextlib.rst:50
msgid ""
"While many objects natively support use in with statements, sometimes a "
"resource needs to be managed that isn't a context manager in its own "
"right, and doesn't implement a ``close()`` method for use with "
"``contextlib.closing``."
msgstr ""
"많은 객체가 자체적으로 with 문에서의 사용을 지원하지만, 스스로는 컨텍스트 관리자가 아니고 "
"``contextlib.closing``\\과 함께 사용할 ``close()`` 메서드를 구현하지 않는 자원을 관리해야 하는 경우가"
" 있습니다."
#: ../../library/contextlib.rst:54
msgid ""
"An abstract example would be the following to ensure correct resource "
"management::"
msgstr "올바른 자원 관리를 보장하기 위한 추상적인 예는 다음과 같습니다::"
#: ../../library/contextlib.rst:57
msgid ""
"from contextlib import contextmanager\n"
"\n"
"@contextmanager\n"
"def managed_resource(*args, **kwds):\n"
" # Code to acquire resource, e.g.:\n"
" resource = acquire_resource(*args, **kwds)\n"
" try:\n"
" yield resource\n"
" finally:\n"
" # Code to release resource, e.g.:\n"
" release_resource(resource)"
msgstr ""
"from contextlib import contextmanager\n"
"\n"
"@contextmanager\n"
"def managed_resource(*args, **kwds):\n"
" # 자원을 얻는 코드, 예를 들어:\n"
" resource = acquire_resource(*args, **kwds)\n"
" try:\n"
" yield resource\n"
" finally:\n"
" # 자원을 해제하는 코드, 예를 들어:\n"
" release_resource(resource)"
#: ../../library/contextlib.rst:69
msgid "The function can then be used like this::"
msgstr ""
#: ../../library/contextlib.rst:71
msgid ""
">>> with managed_resource(timeout=3600) as resource:\n"
"... # Resource is released at the end of this block,\n"
"... # even if code in the block raises an exception"
msgstr ""
">>> with managed_resource(timeout=3600) as resource:\n"
"... # 블록의 코드에서 예외가 발생하더라도,\n"
"... # 이 블록의 끝에서 자원이 해제됩니다"
#: ../../library/contextlib.rst:75
msgid ""
"The function being decorated must return a :term:`generator`-iterator "
"when called. This iterator must yield exactly one value, which will be "
"bound to the targets in the :keyword:`with` statement's :keyword:`!as` "
"clause, if any."
msgstr ""
"데코레이트 되는 함수는 호출될 때 :term:`제너레이터 <generator>` 이터레이터를 반환해야 합니다. 이 이터레이터는 "
"정확히 하나의 값을 산출해야 하며, 이는 :keyword:`with` 문의 :keyword:`!as` 절에 있는 대상에 연결됩니다 "
"(있다면)."
#: ../../library/contextlib.rst:79
msgid ""
"At the point where the generator yields, the block nested in the "
":keyword:`with` statement is executed. The generator is then resumed "
"after the block is exited. If an unhandled exception occurs in the block,"
" it is reraised inside the generator at the point where the yield "
"occurred. Thus, you can use a :keyword:`try`...\\ :keyword:`except`...\\"
" :keyword:`finally` statement to trap the error (if any), or ensure that "
"some cleanup takes place. If an exception is trapped merely in order to "
"log it or to perform some action (rather than to suppress it entirely), "
"the generator must reraise that exception. Otherwise the generator "
"context manager will indicate to the :keyword:`!with` statement that the "
"exception has been handled, and execution will resume with the statement "
"immediately following the :keyword:`!with` statement."
msgstr ""
"제너레이터가 산출하는 지점에서, :keyword:`with` 문에 중첩된 블록이 실행됩니다. 그런 다음 블록이 종료된 후 "
"제너레이터가 재개합니다. 블록에서 처리되지 않은 예외가 발생하면, 제너레이터 내부의 yield가 등장한 지점에서 다시 발생합니다. "
"따라서, :keyword:`try`...\\ :keyword:`except`...\\ :keyword:`finally` 문을 "
"사용하여 에러(있다면)를 잡거나, 어떤 정리가 수행되도록 할 수 있습니다. 예외를 단지 로그 하기 위해 또는 (예외를 완전히 "
"억제하는 대신) 어떤 작업을 수행하기 위해 예외를 잡았다면 제너레이터는 해당 예외를 다시 발생시켜야 합니다. 그렇지 않으면 "
"제너레이터 컨텍스트 관리자가 :keyword:`!with` 문에 예외가 처리되었음을 표시하고, :keyword:`!with` 문 "
"바로 다음에 오는 문장으로 실행이 재개됩니다."
#: ../../library/contextlib.rst:91
msgid ""
":func:`contextmanager` uses :class:`ContextDecorator` so the context "
"managers it creates can be used as decorators as well as in "
":keyword:`with` statements. When used as a decorator, a new generator "
"instance is implicitly created on each function call (this allows the "
"otherwise \"one-shot\" context managers created by :func:`contextmanager`"
" to meet the requirement that context managers support multiple "
"invocations in order to be used as decorators)."
msgstr ""
":func:`contextmanager`\\는 :class:`ContextDecorator`\\를 사용해서, 만들어진 컨텍스트 "
"관리자를 :keyword:`with` 문뿐만 아니라 데코레이터로 사용할 수 있습니다. 데코레이터로 사용될 때, 새로운 제너레이터 "
"인스턴스는 각 함수 호출마다 묵시적으로 만들어집니다 (이는 그렇지 않을 경우 :func:`contextmanager`\\에 의해 "
"만들어진 \"일회성\" 컨텍스트 관리자가 데코레이터로 사용하기 위해 컨텍스트 관리자가 여러 번의 호출을 지원해야 한다는 요구 사항을"
" 충족시킬 수 있도록 합니다) ."
#: ../../library/contextlib.rst:98
msgid "Use of :class:`ContextDecorator`."
msgstr ":class:`ContextDecorator` 사용."
#: ../../library/contextlib.rst:104
msgid ""
"Similar to :func:`~contextlib.contextmanager`, but creates an "
":ref:`asynchronous context manager <async-context-managers>`."
msgstr ""
":func:`~contextlib.contextmanager`\\와 유사하지만, :ref:`비동기 컨텍스트 관리자 <async-"
"context-managers>`\\를 만듭니다."
#: ../../library/contextlib.rst:107
msgid ""
"This function is a :term:`decorator` that can be used to define a factory"
" function for :keyword:`async with` statement asynchronous context "
"managers, without needing to create a class or separate "
":meth:`~object.__aenter__` and :meth:`~object.__aexit__` methods. It must"
" be applied to an :term:`asynchronous generator` function."
msgstr ""
"이 함수는 클래스나 별도의 :meth:`~object.__aenter__`\\와 :meth:`~object.__aexit__` "
"메서드를 작성할 필요 없이, :keyword:`async with` 문 비동기 컨텍스트 관리자를 위한 팩토리 함수를 정의하는 데 "
"사용할 수 있는 :term:`데코레이터 <decorator>`\\입니다. :term:`비동기 제너레이터 <asynchronous "
"generator>` 함수에 적용해야 합니다."
#: ../../library/contextlib.rst:113
msgid "A simple example::"
msgstr "간단한 예::"
#: ../../library/contextlib.rst:115
msgid ""
"from contextlib import asynccontextmanager\n"
"\n"
"@asynccontextmanager\n"
"async def get_connection():\n"
" conn = await acquire_db_connection()\n"
" try:\n"
" yield conn\n"
" finally:\n"
" await release_db_connection(conn)\n"
"\n"
"async def get_all_users():\n"
" async with get_connection() as conn:\n"
" return conn.query('SELECT ...')"
msgstr ""
"from contextlib import asynccontextmanager\n"
"\n"
"@asynccontextmanager\n"
"async def get_connection():\n"
" conn = await acquire_db_connection()\n"
" try:\n"
" yield conn\n"
" finally:\n"
" await release_db_connection(conn)\n"
"\n"
"async def get_all_users():\n"
" async with get_connection() as conn:\n"
" return conn.query('SELECT ...')"
#: ../../library/contextlib.rst:131
msgid ""
"Context managers defined with :func:`asynccontextmanager` can be used "
"either as decorators or with :keyword:`async with` statements::"
msgstr ""
#: ../../library/contextlib.rst:134
#, python-brace-format
msgid ""
"import time\n"
"from contextlib import asynccontextmanager\n"
"\n"
"@asynccontextmanager\n"
"async def timeit():\n"
" now = time.monotonic()\n"
" try:\n"
" yield\n"
" finally:\n"
" print(f'it took {time.monotonic() - now}s to run')\n"
"\n"
"@timeit()\n"
"async def main():\n"
" # ... async code ..."
msgstr ""
"import time\n"
"from contextlib import asynccontextmanager\n"
"\n"
"@asynccontextmanager\n"
"async def timeit():\n"
" now = time.monotonic()\n"
" try:\n"
" yield\n"
" finally:\n"
" print(f'it took {time.monotonic() - now}s to run')\n"
"\n"
"@timeit()\n"
"async def main():\n"
" # ... 비동기 코드 ..."
#: ../../library/contextlib.rst:149
msgid ""
"When used as a decorator, a new generator instance is implicitly created "
"on each function call. This allows the otherwise \"one-shot\" context "
"managers created by :func:`asynccontextmanager` to meet the requirement "
"that context managers support multiple invocations in order to be used as"
" decorators."
msgstr ""
"데코레이터로 사용될 때, 새로운 제너레이터 인스턴스는 각 함수 호출마다 묵시적으로 만들어집니다. 이는 그렇지 않을 경우 "
":func:`contextmanager`\\에 의해 만들어진 \"일회성\" 컨텍스트 관리자가 데코레이터로 사용하기 위해 컨텍스트 "
"관리자가 여러 번의 호출을 지원해야 한다는 요구 사항을 충족시킬 수 있도록 합니다."
#: ../../library/contextlib.rst:154
msgid ""
"Async context managers created with :func:`asynccontextmanager` can be "
"used as decorators."
msgstr ""
#: ../../library/contextlib.rst:161
msgid ""
"Return a context manager that closes *thing* upon completion of the "
"block. This is basically equivalent to::"
msgstr "블록이 완료될 때 *thing*\\을 닫는 컨텍스트 관리자를 반환합니다. 이것은 기본적으로 다음과 동등합니다::"
#: ../../library/contextlib.rst:164
msgid ""
"from contextlib import contextmanager\n"
"\n"
"@contextmanager\n"
"def closing(thing):\n"
" try:\n"
" yield thing\n"
" finally:\n"
" thing.close()"
msgstr ""
"from contextlib import contextmanager\n"
"\n"
"@contextmanager\n"
"def closing(thing):\n"
" try:\n"
" yield thing\n"
" finally:\n"
" thing.close()"
#: ../../library/contextlib.rst:173
msgid "And lets you write code like this::"
msgstr "그리고 다음과 같은 코드를 작성할 수 있도록 합니다::"
#: ../../library/contextlib.rst:175
msgid ""
"from contextlib import closing\n"
"from urllib.request import urlopen\n"
"\n"
"with closing(urlopen('https://www.python.org')) as page:\n"
" for line in page:\n"
" print(line)"
msgstr ""
"from contextlib import closing\n"
"from urllib.request import urlopen\n"
"\n"
"with closing(urlopen('https://www.python.org')) as page:\n"
" for line in page:\n"
" print(line)"
#: ../../library/contextlib.rst:182
msgid ""
"without needing to explicitly close ``page``. Even if an error occurs, "
"``page.close()`` will be called when the :keyword:`with` block is exited."
msgstr ""
"``page``\\를 명시적으로 닫을 필요가 없습니다. 에러가 발생하더라도, :keyword:`with` 블록이 종료될 때 "
"``page.close()``\\가 호출됩니다."
#: ../../library/contextlib.rst:187
msgid ""
"Most types managing resources support the :term:`context manager` "
"protocol, which closes *thing* on leaving the :keyword:`with` statement. "
"As such, :func:`!closing` is most useful for third party types that don't"
" support context managers. This example is purely for illustration "
"purposes, as :func:`~urllib.request.urlopen` would normally be used in a "
"context manager."
msgstr ""
#: ../../library/contextlib.rst:196
msgid ""
"Return an async context manager that calls the ``aclose()`` method of "
"*thing* upon completion of the block. This is basically equivalent to::"
msgstr ""
"블록이 완료될 때 *thing*\\의 ``aclose()`` 메서드를 호출하는 비동기 컨텍스트 관리자를 반환합니다. 이것은 "
"기본적으로 다음과 동등합니다::"
#: ../../library/contextlib.rst:199
msgid ""
"from contextlib import asynccontextmanager\n"
"\n"
"@asynccontextmanager\n"
"async def aclosing(thing):\n"
" try:\n"
" yield thing\n"
" finally:\n"
" await thing.aclose()"
msgstr ""
"from contextlib import asynccontextmanager\n"
"\n"
"@asynccontextmanager\n"
"async def aclosing(thing):\n"
" try:\n"
" yield thing\n"
" finally:\n"
" await thing.aclose()"
#: ../../library/contextlib.rst:208
msgid ""
"Significantly, ``aclosing()`` supports deterministic cleanup of async "
"generators when they happen to exit early by :keyword:`break` or an "
"exception. For example::"
msgstr ""
#: ../../library/contextlib.rst:212
msgid ""
"from contextlib import aclosing\n"
"\n"
"async with aclosing(my_generator()) as values:\n"
" async for value in values:\n"
" if value == 42:\n"
" break"
msgstr ""
"from contextlib import aclosing\n"
"\n"
"async with aclosing(my_generator()) as values:\n"
" async for value in values:\n"
" if value == 42:\n"
" break"
#: ../../library/contextlib.rst:219
msgid ""
"This pattern ensures that the generator's async exit code is executed in "
"the same context as its iterations (so that exceptions and context "
"variables work as expected, and the exit code isn't run after the "
"lifetime of some task it depends on)."
msgstr ""
#: ../../library/contextlib.rst:231
msgid ""
"Return a context manager that returns *enter_result* from ``__enter__``, "
"but otherwise does nothing. It is intended to be used as a stand-in for "
"an optional context manager, for example::"
msgstr ""
"``__enter__``\\에서 *enter_result*\\를 반환하지만, 그 외에는 아무것도 하지 않는 컨텍스트 관리자를 "
"반환합니다. 선택적 컨텍스트 관리자를 위한 대체로 사용하기 위한 것입니다, 예를 들어::"
#: ../../library/contextlib.rst:235
msgid ""
"def myfunction(arg, ignore_exceptions=False):\n"
" if ignore_exceptions:\n"
" # Use suppress to ignore all exceptions.\n"
" cm = contextlib.suppress(Exception)\n"
" else:\n"
" # Do not ignore any exceptions, cm has no effect.\n"
" cm = contextlib.nullcontext()\n"
" with cm:\n"
" # Do something"
msgstr ""
"def myfunction(arg, ignore_exceptions=False):\n"
" if ignore_exceptions:\n"
" # 모든 예외를 무시하기 위해 suppress를 사용합니다.\n"
" cm = contextlib.suppress(Exception)\n"
" else:\n"
" # 아무런 예외도 무시하지 않습니다, cm은 아무 효과도 없습니다.\n"
" cm = contextlib.nullcontext()\n"
" with cm:\n"
" # 뭔가 합니다"
#: ../../library/contextlib.rst:245
msgid "An example using *enter_result*::"
msgstr "*enter_result*\\를 사용하는 예::"
#: ../../library/contextlib.rst:247
msgid ""
"def process_file(file_or_path):\n"
" if isinstance(file_or_path, str):\n"
" # If string, open file\n"
" cm = open(file_or_path)\n"
" else:\n"
" # Caller is responsible for closing file\n"
" cm = nullcontext(file_or_path)\n"
"\n"
" with cm as file:\n"
" # Perform processing on the file"
msgstr ""
"def process_file(file_or_path):\n"
" if isinstance(file_or_path, str):\n"
" # 문자열이면, 파일을 엽니다\n"
" cm = open(file_or_path)\n"
" else:\n"
" # 파일을 닫는 책임은 호출자에게 있습니다\n"
" cm = nullcontext(file_or_path)\n"
"\n"
" with cm as file:\n"
" # 파일에 대한 처리를 수행합니다"
#: ../../library/contextlib.rst:258
msgid ""
"It can also be used as a stand-in for :ref:`asynchronous context managers"
" <async-context-managers>`::"
msgstr "또한 :ref:`비동기 컨텍스트 관리자 <async-context-managers>`\\의 대체로 사용할 수 있습니다::"
#: ../../library/contextlib.rst:261
msgid ""
"async def send_http(session=None):\n"
" if not session:\n"
" # If no http session, create it with aiohttp\n"
" cm = aiohttp.ClientSession()\n"
" else:\n"
" # Caller is responsible for closing the session\n"
" cm = nullcontext(session)\n"
"\n"
" async with cm as session:\n"
" # Send http requests with session"
msgstr ""
"async def send_http(session=None):\n"
" if not session:\n"
" # http 세션이 없으면, aiohttp 로 만듭니다\n"
" cm = aiohttp.ClientSession()\n"
" else:\n"
" # 세션을 닫는 책임은 호출자에게 있습니다\n"
" cm = nullcontext(session)\n"
"\n"
" async with cm as session:\n"
" # 세션으로 http 요청을 보냅니다"
#: ../../library/contextlib.rst:274
msgid ":term:`asynchronous context manager` support was added."
msgstr ""
#: ../../library/contextlib.rst:281
msgid ""
"Return a context manager that suppresses any of the specified exceptions "
"if they occur in the body of a :keyword:`!with` statement and then "
"resumes execution with the first statement following the end of the "
":keyword:`!with` statement."
msgstr ""
":keyword:`!with` 문의 본문에서 발생하는 지정된 예외를 모두 억제한 후 :keyword:`!with` 문의 끝 다음에 "
"오는 첫 번째 문장에서 실행을 재개하는 컨텍스트 관리자를 반환합니다."
#: ../../library/contextlib.rst:286
msgid ""
"As with any other mechanism that completely suppresses exceptions, this "
"context manager should be used only to cover very specific errors where "
"silently continuing with program execution is known to be the right thing"
" to do."
msgstr ""
"예외를 완전히 억제하는 다른 메커니즘과 마찬가지로, 이 컨텍스트 관리자는 프로그램 실행을 조용히 계속하는 것이 옳은 것으로 알려진 "
"매우 특정한 에러를 다루기 위해서만 사용해야 합니다."
#: ../../library/contextlib.rst:291
msgid "For example::"
msgstr "예를 들면::"
#: ../../library/contextlib.rst:293
msgid ""
"from contextlib import suppress\n"
"\n"
"with suppress(FileNotFoundError):\n"
" os.remove('somefile.tmp')\n"
"\n"
"with suppress(FileNotFoundError):\n"
" os.remove('someotherfile.tmp')"
msgstr ""
"from contextlib import suppress\n"
"\n"
"with suppress(FileNotFoundError):\n"
" os.remove('somefile.tmp')\n"
"\n"
"with suppress(FileNotFoundError):\n"
" os.remove('someotherfile.tmp')"
#: ../../library/contextlib.rst:301
msgid "This code is equivalent to::"
msgstr "이 코드는 다음과 동등합니다::"
#: ../../library/contextlib.rst:303
msgid ""
"try:\n"
" os.remove('somefile.tmp')\n"
"except FileNotFoundError:\n"
" pass\n"
"\n"
"try:\n"
" os.remove('someotherfile.tmp')\n"
"except FileNotFoundError:\n"
" pass"
msgstr ""
"try:\n"
" os.remove('somefile.tmp')\n"
"except FileNotFoundError:\n"
" pass\n"
"\n"
"try:\n"
" os.remove('someotherfile.tmp')\n"
"except FileNotFoundError:\n"
" pass"
#: ../../library/contextlib.rst:313 ../../library/contextlib.rst:362
#: ../../library/contextlib.rst:372 ../../library/contextlib.rst:389
msgid "This context manager is :ref:`reentrant <reentrant-cms>`."
msgstr "이 컨텍스트 관리자는 :ref:`재진입 가능 <reentrant-cms>`\\합니다."
#: ../../library/contextlib.rst:315
msgid ""
"If the code within the :keyword:`!with` block raises a "
":exc:`BaseExceptionGroup`, suppressed exceptions are removed from the "
"group. Any exceptions of the group which are not suppressed are re-"
"raised in a new group which is created using the original group's "
":meth:`~BaseExceptionGroup.derive` method."
msgstr ""
#: ../../library/contextlib.rst:323
msgid ""
"``suppress`` now supports suppressing exceptions raised as part of a "
":exc:`BaseExceptionGroup`."
msgstr ""
#: ../../library/contextlib.rst:329
msgid ""
"Context manager for temporarily redirecting :data:`sys.stdout` to another"
" file or file-like object."
msgstr ":data:`sys.stdout`\\을 다른 파일이나 파일류 객체로 일시적으로 리디렉션 하기 위한 컨텍스트 관리자."
#: ../../library/contextlib.rst:332
msgid ""
"This tool adds flexibility to existing functions or classes whose output "
"is hardwired to stdout."
msgstr "이 도구는 출력이 stdout에 배선된 기존 함수나 클래스에 유연성을 추가합니다."
#: ../../library/contextlib.rst:335
msgid ""
"For example, the output of :func:`help` normally is sent to *sys.stdout*."
" You can capture that output in a string by redirecting the output to an "
":class:`io.StringIO` object. The replacement stream is returned from the "
"``__enter__`` method and so is available as the target of the "
":keyword:`with` statement::"
msgstr ""
"예를 들어, :func:`help`\\의 출력은 일반적으로 *sys.stdout*\\으로 전송됩니다. 출력을 "
":class:`io.StringIO` 객체로 리디렉션 하여 해당 출력을 문자열로 캡처 할 수 있습니다. 대체 스트림이 "
"``__enter__`` 메서드에서 반환되어 :keyword:`with` 문의 대상으로 사용할 수 있습니다::"
#: ../../library/contextlib.rst:341
msgid ""
"with redirect_stdout(io.StringIO()) as f:\n"
" help(pow)\n"
"s = f.getvalue()"
msgstr ""
"with redirect_stdout(io.StringIO()) as f:\n"
" help(pow)\n"
"s = f.getvalue()"
#: ../../library/contextlib.rst:345
msgid ""
"To send the output of :func:`help` to a file on disk, redirect the output"
" to a regular file::"
msgstr ":func:`help`\\의 출력을 디스크의 파일로 보내려면, 출력을 일반 파일로 리디렉션 하십시오::"
#: ../../library/contextlib.rst:348
msgid ""
"with open('help.txt', 'w') as f:\n"
" with redirect_stdout(f):\n"
" help(pow)"
msgstr ""
"with open('help.txt', 'w') as f:\n"
" with redirect_stdout(f):\n"
" help(pow)"
#: ../../library/contextlib.rst:352
msgid "To send the output of :func:`help` to *sys.stderr*::"
msgstr ":func:`help`\\의 출력을 *sys.stderr*\\로 보내려면::"
#: ../../library/contextlib.rst:354
msgid ""
"with redirect_stdout(sys.stderr):\n"
" help(pow)"
msgstr ""
"with redirect_stdout(sys.stderr):\n"
" help(pow)"
#: ../../library/contextlib.rst:357
msgid ""
"Note that the global side effect on :data:`sys.stdout` means that this "
"context manager is not suitable for use in library code and most threaded"
" applications. It also has no effect on the output of subprocesses. "
"However, it is still a useful approach for many utility scripts."
msgstr ""
":data:`sys.stdout`\\에 대한 전역 부작용은 이 컨텍스트 관리자가 라이브러리 코드와 대부분의 스레드 응용 프로그램에 "
"사용하기에 적합하지 않음을 의미합니다. 또한 서브 프로세스의 출력에는 영향을 미치지 않습니다. 그러나, 여전히 많은 유틸리티 "
"스크립트에 유용한 접근법입니다."
#: ../../library/contextlib.rst:369
msgid ""
"Similar to :func:`~contextlib.redirect_stdout` but redirecting "
":data:`sys.stderr` to another file or file-like object."
msgstr ""
":func:`~contextlib.redirect_stdout`\\과 유사하지만, :data:`sys.stderr`\\를 다른 "
"파일이나 파일류 객체로 리디렉션 합니다."
#: ../../library/contextlib.rst:379
msgid ""
"Non parallel-safe context manager to change the current working "
"directory. As this changes a global state, the working directory, it is "
"not suitable for use in most threaded or async contexts. It is also not "
"suitable for most non-linear code execution, like generators, where the "
"program execution is temporarily relinquished -- unless explicitly "
"desired, you should not yield when this context manager is active."
msgstr ""
#: ../../library/contextlib.rst:386
msgid ""
"This is a simple wrapper around :func:`~os.chdir`, it changes the current"
" working directory upon entering and restores the old one on exit."
msgstr ""
#: ../../library/contextlib.rst:396
msgid ""
"A base class that enables a context manager to also be used as a "
"decorator."
msgstr "컨텍스트 관리자를 데코레이터로도 사용할 수 있도록 하는 베이스 클래스."
#: ../../library/contextlib.rst:398
msgid ""
"Context managers inheriting from ``ContextDecorator`` have to implement "
"``__enter__`` and ``__exit__`` as normal. ``__exit__`` retains its "
"optional exception handling even when used as a decorator."
msgstr ""
"``ContextDecorator``\\를 상속하는 컨텍스트 관리자는 일반적인 방식으로 ``__enter__``\\와 "
"``__exit__``\\를 구현해야 합니다. ``__exit__``\\는 데코레이터로 사용될 때도 선택적 예외 처리를 유지합니다."
#: ../../library/contextlib.rst:402
msgid ""
"``ContextDecorator`` is used by :func:`contextmanager`, so you get this "
"functionality automatically."
msgstr ""
"``ContextDecorator``\\는 :func:`contextmanager`\\에서 사용되므로, 이 기능을 자동으로 얻게 "
"됩니다."
#: ../../library/contextlib.rst:405
msgid "Example of ``ContextDecorator``::"
msgstr "``ContextDecorator``\\의 예::"
#: ../../library/contextlib.rst:407
msgid ""
"from contextlib import ContextDecorator\n"
"\n"
"class mycontext(ContextDecorator):\n"
" def __enter__(self):\n"
" print('Starting')\n"
" return self\n"
"\n"
" def __exit__(self, *exc):\n"
" print('Finishing')\n"
" return False"
msgstr ""
"from contextlib import ContextDecorator\n"
"\n"
"class mycontext(ContextDecorator):\n"
" def __enter__(self):\n"
" print('Starting')\n"
" return self\n"
"\n"
" def __exit__(self, *exc):\n"
" print('Finishing')\n"
" return False"
#: ../../library/contextlib.rst:418 ../../library/contextlib.rst:490
msgid "The class can then be used like this::"
msgstr ""
#: ../../library/contextlib.rst:420
msgid ""
">>> @mycontext()\n"
"... def function():\n"
"... print('The bit in the middle')\n"
"...\n"
">>> function()\n"
"Starting\n"
"The bit in the middle\n"
"Finishing\n"
"\n"
">>> with mycontext():\n"
"... print('The bit in the middle')\n"
"...\n"
"Starting\n"
"The bit in the middle\n"
"Finishing"
msgstr ""
">>> @mycontext()\n"
"... def function():\n"
"... print('The bit in the middle')\n"
"...\n"
">>> function()\n"
"Starting\n"
"The bit in the middle\n"
"Finishing\n"
"\n"
">>> with mycontext():\n"
"... print('The bit in the middle')\n"
"...\n"
"Starting\n"
"The bit in the middle\n"
"Finishing"
#: ../../library/contextlib.rst:436
msgid ""
"This change is just syntactic sugar for any construct of the following "
"form::"
msgstr "이 변경은 단지 다음 형식의 구성에 대한 편의 문법일 뿐입니다::"
#: ../../library/contextlib.rst:438
msgid ""
"def f():\n"
" with cm():\n"
" # Do stuff"
msgstr ""
"def f():\n"
" with cm():\n"
" # 뭔가 합니다"
#: ../../library/contextlib.rst:442
msgid "``ContextDecorator`` lets you instead write::"
msgstr "``ContextDecorator``\\는 대신 다음과 같이 쓸 수 있도록 합니다::"
#: ../../library/contextlib.rst:444
msgid ""
"@cm()\n"
"def f():\n"
" # Do stuff"
msgstr ""
"@cm()\n"
"def f():\n"
" # 뭔가 합니다"
#: ../../library/contextlib.rst:448
msgid ""
"It makes it clear that the ``cm`` applies to the whole function, rather "
"than just a piece of it (and saving an indentation level is nice, too)."
msgstr ""
"``cm``\\이 단지 함수의 일부가 아니라 전체 함수에 적용된다는 것을 분명히 합니다 (그리고 들여쓰기 수준을 절약하는 것도 "
"좋습니다)."
#: ../../library/contextlib.rst:451
msgid ""
"Existing context managers that already have a base class can be extended "
"by using ``ContextDecorator`` as a mixin class::"
msgstr ""
"베이스 클래스가 이미 있는 기존 컨텍스트 관리자는 ``ContextDecorator``\\를 믹스인 클래스로 사용하여 확장할 수 "
"있습니다::"
#: ../../library/contextlib.rst:454
msgid ""
"from contextlib import ContextDecorator\n"
"\n"
"class mycontext(ContextBaseClass, ContextDecorator):\n"
" def __enter__(self):\n"
" return self\n"
"\n"
" def __exit__(self, *exc):\n"
" return False"
msgstr ""
"from contextlib import ContextDecorator\n"
"\n"
"class mycontext(ContextBaseClass, ContextDecorator):\n"
" def __enter__(self):\n"
" return self\n"
"\n"
" def __exit__(self, *exc):\n"
" return False"
#: ../../library/contextlib.rst:464
msgid ""
"As the decorated function must be able to be called multiple times, the "
"underlying context manager must support use in multiple :keyword:`with` "
"statements. If this is not the case, then the original construct with the"
" explicit :keyword:`!with` statement inside the function should be used."
msgstr ""
"데코레이트 된 함수는 여러 번 호출될 수 있어야 해서, 하부 컨텍스트 관리자는 여러 :keyword:`with` 문에서의 사용을 "
"지원해야 합니다. 그렇지 않으면, 함수 내에 명시적인 :keyword:`!with` 문이 있는 원래 구문을 사용해야 합니다."
#: ../../library/contextlib.rst:474
msgid "Similar to :class:`ContextDecorator` but only for asynchronous functions."
msgstr ":class:`ContextDecorator`\\와 유사하지만, 비동기 함수 전용입니다."
#: ../../library/contextlib.rst:476
msgid "Example of ``AsyncContextDecorator``::"
msgstr "``AsyncContextDecorator``\\의 예::"
#: ../../library/contextlib.rst:478
msgid ""
"from asyncio import run\n"
"from contextlib import AsyncContextDecorator\n"
"\n"
"class mycontext(AsyncContextDecorator):\n"
" async def __aenter__(self):\n"
" print('Starting')\n"
" return self\n"
"\n"
" async def __aexit__(self, *exc):\n"
" print('Finishing')\n"
" return False"
msgstr ""
"from asyncio import run\n"
"from contextlib import AsyncContextDecorator\n"
"\n"
"class mycontext(AsyncContextDecorator):\n"
" async def __aenter__(self):\n"
" print('Starting')\n"
" return self\n"
"\n"
" async def __aexit__(self, *exc):\n"
" print('Finishing')\n"
" return False"
#: ../../library/contextlib.rst:492
msgid ""
">>> @mycontext()\n"
"... async def function():\n"
"... print('The bit in the middle')\n"
"...\n"
">>> run(function())\n"
"Starting\n"
"The bit in the middle\n"
"Finishing\n"
"\n"
">>> async def function():\n"
"... async with mycontext():\n"
"... print('The bit in the middle')\n"
"...\n"
">>> run(function())\n"
"Starting\n"
"The bit in the middle\n"
"Finishing"
msgstr ""
">>> @mycontext()\n"
"... async def function():\n"
"... print('The bit in the middle')\n"
"...\n"
">>> run(function())\n"
"Starting\n"
"The bit in the middle\n"
"Finishing\n"
"\n"
">>> async def function():\n"
"... async with mycontext():\n"
"... print('The bit in the middle')\n"
"...\n"
">>> run(function())\n"
"Starting\n"
"The bit in the middle\n"
"Finishing"
#: ../../library/contextlib.rst:515
msgid ""
"A context manager that is designed to make it easy to programmatically "
"combine other context managers and cleanup functions, especially those "
"that are optional or otherwise driven by input data."
msgstr ""
"다른 컨텍스트 관리자와 정리 함수, 특히 입력 데이터에 의해 선택적이거나 다른 방식으로 구동되는 것들을 프로그래밍 방식으로 쉽게 "
"결합할 수 있도록 설계된 컨텍스트 관리자."
#: ../../library/contextlib.rst:519
msgid ""
"For example, a set of files may easily be handled in a single with "
"statement as follows::"
msgstr "예를 들어, 일련의 파일을 다음과 같이 단일 with 문으로 쉽게 처리할 수 있습니다::"
#: ../../library/contextlib.rst:522
msgid ""
"with ExitStack() as stack:\n"
" files = [stack.enter_context(open(fname)) for fname in filenames]\n"
" # All opened files will automatically be closed at the end of\n"
" # the with statement, even if attempts to open files later\n"
" # in the list raise an exception"
msgstr ""
"with ExitStack() as stack:\n"
" files = [stack.enter_context(open(fname)) for fname in filenames]\n"
" # 목록의 뒤에 나오는 파일을 열려는 시도가\n"
" # 예외를 발생시키더라도, with 문의 끝에서\n"
" # 열린 모든 파일이 자동으로 닫힙니다."
#: ../../library/contextlib.rst:528
msgid ""
"The :meth:`~object.__enter__` method returns the :class:`ExitStack` "
"instance, and performs no additional operations."
msgstr ""
#: ../../library/contextlib.rst:531
msgid ""
"Each instance maintains a stack of registered callbacks that are called "
"in reverse order when the instance is closed (either explicitly or "
"implicitly at the end of a :keyword:`with` statement). Note that "
"callbacks are *not* invoked implicitly when the context stack instance is"
" garbage collected."
msgstr ""
"각 인스턴스는 인스턴스가 닫힐 때 (명시적으로 혹은 :keyword:`with` 문의 끝에서 묵시적으로) 역순으로 호출되는 등록된 "
"콜백의 스택을 유지합니다. 컨텍스트 스택 인스턴스가 가비지 수집될 때 콜백이 묵시적으로 호출되지 *않음*\\에 유의하십시오."
#: ../../library/contextlib.rst:536
msgid ""
"This stack model is used so that context managers that acquire their "
"resources in their ``__init__`` method (such as file objects) can be "
"handled correctly."
msgstr ""
"이 스택 모델은 ``__init__`` 메서드에서 자원을 확보하는 컨텍스트 관리자(가령 파일 객체)가 올바르게 처리될 수 있도록 "
"사용됩니다."