Skip to content

Commit a07b2b1

Browse files
committed
Add new asyncio-based implementation.
1 parent f58355e commit a07b2b1

File tree

10 files changed

+536
-9
lines changed

10 files changed

+536
-9
lines changed

src/websockets/asyncio/client.py

Whitespace-only changes.

src/websockets/asyncio/connection.py

+526
Large diffs are not rendered by default.

src/websockets/asyncio/messages.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import asyncio
44
import codecs
5-
from typing import AsyncIterator, List, Optional
5+
from typing import AsyncIterable, List, Optional
66

77
from ..frames import Frame, Opcode
88
from ..typing import Data
@@ -101,7 +101,7 @@ async def get(self) -> Data:
101101

102102
return message
103103

104-
async def get_iter(self) -> AsyncIterator[Data]:
104+
async def get_iter(self) -> AsyncIterable[Data]:
105105
"""
106106
Stream the next message.
107107

src/websockets/asyncio/server.py

Whitespace-only changes.

src/websockets/sync/client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
class ClientConnection(Connection):
2626
"""
27-
Threaded implementation of a WebSocket client connection.
27+
:mod:`threading` implementation of a WebSocket client connection.
2828
2929
:class:`ClientConnection` provides :meth:`recv` and :meth:`send` methods for
3030
receiving and sending messages.

src/websockets/sync/connection.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
class Connection:
2828
"""
29-
Threaded implementation of a WebSocket connection.
29+
:mod:`threading` implementation of a WebSocket connection.
3030
3131
:class:`Connection` provides APIs shared between WebSocket servers and
3232
clients.
@@ -229,7 +229,8 @@ def recv_streaming(self) -> Iterator[Data]:
229229
230230
"""
231231
try:
232-
yield from self.recv_messages.get_iter()
232+
for frame in self.recv_messages.get_iter():
233+
yield frame
233234
except EOFError:
234235
raise self.protocol.close_exc from self.recv_events_exc
235236
except RuntimeError:
@@ -273,7 +274,7 @@ def send(self, message: Union[Data, Iterable[Data]]) -> None:
273274
274275
Raises:
275276
ConnectionClosed: When the connection is closed.
276-
RuntimeError: If a connection is busy sending a fragmented message.
277+
RuntimeError: If the connection is sending a fragmented message.
277278
TypeError: If ``message`` doesn't have a supported type.
278279
279280
"""
@@ -552,7 +553,7 @@ def recv_events(self) -> None:
552553

553554
# Acquire the connection lock.
554555
with self.protocol_mutex:
555-
# Feed incoming data to the connection.
556+
# Feed incoming data to the protocol.
556557
self.protocol.receive_data(data)
557558

558559
# This isn't expected to raise an exception.
@@ -595,7 +596,7 @@ def recv_events(self) -> None:
595596
# Breaking out of the while True: ... loop means that we believe
596597
# that the socket doesn't work anymore.
597598
with self.protocol_mutex:
598-
# Feed the end of the data stream to the connection.
599+
# Feed the end of the data stream to the protocol.
599600
self.protocol.receive_eof()
600601

601602
# This isn't expected to generate events.

src/websockets/sync/server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
class ServerConnection(Connection):
3131
"""
32-
Threaded implementation of a WebSocket server connection.
32+
:mod:`threading` implementation of a WebSocket server connection.
3333
3434
:class:`ServerConnection` provides :meth:`recv` and :meth:`send` methods for
3535
receiving and sending messages.

tests/asyncio/test_client.py

Whitespace-only changes.

tests/asyncio/test_connection.py

Whitespace-only changes.

tests/asyncio/test_server.py

Whitespace-only changes.

0 commit comments

Comments
 (0)