Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typing: Replace `File` with `IO[bytes]`.
PIG20804f5f25478ed
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.pyindex 883f0bf6a9a..de77803f755 100644--- a/zerver/lib/actions.py+++ b/zerver/lib/actions.py@@ -8,6 +8,7 @@ from collections import defaultdictfrom dataclasses import asdict, dataclass, fieldfrom operator import itemgetterfrom typing import (+ IO,AbstractSet,Any,Callable,@@ -28,7 +29,6 @@ import orjsonfrom django.conf import settingsfrom django.contrib.contenttypes.models import ContentTypefrom django.core.exceptions import ValidationError-from django.core.files import Filefrom django.db import IntegrityError, connection, transactionfrom django.db.models import Count, Exists, F, OuterRef, Q, Sumfrom django.db.models.query import QuerySet@@ -7128,7 +7128,7 @@ def notify_realm_emoji(realm: Realm) -> None:def check_add_realm_emoji(- realm: Realm, name: str, author: UserProfile, image_file: File+ realm: Realm, name: str, author: UserProfile, image_file: IO[bytes]) -> Optional[RealmEmoji]:realm_emoji = RealmEmoji(realm=realm, name=name, author=author)realm_emoji.full_clean()diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.pyindex 6816440d7e5..bc11ad5e519 100644--- a/zerver/lib/test_helpers.py+++ b/zerver/lib/test_helpers.py@@ -206,7 +206,7 @@ def reset_emails_in_zulip_realm() -> None:)-def get_test_image_file(filename: str) -> IO[Any]:+def get_test_image_file(filename: str) -> IO[bytes]:test_avatar_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../tests/images"))return open(os.path.join(test_avatar_dir, filename), "rb")diff --git a/zerver/lib/upload.py b/zerver/lib/upload.pyindex 60eba50c754..c004b2aa171 100644--- a/zerver/lib/upload.py+++ b/zerver/lib/upload.py@@ -11,7 +11,7 @@ import unicodedataimport urllibfrom datetime import timedeltafrom mimetypes import guess_extension, guess_type-from typing import Any, Callable, Optional, Tuple+from typing import IO, Any, Callable, Optional, Tupleimport boto3import botocore@@ -214,7 +214,7 @@ class ZulipUploadBackend:def upload_avatar_image(self,- user_file: File,+ user_file: IO[bytes],acting_user_profile: UserProfile,target_user_profile: UserProfile,content_type: Optional[str] = None,@@ -236,14 +236,14 @@ class ZulipUploadBackend:def ensure_avatar_image(self, user_profile: UserProfile, is_medium: bool = False) -> None:raise NotImplementedError()- def upload_realm_icon_image(self, icon_file: File, user_profile: UserProfile) -> None:+ def upload_realm_icon_image(self, icon_file: IO[bytes], user_profile: UserProfile) -> None:raise NotImplementedError()def get_realm_icon_url(self, realm_id: int, version: int) -> str:raise NotImplementedError()def upload_realm_logo_image(- self, logo_file: File, user_profile: UserProfile, night: bool+ self, logo_file: IO[bytes], user_profile: UserProfile, night: bool) -> None:raise NotImplementedError()@@ -251,7 +251,7 @@ class ZulipUploadBackend:raise NotImplementedError()def upload_emoji_image(- self, emoji_file: File, emoji_file_name: str, user_profile: UserProfile+ self, emoji_file: IO[bytes], emoji_file_name: str, user_profile: UserProfile) -> None:raise NotImplementedError()@@ -511,7 +511,7 @@ class S3UploadBackend(ZulipUploadBackend):def upload_avatar_image(self,- user_file: File,+ user_file: IO[bytes],acting_user_profile: UserProfile,target_user_profile: UserProfile,content_type: Optional[str] = None,@@ -558,7 +558,7 @@ class S3UploadBackend(ZulipUploadBackend):def realm_avatar_and_logo_path(self, realm: Realm) -> str:return os.path.join(str(realm.id), "realm")- def upload_realm_icon_image(self, icon_file: File, user_profile: UserProfile) -> None:+ def upload_realm_icon_image(self, icon_file: IO[bytes], user_profile: UserProfile) -> None:content_type = guess_type(icon_file.name)[0]s3_file_name = os.path.join(self.realm_avatar_and_logo_path(user_profile.realm), "icon")@@ -587,7 +587,7 @@ class S3UploadBackend(ZulipUploadBackend):return public_url + f"?version={version}"def upload_realm_logo_image(- self, logo_file: File, user_profile: UserProfile, night: bool+ self, logo_file: IO[bytes], user_profile: UserProfile, night: bool) -> None:content_type = guess_type(logo_file.name)[0]if night:@@ -647,7 +647,7 @@ class S3UploadBackend(ZulipUploadBackend):)def upload_emoji_image(- self, emoji_file: File, emoji_file_name: str, user_profile: UserProfile+ self, emoji_file: IO[bytes], emoji_file_name: str, user_profile: UserProfile) -> None:content_type = guess_type(emoji_file.name)[0]emoji_path = RealmEmoji.PATH_ID_TEMPLATE.format(@@ -804,7 +804,7 @@ class LocalUploadBackend(ZulipUploadBackend):def upload_avatar_image(self,- user_file: File,+ user_file: IO[bytes],acting_user_profile: UserProfile,target_user_profile: UserProfile,content_type: Optional[str] = None,@@ -836,7 +836,7 @@ class LocalUploadBackend(ZulipUploadBackend):def realm_avatar_and_logo_path(self, realm: Realm) -> str:return os.path.join("avatars", str(realm.id), "realm")- def upload_realm_icon_image(self, icon_file: File, user_profile: UserProfile) -> None:+ def upload_realm_icon_image(self, icon_file: IO[bytes], user_profile: UserProfile) -> None:upload_path = self.realm_avatar_and_logo_path(user_profile.realm)image_data = icon_file.read()write_local_file(upload_path, "icon.original", image_data)@@ -849,7 +849,7 @@ class LocalUploadBackend(ZulipUploadBackend):return f"/user_avatars/{realm_id}/realm/icon.png?version={version}"def upload_realm_logo_image(- self, logo_file: File, user_profile: UserProfile, night: bool+ self, logo_file: IO[bytes], user_profile: UserProfile, night: bool) -> None:upload_path = self.realm_avatar_and_logo_path(user_profile.realm)if night:@@ -896,7 +896,7 @@ class LocalUploadBackend(ZulipUploadBackend):write_local_file("avatars", file_path + file_extension, resized_avatar)def upload_emoji_image(- self, emoji_file: File, emoji_file_name: str, user_profile: UserProfile+ self, emoji_file: IO[bytes], emoji_file_name: str, user_profile: UserProfile) -> None:emoji_path = RealmEmoji.PATH_ID_TEMPLATE.format(realm_id=user_profile.realm_id,@@ -961,7 +961,7 @@ def delete_message_image(path_id: str) -> bool:def upload_avatar_image(- user_file: File,+ user_file: IO[bytes],acting_user_profile: UserProfile,target_user_profile: UserProfile,content_type: Optional[str] = None,@@ -979,15 +979,17 @@ def copy_avatar(source_profile: UserProfile, target_profile: UserProfile) -> Nonupload_backend.copy_avatar(source_profile, target_profile)-def upload_icon_image(user_file: File, user_profile: UserProfile) -> None:+def upload_icon_image(user_file: IO[bytes], user_profile: UserProfile) -> None:upload_backend.upload_realm_icon_image(user_file, user_profile)-def upload_logo_image(user_file: File, user_profile: UserProfile, night: bool) -> None:+def upload_logo_image(user_file: IO[bytes], user_profile: UserProfile, night: bool) -> None:upload_backend.upload_realm_logo_image(user_file, user_profile, night)-def upload_emoji_image(emoji_file: File, emoji_file_name: str, user_profile: UserProfile) -> None:+def upload_emoji_image(+ emoji_file: IO[bytes], emoji_file_name: str, user_profile: UserProfile+) -> None:upload_backend.upload_emoji_image(emoji_file, emoji_file_name, user_profile)