@@ -263,7 +263,6 @@ msgid "Close the transport."
263
263
msgstr "트랜스포트를 닫습니다."
264
264
265
265
#: ../../library/asyncio-protocol.rst:154
266
- #, fuzzy
267
266
msgid ""
268
267
"If the transport has a buffer for outgoing data, buffered data will be "
269
268
"flushed asynchronously. No more data will be received. After all "
@@ -274,7 +273,8 @@ msgid ""
274
273
msgstr ""
275
274
"트랜스포트에 송신 데이터용 버퍼가 있으면, 버퍼 된 데이터는 비동기적으로 플러시 됩니다. 더는 데이터가 수신되지 않습니다. 버퍼 된"
276
275
" 모든 데이터가 플러시 된 후, 프로토콜의 :meth:`protocol.connection_lost() "
277
- "<BaseProtocol.connection_lost>` 메서드가 :const:`None`\\ 을 인자로 사용하여 호출됩니다."
276
+ "<BaseProtocol.connection_lost>` 메서드가 :const:`None`\\ 을 인자로 사용하여 호출됩니다. "
277
+ "트랜스포트가 닫힌 후에는 사용해서는 안 됩니다."
278
278
279
279
#: ../../library/asyncio-protocol.rst:164
280
280
msgid "Return ``True`` if the transport is closing or is closed."
@@ -311,6 +311,9 @@ msgid ""
311
311
"if sock is not None:\n"
312
312
" print(sock.getsockopt(...))"
313
313
msgstr ""
314
+ "sock = transport.get_extra_info('socket')\n"
315
+ "if sock is not None:\n"
316
+ " print(sock.getsockopt(...))"
314
317
315
318
#: ../../library/asyncio-protocol.rst:186
316
319
msgid "Categories of information that can be queried on some transports:"
@@ -679,14 +682,13 @@ msgid "Stop the subprocess."
679
682
msgstr "서브 프로세스를 중지합니다."
680
683
681
684
#: ../../library/asyncio-protocol.rst:425
682
- #, fuzzy
683
685
msgid ""
684
686
"On POSIX systems, this method sends :py:const:`~signal.SIGTERM` to the "
685
687
"subprocess. On Windows, the Windows API function "
686
688
":c:func:`!TerminateProcess` is called to stop the subprocess."
687
689
msgstr ""
688
- "POSIX 시스템에서, 이 메서드는SIGTERM을 서브 프로세스로 보냅니다. 윈도에서, 서브 프로세스를 중지하기 위해 윈도우 "
689
- "API 함수 TerminateProcess() 가 호출됩니다."
690
+ "POSIX 시스템에서, 이 메서드는:py:const:`~signal.SIGTERM` \\ 을 서브 프로세스로 보냅니다. 윈도에서, "
691
+ "서브 프로세스를 중지하기 위해 윈도우 API 함수:c:func:`! TerminateProcess` \\ 가 호출됩니다."
690
692
691
693
#: ../../library/asyncio-protocol.rst:429
692
694
msgid "See also :meth:`subprocess.Popen.terminate`."
@@ -889,14 +891,14 @@ msgid ""
889
891
msgstr "이 메서드는 연결이 열려있는 동안 임의의 횟수만큼 호출될 수 있습니다."
890
892
891
893
#: ../../library/asyncio-protocol.rst:561
892
- #, fuzzy
893
894
msgid ""
894
895
"However, :meth:`protocol.eof_received() <Protocol.eof_received>` is "
895
896
"called at most once. Once ``eof_received()`` is called, "
896
897
"``data_received()`` is not called anymore."
897
898
msgstr ""
898
899
"그러나, :meth:`protocol.eof_received() <Protocol.eof_received>`\\ 는 최대한 한 번만 "
899
- "호출됩니다. 일단 `eof_received()`\\ 가 호출되면, ``data_received()``\\ 는 더는 호출되지 않습니다."
900
+ "호출됩니다. 일단 ``eof_received()``\\ 가 호출되면, ``data_received()``\\ 는 더는 호출되지 "
901
+ "않습니다."
900
902
901
903
#: ../../library/asyncio-protocol.rst:567
902
904
msgid ""
@@ -938,6 +940,10 @@ msgid ""
938
940
" [-> eof_received]?\n"
939
941
"-> connection_lost -> end"
940
942
msgstr ""
943
+ "start -> connection_made\n"
944
+ " [-> data_received]*\n"
945
+ " [-> eof_received]?\n"
946
+ "-> connection_lost -> end"
941
947
942
948
#: ../../library/asyncio-protocol.rst:594
943
949
msgid "Buffered Streaming Protocols"
@@ -1024,6 +1030,12 @@ msgid ""
1024
1030
" [-> eof_received]?\n"
1025
1031
"-> connection_lost -> end"
1026
1032
msgstr ""
1033
+ "start -> connection_made\n"
1034
+ " [-> get_buffer\n"
1035
+ " [-> buffer_updated]?\n"
1036
+ " ]*\n"
1037
+ " [-> eof_received]?\n"
1038
+ "-> connection_lost -> end"
1027
1039
1028
1040
#: ../../library/asyncio-protocol.rst:654
1029
1041
msgid "Datagram Protocols"
@@ -1088,7 +1100,6 @@ msgid "Subprocess Protocols"
1088
1100
msgstr "서브 프로세스 프로토콜"
1089
1101
1090
1102
#: ../../library/asyncio-protocol.rst:692
1091
- #, fuzzy
1092
1103
msgid ""
1093
1104
"Subprocess Protocol instances should be constructed by protocol factories"
1094
1105
" passed to the :meth:`loop.subprocess_exec` and "
@@ -1183,6 +1194,40 @@ msgid ""
1183
1194
"\n"
1184
1195
"asyncio.run(main())"
1185
1196
msgstr ""
1197
+ "import asyncio\n"
1198
+ "\n"
1199
+ "\n"
1200
+ "class EchoServerProtocol(asyncio.Protocol):\n"
1201
+ " def connection_made(self, transport):\n"
1202
+ " peername = transport.get_extra_info('peername')\n"
1203
+ " print('Connection from {}'.format(peername))\n"
1204
+ " self.transport = transport\n"
1205
+ "\n"
1206
+ " def data_received(self, data):\n"
1207
+ " message = data.decode()\n"
1208
+ " print('Data received: {!r}'.format(message))\n"
1209
+ "\n"
1210
+ " print('Send: {!r}'.format(message))\n"
1211
+ " self.transport.write(data)\n"
1212
+ "\n"
1213
+ " print('Close the client socket')\n"
1214
+ " self.transport.close()\n"
1215
+ "\n"
1216
+ "\n"
1217
+ "async def main():\n"
1218
+ " # 저수준 API를 사용할 계획이므로\n"
1219
+ " # 이벤트 루프에 대한 참조를 얻습니다.\n"
1220
+ " loop = asyncio.get_running_loop()\n"
1221
+ "\n"
1222
+ " server = await loop.create_server(\n"
1223
+ " EchoServerProtocol,\n"
1224
+ " '127.0.0.1', 8888)\n"
1225
+ "\n"
1226
+ " async with server:\n"
1227
+ " await server.serve_forever()\n"
1228
+ "\n"
1229
+ "\n"
1230
+ "asyncio.run(main())"
1186
1231
1187
1232
#: ../../library/asyncio-protocol.rst:769
1188
1233
msgid ""
@@ -1250,6 +1295,47 @@ msgid ""
1250
1295
"\n"
1251
1296
"asyncio.run(main())"
1252
1297
msgstr ""
1298
+ "import asyncio\n"
1299
+ "\n"
1300
+ "\n"
1301
+ "class EchoClientProtocol(asyncio.Protocol):\n"
1302
+ " def __init__(self, message, on_con_lost):\n"
1303
+ " self.message = message\n"
1304
+ " self.on_con_lost = on_con_lost\n"
1305
+ "\n"
1306
+ " def connection_made(self, transport):\n"
1307
+ " transport.write(self.message.encode())\n"
1308
+ " print('Data sent: {!r}'.format(self.message))\n"
1309
+ "\n"
1310
+ " def data_received(self, data):\n"
1311
+ " print('Data received: {!r}'.format(data.decode()))\n"
1312
+ "\n"
1313
+ " def connection_lost(self, exc):\n"
1314
+ " print('The server closed the connection')\n"
1315
+ " self.on_con_lost.set_result(True)\n"
1316
+ "\n"
1317
+ "\n"
1318
+ "async def main():\n"
1319
+ " # 저수준 API를 사용할 계획이므로\n"
1320
+ " # 이벤트 루프에 대한 참조를 얻습니다.\n"
1321
+ " loop = asyncio.get_running_loop()\n"
1322
+ "\n"
1323
+ " on_con_lost = loop.create_future()\n"
1324
+ " message = 'Hello World!'\n"
1325
+ "\n"
1326
+ " transport, protocol = await loop.create_connection(\n"
1327
+ " lambda: EchoClientProtocol(message, on_con_lost),\n"
1328
+ " '127.0.0.1', 8888)\n"
1329
+ "\n"
1330
+ " # 프로토콜이 연결이 끊어졌음을 알릴 때까지 기다리고\n"
1331
+ " # 트랜스포트를 닫습니다.\n"
1332
+ " try:\n"
1333
+ " await on_con_lost\n"
1334
+ " finally:\n"
1335
+ " transport.close()\n"
1336
+ "\n"
1337
+ "\n"
1338
+ "asyncio.run(main())"
1253
1339
1254
1340
#: ../../library/asyncio-protocol.rst:825
1255
1341
msgid ""
@@ -1310,6 +1396,40 @@ msgid ""
1310
1396
"\n"
1311
1397
"asyncio.run(main())"
1312
1398
msgstr ""
1399
+ "import asyncio\n"
1400
+ "\n"
1401
+ "\n"
1402
+ "class EchoServerProtocol:\n"
1403
+ " def connection_made(self, transport):\n"
1404
+ " self.transport = transport\n"
1405
+ "\n"
1406
+ " def datagram_received(self, data, addr):\n"
1407
+ " message = data.decode()\n"
1408
+ " print('Received %r from %s' % (message, addr))\n"
1409
+ " print('Send %r to %s' % (message, addr))\n"
1410
+ " self.transport.sendto(data, addr)\n"
1411
+ "\n"
1412
+ "\n"
1413
+ "async def main():\n"
1414
+ " print(\" Starting UDP server\" )\n"
1415
+ "\n"
1416
+ " # 저수준 API를 사용할 계획이므로\n"
1417
+ " # 이벤트 루프에 대한 참조를 얻습니다.\n"
1418
+ " loop = asyncio.get_running_loop()\n"
1419
+ "\n"
1420
+ " # 모든 클라이언트 요청을 처리할\n"
1421
+ " # 하나의 프로토콜 인스턴스가 만들어집니다.\n"
1422
+ " transport, protocol = await loop.create_datagram_endpoint(\n"
1423
+ " EchoServerProtocol,\n"
1424
+ " local_addr=('127.0.0.1', 9999))\n"
1425
+ "\n"
1426
+ " try:\n"
1427
+ " await asyncio.sleep(3600) # 1시간 동안 서비스합니다.\n"
1428
+ " finally:\n"
1429
+ " transport.close()\n"
1430
+ "\n"
1431
+ "\n"
1432
+ "asyncio.run(main())"
1313
1433
1314
1434
#: ../../library/asyncio-protocol.rst:876
1315
1435
msgid "UDP Echo Client"
@@ -1373,6 +1493,53 @@ msgid ""
1373
1493
"\n"
1374
1494
"asyncio.run(main())"
1375
1495
msgstr ""
1496
+ "import asyncio\n"
1497
+ "\n"
1498
+ "\n"
1499
+ "class EchoClientProtocol:\n"
1500
+ " def __init__(self, message, on_con_lost):\n"
1501
+ " self.message = message\n"
1502
+ " self.on_con_lost = on_con_lost\n"
1503
+ " self.transport = None\n"
1504
+ "\n"
1505
+ " def connection_made(self, transport):\n"
1506
+ " self.transport = transport\n"
1507
+ " print('Send:', self.message)\n"
1508
+ " self.transport.sendto(self.message.encode())\n"
1509
+ "\n"
1510
+ " def datagram_received(self, data, addr):\n"
1511
+ " print(\" Received:\" , data.decode())\n"
1512
+ "\n"
1513
+ " print(\" Close the socket\" )\n"
1514
+ " self.transport.close()\n"
1515
+ "\n"
1516
+ " def error_received(self, exc):\n"
1517
+ " print('Error received:', exc)\n"
1518
+ "\n"
1519
+ " def connection_lost(self, exc):\n"
1520
+ " print(\" Connection closed\" )\n"
1521
+ " self.on_con_lost.set_result(True)\n"
1522
+ "\n"
1523
+ "\n"
1524
+ "async def main():\n"
1525
+ " # 저수준 API를 사용할 계획이므로\n"
1526
+ " # 이벤트 루프에 대한 참조를 얻습니다.\n"
1527
+ " loop = asyncio.get_running_loop()\n"
1528
+ "\n"
1529
+ " on_con_lost = loop.create_future()\n"
1530
+ " message =\" Hello World!\" \n"
1531
+ "\n"
1532
+ " transport, protocol = await loop.create_datagram_endpoint(\n"
1533
+ " lambda: EchoClientProtocol(message, on_con_lost),\n"
1534
+ " remote_addr=('127.0.0.1', 9999))\n"
1535
+ "\n"
1536
+ " try:\n"
1537
+ " await on_con_lost\n"
1538
+ " finally:\n"
1539
+ " transport.close()\n"
1540
+ "\n"
1541
+ "\n"
1542
+ "asyncio.run(main())"
1376
1543
1377
1544
#: ../../library/asyncio-protocol.rst:933
1378
1545
msgid "Connecting Existing Sockets"
@@ -1435,6 +1602,54 @@ msgid ""
1435
1602
"\n"
1436
1603
"asyncio.run(main())"
1437
1604
msgstr ""
1605
+ "import asyncio\n"
1606
+ "import socket\n"
1607
+ "\n"
1608
+ "\n"
1609
+ "class MyProtocol(asyncio.Protocol):\n"
1610
+ "\n"
1611
+ " def __init__(self, on_con_lost):\n"
1612
+ " self.transport = None\n"
1613
+ " self.on_con_lost = on_con_lost\n"
1614
+ "\n"
1615
+ " def connection_made(self, transport):\n"
1616
+ " self.transport = transport\n"
1617
+ "\n"
1618
+ " def data_received(self, data):\n"
1619
+ " print(\" Received:\" , data.decode())\n"
1620
+ "\n"
1621
+ " # 작업을 완료했습니다: 트랜스포트를 닫습니다;\n"
1622
+ " # connection_lost()가 자동으로 호출됩니다.\n"
1623
+ " self.transport.close()\n"
1624
+ "\n"
1625
+ " def connection_lost(self, exc):\n"
1626
+ " # 소켓이 닫혔습니다\n"
1627
+ " self.on_con_lost.set_result(True)\n"
1628
+ "\n"
1629
+ "\n"
1630
+ "async def main():\n"
1631
+ " # 저수준 API를 사용할 계획이므로\n"
1632
+ " # 이벤트 루프에 대한 참조를 얻습니다.\n"
1633
+ " loop = asyncio.get_running_loop()\n"
1634
+ " on_con_lost = loop.create_future()\n"
1635
+ "\n"
1636
+ " # 연결된 소켓 쌍을 만듭니다\n"
1637
+ " rsock, wsock = socket.socketpair()\n"
1638
+ "\n"
1639
+ " # 데이터를 기다릴 소켓을 등록합니다.\n"
1640
+ " transport, protocol = await loop.create_connection(\n"
1641
+ " lambda: MyProtocol(on_con_lost), sock=rsock)\n"
1642
+ "\n"
1643
+ " # 네트워크로부터의 데이터 수신을 흉내 냅니다.\n"
1644
+ " loop.call_soon(wsock.send, 'abc'.encode())\n"
1645
+ "\n"
1646
+ " try:\n"
1647
+ " await protocol.on_con_lost\n"
1648
+ " finally:\n"
1649
+ " transport.close()\n"
1650
+ " wsock.close()\n"
1651
+ "\n"
1652
+ "asyncio.run(main())"
1438
1653
1439
1654
#: ../../library/asyncio-protocol.rst:989
1440
1655
msgid ""
@@ -1529,6 +1744,63 @@ msgid ""
1529
1744
"date = asyncio.run(get_date())\n"
1530
1745
"print(f\" Current date: {date}\" )"
1531
1746
msgstr ""
1747
+ "import asyncio\n"
1748
+ "import sys\n"
1749
+ "\n"
1750
+ "class DateProtocol(asyncio.SubprocessProtocol):\n"
1751
+ " def __init__(self, exit_future):\n"
1752
+ " self.exit_future = exit_future\n"
1753
+ " self.output = bytearray()\n"
1754
+ " self.pipe_closed = False\n"
1755
+ " self.exited = False\n"
1756
+ "\n"
1757
+ " def pipe_connection_lost(self, fd, exc):\n"
1758
+ " self.pipe_closed = True\n"
1759
+ " self.check_for_exit()\n"
1760
+ "\n"
1761
+ " def pipe_data_received(self, fd, data):\n"
1762
+ " self.output.extend(data)\n"
1763
+ "\n"
1764
+ " def process_exited(self):\n"
1765
+ " self.exited = True\n"
1766
+ " # pipe_connection_lost() 메서드 전에\n"
1767
+ " # process_exited() 메서드가 호출될 수 있습니다:\n"
1768
+ " # 두 메서드가 모두 호출될 때까지 기다립니다.\n"
1769
+ " self.check_for_exit()\n"
1770
+ "\n"
1771
+ " def check_for_exit(self):\n"
1772
+ " if self.pipe_closed and self.exited:\n"
1773
+ " self.exit_future.set_result(True)\n"
1774
+ "\n"
1775
+ "async def get_date():\n"
1776
+ " # 저수준 API를 사용할 계획이므로\n"
1777
+ " # 이벤트 루프에 대한 참조를 얻습니다.\n"
1778
+ " loop = asyncio.get_running_loop()\n"
1779
+ "\n"
1780
+ " code = 'import datetime; print(datetime.datetime.now())'\n"
1781
+ " exit_future = asyncio.Future(loop=loop)\n"
1782
+ "\n"
1783
+ " # DateProtocol이 제어하는 서브 프로세스를 만듭니다;\n"
1784
+ " # 표준 출력을 파이프로 리디렉트합니다.\n"
1785
+ " transport, protocol = await loop.subprocess_exec(\n"
1786
+ " lambda: DateProtocol(exit_future),\n"
1787
+ " sys.executable, '-c', code,\n"
1788
+ " stdin=None, stderr=None)\n"
1789
+ "\n"
1790
+ " # 프로토콜의 process_exited() 메서드를 사용하여\n"
1791
+ " # 서브 프로세스 종료를 기다립니다.\n"
1792
+ " await exit_future\n"
1793
+ "\n"
1794
+ " # stdout 파이프를 닫습니다.\n"
1795
+ " transport.close()\n"
1796
+ "\n"
1797
+ " # 프로토콜의 pipe_data_received() 메서드로\n"
1798
+ " # 수집된 출력을 읽습니다.\n"
1799
+ " data = bytes(protocol.output)\n"
1800
+ " return data.decode('ascii').rstrip()\n"
1801
+ "\n"
1802
+ "date = asyncio.run(get_date())\n"
1803
+ "print(f\" Current date: {date}\" )"
1532
1804
1533
1805
#: ../../library/asyncio-protocol.rst:1065
1534
1806
msgid ""