botapi-py 1.4.10__tar.gz → 1.4.12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: botapi-py
3
- Version: 1.4.10
3
+ Version: 1.4.12
4
4
  Summary: A simple and flexible Python library to conveniently build fast Telegram bots using the Bot API.
5
5
  Requires-Dist: httpx>=0.28.1
6
6
  Requires-Dist: pydantic>=2.12.0
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "botapi-py"
3
- version = "1.4.10"
3
+ version = "1.4.12"
4
4
  description = "A simple and flexible Python library to conveniently build fast Telegram bots using the Bot API."
5
5
  # readme = "README.md"
6
6
  # authors = [
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- from typing import Optional, Union, List, cast, overload
3
+ from typing import Optional, Union, List, cast
4
4
 
5
5
  from . import enums
6
6
  from . import types
@@ -243,51 +243,3 @@ class BotShortcuts:
243
243
  case _:
244
244
  raise ValueError(f'Unknown media type: {file_type}')
245
245
 
246
- @overload
247
- async def download_file(
248
- self,
249
- file: types.File,
250
- destination_path: str
251
- ) -> None: ...
252
-
253
- @overload
254
- async def download_file(
255
- self,
256
- file: types.File,
257
- destination_path: None = None
258
- ) -> bytes: ...
259
-
260
- async def download_file(
261
- self,
262
- file: types.File,
263
- destination_path: Optional[str] = None
264
- ) -> bytes | None:
265
- '''
266
- Convenience method to download a file from Telegram servers.
267
-
268
- Call this method with a `File` object obtained via `get_file`.
269
-
270
- :param file: File object to download.
271
- :param destination_path: Optional path to save the downloaded file. If not provided, the file content will be returned as bytes.
272
- :return: The file content as bytes if destination_path is not provided, otherwise None.
273
- '''
274
- self = cast(methods.Bot, self)
275
-
276
- file_path = file.file_path
277
- if not file_path:
278
- raise ValueError('The file does not have a valid file_path to download.')
279
-
280
- # https://api.telegram.org/file/bot<token>/<file_path>
281
- # https://api.telegram.org/file/bot<token>/test/<file_path>
282
- url = self._compose_api_file_url(file_path=file_path) # pyright: ignore[reportPrivateUsage]
283
-
284
- response = await self.session.get(url)
285
- content = response.content
286
-
287
- if destination_path:
288
- with open(destination_path, 'wb') as f:
289
- f.write(content)
290
- return None
291
-
292
- return content
293
-
@@ -5,7 +5,7 @@
5
5
  from __future__ import annotations
6
6
 
7
7
  from pydantic import BaseModel, Field, TypeAdapter
8
- from typing import TYPE_CHECKING, Union, Optional, Literal, List, Any
8
+ from typing import TYPE_CHECKING, Union, Optional, Literal, List, Any, overload
9
9
 
10
10
  from . import enums
11
11
 
@@ -3200,7 +3200,51 @@ class File(BaseModel, frozen=True):
3200
3200
  file_id: str
3201
3201
  file_unique_id: str
3202
3202
  file_size: Optional[int] = Field(default=None)
3203
- file_path: Optional[str] = Field(default=None)
3203
+ file_path: Optional[str] = Field(default=None)
3204
+
3205
+ @overload
3206
+ async def download(
3207
+ self,
3208
+ bot: methods.Bot,
3209
+ destination_path: str
3210
+ ) -> None: ...
3211
+
3212
+ @overload
3213
+ async def download(
3214
+ self,
3215
+ bot: methods.Bot,
3216
+ destination_path: None = None
3217
+ ) -> bytes: ...
3218
+
3219
+ async def download(
3220
+ self,
3221
+ bot: methods.Bot,
3222
+ destination_path: Optional[str] = None
3223
+ ) -> bytes | None:
3224
+ '''
3225
+ Convenience method to download a file from Telegram servers.
3226
+
3227
+ :param destination_path: Optional path to save the downloaded file. If not provided, the file content will be returned as bytes.
3228
+ :return: The file content as bytes if destination_path is not provided, otherwise None.
3229
+ '''
3230
+ file_path = self.file_path
3231
+ if not file_path:
3232
+ raise ValueError('The file does not have a valid file_path to download.')
3233
+
3234
+ # https://api.telegram.org/file/bot<token>/<file_path>
3235
+ # https://api.telegram.org/file/bot<token>/test/<file_path>
3236
+ url = bot._compose_api_file_url(file_path=file_path) # pyright: ignore[reportPrivateUsage]
3237
+
3238
+ response = await bot.session.get(url)
3239
+ content = response.content
3240
+
3241
+ if destination_path:
3242
+ with open(destination_path, 'wb') as f:
3243
+ f.write(content)
3244
+ return None
3245
+
3246
+ return content
3247
+
3204
3248
 
3205
3249
  class WebAppInfo(BaseModel, frozen=True):
3206
3250
  '''