Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
upload: Switch from BinaryIO to IO[bytes].
Alex Vandiver2dc737335ee3
diff --git a/zerver/lib/upload/__init__.py b/zerver/lib/upload/__init__.pyindex 1a2eb527768..27268487f54 100644--- a/zerver/lib/upload/__init__.py+++ b/zerver/lib/upload/__init__.py@@ -5,7 +5,7 @@ import reimport unicodedatafrom collections.abc import Callable, Iteratorfrom datetime import datetime-from typing import IO, Any, BinaryIO+from typing import IO, Anyfrom urllib.parse import unquote, urljoinimport pyvips@@ -212,7 +212,7 @@ def attachment_vips_source(path_id: str) -> StreamingSourceWithSize:return upload_backend.attachment_vips_source(path_id)-def save_attachment_contents(path_id: str, filehandle: BinaryIO) -> None:+def save_attachment_contents(path_id: str, filehandle: IO[bytes]) -> None:return upload_backend.save_attachment_contents(path_id, filehandle)diff --git a/zerver/lib/upload/base.py b/zerver/lib/upload/base.pyindex 021f19420a6..cfc8ec43188 100644--- a/zerver/lib/upload/base.py+++ b/zerver/lib/upload/base.py@@ -2,7 +2,7 @@ import osfrom collections.abc import Callable, Iteratorfrom dataclasses import dataclassfrom datetime import datetime-from typing import IO, Any, BinaryIO+from typing import IO, Anyimport pyvips@@ -54,7 +54,7 @@ class ZulipUploadBackend:) -> None:raise NotImplementedError- def save_attachment_contents(self, path_id: str, filehandle: BinaryIO) -> None:+ def save_attachment_contents(self, path_id: str, filehandle: IO[bytes]) -> None:raise NotImplementedErrordef attachment_vips_source(self, path_id: str) -> StreamingSourceWithSize:diff --git a/zerver/lib/upload/local.py b/zerver/lib/upload/local.pyindex 58c5c042f1c..d98d77fc30b 100644--- a/zerver/lib/upload/local.py+++ b/zerver/lib/upload/local.py@@ -5,7 +5,7 @@ import secretsimport shutilfrom collections.abc import Callable, Iteratorfrom datetime import datetime-from typing import IO, Any, BinaryIO, Literal+from typing import IO, Any, Literalimport pyvipsfrom django.conf import settings@@ -98,7 +98,7 @@ class LocalUploadBackend(ZulipUploadBackend):write_local_file("files", path_id, file_data)@override- def save_attachment_contents(self, path_id: str, filehandle: BinaryIO) -> None:+ def save_attachment_contents(self, path_id: str, filehandle: IO[bytes]) -> None:filehandle.write(read_local_file("files", path_id))@overridediff --git a/zerver/lib/upload/s3.py b/zerver/lib/upload/s3.pyindex 29407cff80f..ae3c7bbaefd 100644--- a/zerver/lib/upload/s3.py+++ b/zerver/lib/upload/s3.py@@ -3,7 +3,7 @@ import osimport secretsfrom collections.abc import Callable, Iteratorfrom datetime import datetime-from typing import IO, TYPE_CHECKING, Any, BinaryIO, Literal+from typing import IO, TYPE_CHECKING, Any, Literalfrom urllib.parse import urljoin, urlsplit, urlunsplitimport botocore@@ -263,7 +263,7 @@ class S3UploadBackend(ZulipUploadBackend):)@override- def save_attachment_contents(self, path_id: str, filehandle: BinaryIO) -> None:+ def save_attachment_contents(self, path_id: str, filehandle: IO[bytes]) -> None:for chunk in self.uploads_bucket.Object(path_id).get()["Body"]:filehandle.write(chunk)