upload: Switch from BinaryIO to IO[bytes].

This is slightly more generally-compatible.
This commit is contained in:
Alex Vandiver 2024-09-19 20:48:03 +00:00 committed by Tim Abbott
parent 638c579c56
commit 2dc737335e
4 changed files with 8 additions and 8 deletions

View File

@ -5,7 +5,7 @@ import re
import unicodedata
from collections.abc import Callable, Iterator
from datetime import datetime
from typing import IO, Any, BinaryIO
from typing import IO, Any
from urllib.parse import unquote, urljoin
import 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)

View File

@ -2,7 +2,7 @@ import os
from collections.abc import Callable, Iterator
from dataclasses import dataclass
from datetime import datetime
from typing import IO, Any, BinaryIO
from typing import IO, Any
import 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 NotImplementedError
def attachment_vips_source(self, path_id: str) -> StreamingSourceWithSize:

View File

@ -5,7 +5,7 @@ import secrets
import shutil
from collections.abc import Callable, Iterator
from datetime import datetime
from typing import IO, Any, BinaryIO, Literal
from typing import IO, Any, Literal
import pyvips
from 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))
@override

View File

@ -3,7 +3,7 @@ import os
import secrets
from collections.abc import Callable, Iterator
from datetime import datetime
from typing import IO, TYPE_CHECKING, Any, BinaryIO, Literal
from typing import IO, TYPE_CHECKING, Any, Literal
from urllib.parse import urljoin, urlsplit, urlunsplit
import 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)