From 7a7d2e3848ac3512bc47843e7ef9d1f6d90856a1 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 1 Nov 2020 19:39:53 +0100 Subject: [PATCH] Add whence parameter to UploadFile.seek() --- starlette/datastructures.py | 6 +++--- tests/test_datastructures.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/starlette/datastructures.py b/starlette/datastructures.py index 8dad7b0b50..558730c45b 100644 --- a/starlette/datastructures.py +++ b/starlette/datastructures.py @@ -449,11 +449,11 @@ async def read(self, size: int = -1) -> typing.Union[bytes, str]: return self.file.read(size) return await run_in_threadpool(self.file.read, size) - async def seek(self, offset: int) -> None: + async def seek(self, offset: int, whence: int) -> None: if self._in_memory: - self.file.seek(offset) + self.file.seek(offset, whence) else: - await run_in_threadpool(self.file.seek, offset) + await run_in_threadpool(self.file.seek, offset, whence) async def close(self) -> None: if self._in_memory: diff --git a/tests/test_datastructures.py b/tests/test_datastructures.py index b0e6baf985..bd356c236f 100644 --- a/tests/test_datastructures.py +++ b/tests/test_datastructures.py @@ -222,7 +222,7 @@ async def test_upload_file(): big_file = BigUploadFile("big-file") await big_file.write(b"big-data" * 512) await big_file.write(b"big-data") - await big_file.seek(0) + await big_file.seek(0, 0) assert await big_file.read(1024) == b"big-data" * 128 await big_file.close()