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

Method sendfile

Lib/asyncio/base_events.py:1245–1290  ·  view source on GitHub ↗

Send a file to transport. Return the total number of bytes which were sent. The method uses high-performance os.sendfile if available. file must be a regular file object opened in binary mode. offset tells from where to start reading the file. If specified,

(self, transport, file, offset=0, count=None,
                       *, fallback=True)

Source from the content-addressed store, hash-verified

1243 return transport, protocol
1244
1245 async def sendfile(self, transport, file, offset=0, count=None,
1246 *, fallback=True):
1247 """Send a file to transport.
1248
1249 Return the total number of bytes which were sent.
1250
1251 The method uses high-performance os.sendfile if available.
1252
1253 file must be a regular file object opened in binary mode.
1254
1255 offset tells from where to start reading the file. If specified,
1256 count is the total number of bytes to transmit as opposed to
1257 sending the file until EOF is reached. File position is updated on
1258 return or also in case of error in which case file.tell()
1259 can be used to figure out the number of bytes
1260 which were sent.
1261
1262 fallback set to True makes asyncio to manually read and send
1263 the file when the platform does not support the sendfile syscall
1264 (e.g. Windows or SSL socket on Unix).
1265
1266 Raise SendfileNotAvailableError if the system does not support
1267 sendfile syscall and fallback is False.
1268 """
1269 if transport.is_closing():
1270 raise RuntimeError("Transport is closing")
1271 mode = getattr(transport, '_sendfile_compatible',
1272 constants._SendfileMode.UNSUPPORTED)
1273 if mode is constants._SendfileMode.UNSUPPORTED:
1274 raise RuntimeError(
1275 f"sendfile is not supported for transport {transport!r}")
1276 if mode is constants._SendfileMode.TRY_NATIVE:
1277 try:
1278 return await self._sendfile_native(transport, file,
1279 offset, count)
1280 except exceptions.SendfileNotAvailableError:
1281 if not fallback:
1282 raise
1283
1284 if not fallback:
1285 raise RuntimeError(
1286 f"fallback is disabled and native sendfile is not "
1287 f"supported for transport {transport!r}")
1288
1289 return await self._sendfile_fallback(transport, file,
1290 offset, count)
1291
1292 async def _sendfile_native(self, transp, file, offset, count):
1293 raise exceptions.SendfileNotAvailableError(

Callers

nothing calls this directly

Calls 3

_sendfile_nativeMethod · 0.95
_sendfile_fallbackMethod · 0.95
is_closingMethod · 0.45

Tested by

no test coverage detected