1
- """
2
- The `Stream` class here provides a lightweight layer over
3
- `asyncio.StreamReader` and `asyncio.StreamWriter`.
4
-
5
- Similarly `PoolSemaphore` is a lightweight layer over `BoundedSemaphore`.
6
-
7
- These classes help encapsulate the timeout logic, make it easier to unit-test
8
- protocols, and help keep the rest of the package more `async`/`await`
9
- based, and less strictly `asyncio`-specific.
10
- """
11
1
import asyncio
12
2
import functools
13
3
import ssl
21
11
BaseEvent ,
22
12
BasePoolSemaphore ,
23
13
BaseQueue ,
24
- BaseStream ,
14
+ BaseTCPStream ,
25
15
ConcurrencyBackend ,
26
16
TimeoutFlag ,
27
17
)
@@ -50,7 +40,7 @@ def _fixed_write(self, data: bytes) -> None: # type: ignore
50
40
MonkeyPatch .write = _fixed_write
51
41
52
42
53
- class Stream ( BaseStream ):
43
+ class TCPStream ( BaseTCPStream ):
54
44
def __init__ (
55
45
self ,
56
46
stream_reader : asyncio .StreamReader ,
@@ -176,13 +166,13 @@ def loop(self) -> asyncio.AbstractEventLoop:
176
166
self ._loop = asyncio .new_event_loop ()
177
167
return self ._loop
178
168
179
- async def connect (
169
+ async def open_tcp_stream (
180
170
self ,
181
171
hostname : str ,
182
172
port : int ,
183
173
ssl_context : typing .Optional [ssl .SSLContext ],
184
174
timeout : TimeoutConfig ,
185
- ) -> BaseStream :
175
+ ) -> BaseTCPStream :
186
176
try :
187
177
stream_reader , stream_writer = await asyncio .wait_for ( # type: ignore
188
178
asyncio .open_connection (hostname , port , ssl = ssl_context ),
@@ -191,25 +181,25 @@ async def connect(
191
181
except asyncio .TimeoutError :
192
182
raise ConnectTimeout ()
193
183
194
- return Stream (
184
+ return TCPStream (
195
185
stream_reader = stream_reader , stream_writer = stream_writer , timeout = timeout
196
186
)
197
187
198
188
async def start_tls (
199
189
self ,
200
- stream : BaseStream ,
190
+ stream : BaseTCPStream ,
201
191
hostname : str ,
202
192
ssl_context : ssl .SSLContext ,
203
193
timeout : TimeoutConfig ,
204
- ) -> BaseStream :
194
+ ) -> BaseTCPStream :
205
195
206
196
loop = self .loop
207
197
if not hasattr (loop , "start_tls" ): # pragma: no cover
208
198
raise NotImplementedError (
209
199
"asyncio.AbstractEventLoop.start_tls() is only available in Python 3.7+"
210
200
)
211
201
212
- assert isinstance (stream , Stream )
202
+ assert isinstance (stream , TCPStream )
213
203
214
204
stream_reader = asyncio .StreamReader ()
215
205
protocol = asyncio .StreamReaderProtocol (stream_reader )
0 commit comments