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
| 178 | |
| 179 | |
| 180 | class 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 | self._transport = transport |
| 218 | self._over_ssl = transport.get_extra_info('sslcontext') is not None |
| 219 | |
| 220 | def connection_made(self, transport): |
| 221 | if self._reject_connection: |
| 222 | context = { |
| 223 | 'message': ('An open stream was garbage collected prior to ' |
| 224 | 'establishing network connection; ' |
| 225 | 'call "stream.close()" explicitly.') |
| 226 | } |
| 227 | if self._source_traceback: |
| 228 | context['source_traceback'] = self._source_traceback |
| 229 | self._loop.call_exception_handler(context) |
| 230 | transport.abort() |
| 231 | return |
| 232 | self._transport = transport |
| 233 | reader = self._stream_reader |
| 234 | if reader is not None: |
| 235 | reader.set_transport(transport) |
| 236 | self._over_ssl = transport.get_extra_info('sslcontext') is not None |
| 237 | if self._client_connected_cb is not None: |
no outgoing calls
no test coverage detected
searching dependent graphs…