MCPcopy Index your code
hub / github.com/python/cpython / _SendfileFallbackProtocol

Class _SendfileFallbackProtocol

Lib/asyncio/base_events.py:209–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

207
208
209class _SendfileFallbackProtocol(protocols.Protocol):
210 def __init__(self, transp):
211 if not isinstance(transp, transports._FlowControlMixin):
212 raise TypeError("transport should be _FlowControlMixin instance")
213 self._transport = transp
214 self._proto = transp.get_protocol()
215 self._should_resume_reading = transp.is_reading()
216 self._should_resume_writing = transp._protocol_paused
217 transp.pause_reading()
218 transp.set_protocol(self)
219 if self._should_resume_writing:
220 self._write_ready_fut = self._transport._loop.create_future()
221 else:
222 self._write_ready_fut = None
223
224 async def drain(self):
225 if self._transport.is_closing():
226 raise ConnectionError("Connection closed by peer")
227 fut = self._write_ready_fut
228 if fut is None:
229 return
230 await fut
231
232 def connection_made(self, transport):
233 raise RuntimeError("Invalid state: "
234 "connection should have been established already.")
235
236 def connection_lost(self, exc):
237 if self._write_ready_fut is not None:
238 # Never happens if peer disconnects after sending the whole content
239 # Thus disconnection is always an exception from user perspective
240 if exc is None:
241 self._write_ready_fut.set_exception(
242 ConnectionError("Connection is closed by peer"))
243 else:
244 self._write_ready_fut.set_exception(exc)
245 self._proto.connection_lost(exc)
246
247 def pause_writing(self):
248 if self._write_ready_fut is not None:
249 return
250 self._write_ready_fut = self._transport._loop.create_future()
251
252 def resume_writing(self):
253 if self._write_ready_fut is None:
254 return
255 self._write_ready_fut.set_result(False)
256 self._write_ready_fut = None
257
258 def data_received(self, data):
259 raise RuntimeError("Invalid state: reading should be paused")
260
261 def eof_received(self):
262 raise RuntimeError("Invalid state: reading should be paused")
263
264 async def restore(self):
265 self._transport.set_protocol(self._proto)
266 if self._should_resume_reading:

Callers 1

_sendfile_fallbackMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…