MCPcopy Index your code
hub / github.com/RustPython/RustPython / StreamReaderProtocol

Class StreamReaderProtocol

Lib/asyncio/streams.py:180–306  ·  view source on GitHub ↗

Helper class to adapt between Protocol and StreamReader. (This is a helper class instead of making StreamReader itself a Protocol subclass, because the StreamReader has other potential uses, and to prevent the user of the StreamReader to accidentally call inappropriate methods of th

Source from the content-addressed store, hash-verified

178
179
180class StreamReaderProtocol(FlowControlMixin, protocols.Protocol):
181 """Helper class to adapt between Protocol and StreamReader.
182
183 (This is a helper class instead of making StreamReader itself a
184 Protocol subclass, because the StreamReader has other potential
185 uses, and to prevent the user of the StreamReader to accidentally
186 call inappropriate methods of the protocol.)
187 """
188
189 _source_traceback = None
190
191 def __init__(self, stream_reader, client_connected_cb=None, loop=None):
192 super().__init__(loop=loop)
193 if stream_reader is not None:
194 self._stream_reader_wr = weakref.ref(stream_reader)
195 self._source_traceback = stream_reader._source_traceback
196 else:
197 self._stream_reader_wr = None
198 if client_connected_cb is not None:
199 # This is a stream created by the `create_server()` function.
200 # Keep a strong reference to the reader until a connection
201 # is established.
202 self._strong_reader = stream_reader
203 self._reject_connection = False
204 self._task = None
205 self._transport = None
206 self._client_connected_cb = client_connected_cb
207 self._over_ssl = False
208 self._closed = self._loop.create_future()
209
210 @property
211 def _stream_reader(self):
212 if self._stream_reader_wr is None:
213 return None
214 return self._stream_reader_wr()
215
216 def _replace_transport(self, transport):
217 loop = self._loop
218 self._transport = transport
219 self._over_ssl = transport.get_extra_info('sslcontext') is not None
220
221 def connection_made(self, transport):
222 if self._reject_connection:
223 context = {
224 'message': ('An open stream was garbage collected prior to '
225 'establishing network connection; '
226 'call "stream.close()" explicitly.')
227 }
228 if self._source_traceback:
229 context['source_traceback'] = self._source_traceback
230 self._loop.call_exception_handler(context)
231 transport.abort()
232 return
233 self._transport = transport
234 reader = self._stream_reader
235 if reader is not None:
236 reader.set_transport(transport)
237 self._over_ssl = transport.get_extra_info('sslcontext') is not None

Callers 3

open_connectionFunction · 0.85
factoryFunction · 0.85
open_unix_connectionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected