|
27 | 27 | import threading |
28 | 28 | from concurrent import futures |
29 | 29 | from typing import ( |
| 30 | + TYPE_CHECKING, |
30 | 31 | Any, |
| 32 | + AsyncIterable, |
| 33 | + AsyncIterator, |
31 | 34 | BinaryIO, |
32 | 35 | Iterable, |
33 | | - TYPE_CHECKING, |
34 | | - NamedTuple, |
35 | | - Literal, |
36 | 36 | Iterator, |
37 | | - AsyncIterable, |
38 | | - AsyncIterator, |
| 37 | + Literal, |
| 38 | + NamedTuple, |
39 | 39 | ) |
40 | 40 |
|
41 | 41 | import httpx |
42 | 42 |
|
| 43 | +from pywa.types.others import InteractiveType |
| 44 | + |
43 | 45 | from .types import ( |
44 | | - FlowMetricName, |
45 | | - FlowMetricGranularity, |
46 | | - FlowJSON, |
| 46 | + Button, |
| 47 | + ButtonUrl, |
47 | 48 | CallbackData, |
| 49 | + CallPermissionRequestButton, |
| 50 | + FlowButton, |
| 51 | + FlowJSON, |
| 52 | + FlowMetricGranularity, |
| 53 | + FlowMetricName, |
| 54 | + SectionList, |
48 | 55 | URLButton, |
49 | 56 | VoiceCallButton, |
50 | | - SectionList, |
51 | | - FlowButton, |
52 | | - Button, |
53 | | - CallPermissionRequestButton, |
54 | | - ButtonUrl, |
55 | 57 | ) |
56 | | -from pywa.types.others import InteractiveType |
57 | 58 | from .types.media import Media |
58 | 59 | from .types.templates import ( |
| 60 | + BaseParams, |
| 61 | + Carousel, |
| 62 | + HeaderFormatType, |
59 | 63 | TemplateBaseComponent, |
60 | 64 | _BaseMediaHeaderComponent, |
61 | | - HeaderFormatType, |
62 | | - Carousel, |
63 | 65 | _BaseMediaParams, |
64 | | - BaseParams, |
65 | 66 | ) |
66 | 67 |
|
67 | 68 | if TYPE_CHECKING: |
@@ -382,12 +383,13 @@ def get_media_from_file_like_obj( |
382 | 383 | try: |
383 | 384 | length = os.fstat(file_obj.fileno()).st_size |
384 | 385 | except (AttributeError, OSError): |
385 | | - pos = file_obj.tell() |
386 | | - file_obj.seek(0, io.SEEK_END) |
387 | | - length = file_obj.tell() |
388 | | - file_obj.seek(pos) |
389 | | - except (AttributeError, OSError): |
390 | | - length = None |
| 386 | + try: |
| 387 | + pos = file_obj.tell() |
| 388 | + file_obj.seek(0, io.SEEK_END) |
| 389 | + length = file_obj.tell() |
| 390 | + file_obj.seek(pos) |
| 391 | + except (AttributeError, OSError): |
| 392 | + length = None |
391 | 393 | filename = getattr(file_obj, "name", None) |
392 | 394 | return MediaInfo( |
393 | 395 | content=file_obj, |
@@ -458,6 +460,7 @@ def internal_upload_media( |
458 | 460 | media_type: str | None, |
459 | 461 | mime_type: str | None, |
460 | 462 | filename: str | None, |
| 463 | + ttl_minutes: int | None = None, |
461 | 464 | download_chunk_size: int | None, |
462 | 465 | wa: WhatsApp, |
463 | 466 | phone_id: str, |
@@ -526,9 +529,11 @@ def internal_upload_media( |
526 | 529 | or media_info.mime_type |
527 | 530 | or _media_types_default_mime_types.get(media_type, "text/plain"), |
528 | 531 | filename=final_filename, |
| 532 | + ttl_minutes=ttl_minutes, |
529 | 533 | )["id"], |
530 | 534 | uploaded_to=phone_id, |
531 | 535 | filename=final_filename, |
| 536 | + ttl_minutes=ttl_minutes, |
532 | 537 | ) |
533 | 538 |
|
534 | 539 | finally: |
|
0 commit comments