@@ -42,6 +42,20 @@ class Media:
4242 LEASE_API_PATH : ClassVar [str ]
4343 LEASE_RESPONSE_KEY : ClassVar [str ] = "s3UploadLease"
4444
45+ @staticmethod
46+ async def _raise_upload_error (response : ClientResponse , / ) -> None :
47+ raise ServerError (response )
48+
49+ @property
50+ def _mime_type (self ) -> str :
51+ if self ._mime_type_value is None :
52+ mime_type , _ = guess_file_type (self .name )
53+ if mime_type is None :
54+ msg = f"Unable to determine the MIME type of { self .name !r} ."
55+ raise ClientException (msg )
56+ self ._mime_type_value = mime_type
57+ return self ._mime_type_value
58+
4559 def __eq__ (self , other : object ) -> bool :
4660 """Return whether the other instance equals the current."""
4761 return type (other ) is type (self ) and self .name == other .name and self ._fp == other ._fp
@@ -77,15 +91,8 @@ def __repr__(self) -> str:
7791 """Return a string representation of the instance."""
7892 return f"<{ self .__class__ .__name__ } name={ self .name !r} >"
7993
80- @property
81- def _mime_type (self ) -> str :
82- if self ._mime_type_value is None :
83- mime_type , _ = guess_file_type (self .name )
84- if mime_type is None :
85- msg = f"Unable to determine the MIME type of { self .name !r} ."
86- raise ClientException (msg )
87- self ._mime_type_value = mime_type
88- return self ._mime_type_value
94+ def _build_lease_data (self , ** additional_data : str ) -> dict [str , str ]:
95+ return {"filepath" : self .name , "mimetype" : self ._mime_type , ** additional_data }
8996
9097 async def _build_payload (self ) -> BytesIO :
9198 """Read the media content and wrap it in a named file-like object."""
@@ -98,9 +105,6 @@ async def _build_payload(self) -> BytesIO:
98105 payload .name = self .name
99106 return payload
100107
101- def _build_lease_data (self , ** additional_data : str ) -> dict [str , str ]:
102- return {"filepath" : self .name , "mimetype" : self ._mime_type , ** additional_data }
103-
104108 async def _lease_and_post (
105109 self , lease_url : str , reddit : asyncpraw .Reddit , / , ** additional_lease_data : str
106110 ) -> tuple [dict [str , Any ], dict [str , str ], str ]:
@@ -125,10 +129,6 @@ async def _post_to_s3(self, reddit: asyncpraw.Reddit, upload_data: dict[str, str
125129 if not response .ok :
126130 await self ._raise_upload_error (response )
127131
128- @staticmethod
129- async def _raise_upload_error (response : ClientResponse , / ) -> None :
130- raise ServerError (response )
131-
132132 async def _upload (self , subreddit : models .Subreddit , / , ** additional_lease_data : str ) -> str :
133133 """Upload the media to Reddit.
134134
@@ -194,7 +194,12 @@ async def _raise_upload_error(response: ClientResponse, /) -> None:
194194 await Media ._raise_upload_error (response )
195195
196196 async def _upload ( # pyright: ignore[reportIncompatibleMethodOverride] # post media is uploaded with a Reddit instance rather than a Subreddit
197- self , reddit : asyncpraw .Reddit , / , * , expected_mime_prefix : str | None = None , upload_type : str = "link"
197+ self ,
198+ reddit : asyncpraw .Reddit ,
199+ / ,
200+ * ,
201+ expected_mime_prefix : str | None = None ,
202+ upload_type : str = "link" ,
198203 ) -> str :
199204 """Upload the media to Reddit (undocumented endpoint).
200205
0 commit comments