Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Lib/asyncio/base_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,12 @@ async def sendfile(self, transport, file, offset=0, count=None,
except events.SendfileNotAvailableError as exc:
if not fallback:
raise
# the mode is FALLBACK or fallback is True

if not fallback:
raise RuntimeError(
f"fallback is disabled and native sendfile is not "
f"supported for transport {transport!r}")

return await self._sendfile_fallback(transport, file,
offset, count)

Expand Down
9 changes: 9 additions & 0 deletions Lib/test/test_asyncio/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import asyncio
from asyncio import base_events
from asyncio import constants
from asyncio import coroutines
from asyncio import events
from asyncio import proactor_events
Expand Down Expand Up @@ -2381,6 +2382,14 @@ async def coro():
ret = self.run_loop(t)
self.assertEqual(ret, len(self.DATA))

def test_sendfile_no_fallback_for_fallback_transport(self):
transport = mock.Mock()
transport.is_closing.side_effect = lambda: False
transport._sendfile_compatible = constants._SendfileMode.FALLBACK
with self.assertRaisesRegex(RuntimeError, 'fallback is disabled'):
self.loop.run_until_complete(
self.loop.sendfile(transport, None, fallback=False))


if sys.platform == 'win32':

Expand Down