mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2026-06-19 07:35:19 +00:00
WIP: Flesh out the implementation a little more
Some tests are still failing
This commit is contained in:
@@ -522,12 +522,3 @@ class ChatBackground(TelegramObject):
|
||||
|
||||
self._id_attrs = (self.type,)
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ChatBackground":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["type"] = de_json_optional(data.get("type"), BackgroundType, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -623,52 +623,3 @@ class ChatFullInfo(_ChatBase):
|
||||
return get_timedelta_value(
|
||||
self._message_auto_delete_time, attribute="message_auto_delete_time"
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ChatFullInfo":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["emoji_status_expiration_date"] = from_timestamp(
|
||||
data.get("emoji_status_expiration_date"), tzinfo=loc_tzinfo
|
||||
)
|
||||
|
||||
data["photo"] = de_json_optional(data.get("photo"), ChatPhoto, bot)
|
||||
data["accepted_gift_types"] = de_json_optional(
|
||||
data.get("accepted_gift_types"), AcceptedGiftTypes, bot
|
||||
)
|
||||
|
||||
from telegram import ( # pylint: disable=import-outside-toplevel # noqa: PLC0415
|
||||
BusinessIntro,
|
||||
BusinessLocation,
|
||||
BusinessOpeningHours,
|
||||
Message,
|
||||
)
|
||||
|
||||
data["pinned_message"] = de_json_optional(data.get("pinned_message"), Message, bot)
|
||||
data["permissions"] = de_json_optional(data.get("permissions"), ChatPermissions, bot)
|
||||
data["location"] = de_json_optional(data.get("location"), ChatLocation, bot)
|
||||
data["available_reactions"] = de_list_optional(
|
||||
data.get("available_reactions"), ReactionType, bot
|
||||
)
|
||||
data["birthdate"] = de_json_optional(data.get("birthdate"), Birthdate, bot)
|
||||
data["personal_chat"] = de_json_optional(data.get("personal_chat"), Chat, bot)
|
||||
data["business_intro"] = de_json_optional(data.get("business_intro"), BusinessIntro, bot)
|
||||
data["business_location"] = de_json_optional(
|
||||
data.get("business_location"), BusinessLocation, bot
|
||||
)
|
||||
data["business_opening_hours"] = de_json_optional(
|
||||
data.get("business_opening_hours"), BusinessOpeningHours, bot
|
||||
)
|
||||
data["parent_chat"] = de_json_optional(data.get("parent_chat"), Chat, bot)
|
||||
|
||||
data["rating"] = de_json_optional(data.get("rating"), UserRating, bot)
|
||||
data["unique_gift_colors"] = de_json_optional(
|
||||
data.get("unique_gift_colors"), UniqueGiftColors, bot
|
||||
)
|
||||
data["first_profile_audio"] = de_json_optional(data.get("first_profile_audio"), Audio, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -24,11 +24,7 @@ from typing import TYPE_CHECKING
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional, to_timedelta
|
||||
from telegram._utils.datetime import (
|
||||
extract_tzinfo_from_defaults,
|
||||
from_timestamp,
|
||||
get_timedelta_value,
|
||||
)
|
||||
from telegram._utils.datetime import get_timedelta_value
|
||||
from telegram._utils.types import JSONDict, TimePeriod
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -191,16 +187,3 @@ class ChatInviteLink(TelegramObject):
|
||||
@property
|
||||
def subscription_period(self) -> int | dtm.timedelta | None:
|
||||
return get_timedelta_value(self._subscription_period, attribute="subscription_period")
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ChatInviteLink":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["creator"] = de_json_optional(data.get("creator"), User, bot)
|
||||
data["expire_date"] = from_timestamp(data.get("expire_date", None), tzinfo=loc_tzinfo)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -23,7 +23,6 @@ from typing import TYPE_CHECKING, Final
|
||||
from telegram import constants
|
||||
from telegram._files.location import Location
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -68,15 +67,6 @@ class ChatLocation(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ChatLocation":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["location"] = de_json_optional(data.get("location"), Location, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
MIN_ADDRESS: Final[int] = constants.LocationLimit.MIN_CHAT_LOCATION_ADDRESS
|
||||
""":const:`telegram.constants.LocationLimit.MIN_CHAT_LOCATION_ADDRESS`
|
||||
|
||||
|
||||
@@ -142,23 +142,6 @@ class ChatMemberUpdated(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ChatMemberUpdated":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["chat"] = de_json_optional(data.get("chat"), Chat, bot)
|
||||
data["from_user"] = de_json_optional(data.pop("from", None), User, bot)
|
||||
data["date"] = from_timestamp(data.get("date"), tzinfo=loc_tzinfo)
|
||||
data["old_chat_member"] = de_json_optional(data.get("old_chat_member"), ChatMember, bot)
|
||||
data["new_chat_member"] = de_json_optional(data.get("new_chat_member"), ChatMember, bot)
|
||||
data["invite_link"] = de_json_optional(data.get("invite_link"), ChatInviteLink, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
def _get_attribute_difference(self, attribute: str) -> tuple[object, object]:
|
||||
try:
|
||||
old = self.old_chat_member[attribute]
|
||||
|
||||
@@ -22,7 +22,6 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -60,15 +59,6 @@ class ChatOwnerChanged(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ChatOwnerChanged":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["new_owner"] = de_json_optional(data.get("new_owner"), User, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class ChatOwnerLeft(TelegramObject):
|
||||
"""This object represents a service message about the chat owner leaving the chat.
|
||||
@@ -102,12 +92,3 @@ class ChatOwnerLeft(TelegramObject):
|
||||
self._id_attrs = (self.new_owner,)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ChatOwnerLeft":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["new_owner"] = de_json_optional(data.get("new_owner"), User, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -166,6 +166,12 @@ class ChatPermissions(TelegramObject):
|
||||
"can_send_voice_notes",
|
||||
)
|
||||
|
||||
__REMOVED_API_FIELDS__ = frozenset(
|
||||
{
|
||||
"can_send_media_messages",
|
||||
}
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
can_send_messages: bool | None = None,
|
||||
@@ -245,16 +251,3 @@ class ChatPermissions(TelegramObject):
|
||||
.. versionadded:: 20.0
|
||||
"""
|
||||
return cls(*(False,) * len(cls.__slots__))
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ChatPermissions":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
api_kwargs = {}
|
||||
# This is a deprecated field that TG still returns for backwards compatibility
|
||||
# Let's filter it out to speed up the de-json process
|
||||
if data.get("can_send_media_messages") is not None:
|
||||
api_kwargs["can_send_media_messages"] = data.pop("can_send_media_messages")
|
||||
|
||||
return super()._de_json(data=data, bot=bot, api_kwargs=api_kwargs)
|
||||
|
||||
@@ -26,14 +26,12 @@ from telegram._chat import Chat
|
||||
from telegram._messageentity import MessageEntity
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional, de_list_optional, parse_sequence_arg
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.entities import parse_message_entities, parse_message_entity
|
||||
from telegram._utils.types import JSONDict
|
||||
from telegram.constants import ZERO_DATE
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot, Message
|
||||
from telegram import Message
|
||||
|
||||
|
||||
class ChecklistTask(TelegramObject):
|
||||
@@ -112,25 +110,6 @@ class ChecklistTask(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "ChecklistTask":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
if (date := data.get("completion_date")) == 0:
|
||||
data["completion_date"] = ZERO_DATE
|
||||
else:
|
||||
data["completion_date"] = from_timestamp(date, tzinfo=loc_tzinfo)
|
||||
|
||||
data["completed_by_user"] = de_json_optional(data.get("completed_by_user"), User, bot)
|
||||
data["completed_by_chat"] = de_json_optional(data.get("completed_by_chat"), Chat, bot)
|
||||
data["text_entities"] = de_list_optional(data.get("text_entities"), MessageEntity, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
def parse_entity(self, entity: MessageEntity) -> str:
|
||||
"""Returns the text in :attr:`text`
|
||||
from a given :class:`telegram.MessageEntity` of :attr:`text_entities`.
|
||||
@@ -231,16 +210,6 @@ class Checklist(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "Checklist":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["title_entities"] = de_list_optional(data.get("title_entities"), MessageEntity, bot)
|
||||
data["tasks"] = de_list_optional(data.get("tasks"), ChecklistTask, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
def parse_entity(self, entity: MessageEntity) -> str:
|
||||
"""Returns the text in :attr:`title`
|
||||
from a given :class:`telegram.MessageEntity` of :attr:`title_entities`.
|
||||
@@ -321,7 +290,7 @@ class ChecklistTasksDone(TelegramObject):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
checklist_message: Optional["Message"] = None,
|
||||
checklist_message: "Message | None" = None,
|
||||
marked_as_done_task_ids: Sequence[int] | None = None,
|
||||
marked_as_not_done_task_ids: Sequence[int] | None = None,
|
||||
*,
|
||||
@@ -338,18 +307,6 @@ class ChecklistTasksDone(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "ChecklistTasksDone":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# needs to be imported here to avoid circular import issues
|
||||
from telegram import Message # pylint: disable=import-outside-toplevel # noqa: PLC0415
|
||||
|
||||
data["checklist_message"] = de_json_optional(data.get("checklist_message"), Message, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class ChecklistTasksAdded(TelegramObject):
|
||||
"""
|
||||
@@ -380,7 +337,7 @@ class ChecklistTasksAdded(TelegramObject):
|
||||
def __init__(
|
||||
self,
|
||||
tasks: Sequence[ChecklistTask],
|
||||
checklist_message: Optional["Message"] = None,
|
||||
checklist_message: "Message | None" = None,
|
||||
*,
|
||||
api_kwargs: JSONDict | None = None,
|
||||
):
|
||||
@@ -391,16 +348,3 @@ class ChecklistTasksAdded(TelegramObject):
|
||||
self._id_attrs = (self.tasks,)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "ChecklistTasksAdded":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# needs to be imported here to avoid circular import issues
|
||||
from telegram import Message # pylint: disable=import-outside-toplevel # noqa: PLC0415
|
||||
|
||||
data["checklist_message"] = de_json_optional(data.get("checklist_message"), Message, bot)
|
||||
data["tasks"] = ChecklistTask.de_list(data.get("tasks", []), bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -24,7 +24,6 @@ from typing import TYPE_CHECKING
|
||||
from telegram._files.location import Location
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -91,15 +90,3 @@ class ChosenInlineResult(TelegramObject):
|
||||
self._id_attrs = (self.result_id,)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ChosenInlineResult":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Required
|
||||
data["from_user"] = de_json_optional(data.pop("from", None), User, bot)
|
||||
# Optionals
|
||||
data["location"] = de_json_optional(data.get("location"), Location, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -22,7 +22,6 @@ from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -75,12 +74,3 @@ class DirectMessagesTopic(TelegramObject):
|
||||
|
||||
self._id_attrs = (self.topic_id, self.user)
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "DirectMessagesTopic":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["user"] = de_json_optional(data.get("user"), User, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -48,7 +48,6 @@ class _BaseMedium(TelegramObject):
|
||||
Can't be used to download or reuse the file.
|
||||
file_size (:obj:`int`): Optional. File size.
|
||||
|
||||
|
||||
"""
|
||||
|
||||
__slots__ = ("file_id", "file_size", "file_unique_id")
|
||||
|
||||
@@ -18,16 +18,12 @@
|
||||
# along with this program. If not, see [http://www.gnu.org/licenses/].
|
||||
"""Common base class for media objects with thumbnails"""
|
||||
|
||||
from typing import TYPE_CHECKING, TypeVar
|
||||
from typing import TypeVar
|
||||
|
||||
from telegram._files._basemedium import _BaseMedium
|
||||
from telegram._files.photosize import PhotoSize
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
ThumbedMT_co = TypeVar("ThumbedMT_co", bound="_BaseThumbedMedium", covariant=True)
|
||||
|
||||
@@ -63,6 +59,11 @@ class _BaseThumbedMedium(_BaseMedium):
|
||||
"""
|
||||
|
||||
__slots__ = ("thumbnail",)
|
||||
__REMOVED_API_FIELDS__ = frozenset(
|
||||
{
|
||||
"thumb",
|
||||
}
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -81,20 +82,3 @@ class _BaseThumbedMedium(_BaseMedium):
|
||||
)
|
||||
|
||||
self.thumbnail: PhotoSize | None = thumbnail
|
||||
|
||||
@classmethod
|
||||
def de_json(cls: type[ThumbedMT_co], data: JSONDict, bot: "Bot | None" = None) -> ThumbedMT_co:
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# In case this wasn't already done by the subclass
|
||||
if not isinstance(data.get("thumbnail"), PhotoSize):
|
||||
data["thumbnail"] = de_json_optional(data.get("thumbnail"), PhotoSize, bot)
|
||||
|
||||
api_kwargs = {}
|
||||
# This is a deprecated field that TG still returns for backwards compatibility
|
||||
# Let's filter it out to speed up the de-json process
|
||||
if data.get("thumb") is not None:
|
||||
api_kwargs["thumb"] = data.pop("thumb")
|
||||
|
||||
return super()._de_json(data=data, bot=bot, api_kwargs=api_kwargs)
|
||||
|
||||
@@ -144,6 +144,11 @@ class Sticker(_BaseThumbedMedium):
|
||||
"type",
|
||||
"width",
|
||||
)
|
||||
__REMOVED_API_FIELDS__ = frozenset(
|
||||
{
|
||||
"thumb",
|
||||
}
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -194,23 +199,6 @@ class Sticker(_BaseThumbedMedium):
|
||||
CUSTOM_EMOJI: Final[str] = constants.StickerType.CUSTOM_EMOJI
|
||||
""":const:`telegram.constants.StickerType.CUSTOM_EMOJI`"""
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "Sticker":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["thumbnail"] = de_json_optional(data.get("thumbnail"), PhotoSize, bot)
|
||||
data["mask_position"] = de_json_optional(data.get("mask_position"), MaskPosition, bot)
|
||||
data["premium_animation"] = de_json_optional(data.get("premium_animation"), File, bot)
|
||||
|
||||
api_kwargs = {}
|
||||
# This is a deprecated field that TG still returns for backwards compatibility
|
||||
# Let's filter it out to speed up the de-json process
|
||||
if data.get("thumb") is not None:
|
||||
api_kwargs["thumb"] = data.pop("thumb")
|
||||
|
||||
return super()._de_json(data=data, bot=bot, api_kwargs=api_kwargs)
|
||||
|
||||
|
||||
class StickerSet(TelegramObject):
|
||||
"""This object represents a sticker set.
|
||||
@@ -281,6 +269,7 @@ class StickerSet(TelegramObject):
|
||||
"thumbnail",
|
||||
"title",
|
||||
)
|
||||
__REMOVED_API_FIELDS__ = frozenset({"contains_masks", "is_animated", "is_video", "thumb"})
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -303,23 +292,6 @@ class StickerSet(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "StickerSet":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["thumbnail"] = de_json_optional(data.get("thumbnail"), PhotoSize, bot)
|
||||
data["stickers"] = de_list_optional(data.get("stickers"), Sticker, bot)
|
||||
|
||||
api_kwargs = {}
|
||||
# These are deprecated fields that TG still returns for backwards compatibility
|
||||
# Let's filter them out to speed up the de-json process
|
||||
for deprecated_field in ("contains_masks", "thumb", "is_animated", "is_video"):
|
||||
if deprecated_field in data:
|
||||
api_kwargs[deprecated_field] = data.pop(deprecated_field)
|
||||
|
||||
return super()._de_json(data=data, bot=bot, api_kwargs=api_kwargs)
|
||||
|
||||
|
||||
class MaskPosition(TelegramObject):
|
||||
"""This object describes the position on faces where a mask should be placed by default.
|
||||
|
||||
@@ -22,7 +22,6 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from telegram._files.location import Location
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -102,12 +101,3 @@ class Venue(TelegramObject):
|
||||
self._id_attrs = (self.location, self.title)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "Venue":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["location"] = de_json_optional(data.get("location"), Location, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -29,9 +29,6 @@ from telegram._utils.argumentparsing import de_list_optional, parse_sequence_arg
|
||||
from telegram._utils.datetime import get_timedelta_value
|
||||
from telegram._utils.types import JSONDict, TimePeriod
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot
|
||||
|
||||
|
||||
class Video(_BaseThumbedMedium):
|
||||
"""This object represents a video file.
|
||||
@@ -167,13 +164,3 @@ class Video(_BaseThumbedMedium):
|
||||
@property
|
||||
def start_timestamp(self) -> dtm.timedelta | None | int:
|
||||
return get_timedelta_value(self._start_timestamp, attribute="start_timestamp")
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "Video":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["cover"] = de_list_optional(data.get("cover"), PhotoSize, bot)
|
||||
data["qualities"] = de_list_optional(data.get("qualities"), VideoQuality, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -124,17 +124,6 @@ class Game(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "Game":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["photo"] = de_list_optional(data.get("photo"), PhotoSize, bot)
|
||||
data["text_entities"] = de_list_optional(data.get("text_entities"), MessageEntity, bot)
|
||||
data["animation"] = de_json_optional(data.get("animation"), Animation, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
def parse_text_entity(self, entity: MessageEntity) -> str:
|
||||
"""Returns the text from a given :class:`telegram.MessageEntity`.
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -60,12 +59,3 @@ class GameHighScore(TelegramObject):
|
||||
self._id_attrs = (self.position, self.user, self.score)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "GameHighScore":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["user"] = de_json_optional(data.get("user"), User, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -228,16 +228,6 @@ class Gift(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "Gift":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["sticker"] = de_json_optional(data.get("sticker"), Sticker, bot)
|
||||
data["publisher_chat"] = de_json_optional(data.get("publisher_chat"), Chat, bot)
|
||||
data["background"] = de_json_optional(data.get("background"), GiftBackground, bot)
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class Gifts(TelegramObject):
|
||||
"""This object represent a list of gifts.
|
||||
@@ -270,14 +260,6 @@ class Gifts(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "Gifts":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["gifts"] = de_list_optional(data.get("gifts"), Gift, bot)
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class GiftInfo(TelegramObject):
|
||||
"""Describes a service message about a regular gift that was sent or received.
|
||||
@@ -385,16 +367,6 @@ class GiftInfo(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "GiftInfo":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["gift"] = de_json_optional(data.get("gift"), Gift, bot)
|
||||
data["entities"] = de_list_optional(data.get("entities"), MessageEntity, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
def parse_entity(self, entity: MessageEntity) -> str:
|
||||
"""Returns the text in :attr:`text`
|
||||
from a given :class:`telegram.MessageEntity` of :attr:`entities`.
|
||||
|
||||
@@ -25,12 +25,11 @@ from typing import TYPE_CHECKING
|
||||
from telegram._chat import Chat
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional, de_list_optional, parse_sequence_arg
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from telegram import Bot, Message
|
||||
from telegram import Message
|
||||
|
||||
|
||||
class Giveaway(TelegramObject):
|
||||
@@ -137,21 +136,6 @@ class Giveaway(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "Giveaway":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["chats"] = de_list_optional(data.get("chats"), Chat, bot)
|
||||
data["winners_selection_date"] = from_timestamp(
|
||||
data.get("winners_selection_date"), tzinfo=loc_tzinfo
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class GiveawayCreated(TelegramObject):
|
||||
"""This object represents a service message about the creation of a scheduled giveaway.
|
||||
@@ -292,22 +276,6 @@ class GiveawayWinners(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "GiveawayWinners":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["chat"] = de_json_optional(data.get("chat"), Chat, bot)
|
||||
data["winners"] = de_list_optional(data.get("winners"), User, bot)
|
||||
data["winners_selection_date"] = from_timestamp(
|
||||
data.get("winners_selection_date"), tzinfo=loc_tzinfo
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class GiveawayCompleted(TelegramObject):
|
||||
"""This object represents a service message about the completion of a giveaway without public
|
||||
@@ -363,17 +331,3 @@ class GiveawayCompleted(TelegramObject):
|
||||
)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "GiveawayCompleted":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Unfortunately, this needs to be here due to cyclic imports
|
||||
from telegram._message import ( # pylint: disable=import-outside-toplevel # noqa: PLC0415
|
||||
Message,
|
||||
)
|
||||
|
||||
data["giveaway_message"] = de_json_optional(data.get("giveaway_message"), Message, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -26,7 +26,6 @@ from telegram._games.callbackgame import CallbackGame
|
||||
from telegram._loginurl import LoginUrl
|
||||
from telegram._switchinlinequerychosenchat import SwitchInlineQueryChosenChat
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
from telegram._webappinfo import WebAppInfo
|
||||
|
||||
@@ -344,21 +343,6 @@ class InlineKeyboardButton(TelegramObject):
|
||||
self.icon_custom_emoji_id,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "InlineKeyboardButton":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["login_url"] = de_json_optional(data.get("login_url"), LoginUrl, bot)
|
||||
data["web_app"] = de_json_optional(data.get("web_app"), WebAppInfo, bot)
|
||||
data["callback_game"] = de_json_optional(data.get("callback_game"), CallbackGame, bot)
|
||||
data["switch_inline_query_chosen_chat"] = de_json_optional(
|
||||
data.get("switch_inline_query_chosen_chat"), SwitchInlineQueryChosenChat, bot
|
||||
)
|
||||
data["copy_text"] = de_json_optional(data.get("copy_text"), CopyTextButton, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
def update_callback_data(self, callback_data: str | object) -> None:
|
||||
"""
|
||||
Sets :attr:`callback_data` to the passed object. Intended to be used by
|
||||
|
||||
@@ -91,6 +91,7 @@ class InlineKeyboardMarkup(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
# TODO: Come back to this and modify TGObject to parse nested Sequence's
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "InlineKeyboardMarkup":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
|
||||
@@ -27,7 +27,6 @@ from telegram._files.location import Location
|
||||
from telegram._inline.inlinequeryresultsbutton import InlineQueryResultsButton
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput, TimePeriod
|
||||
|
||||
@@ -132,16 +131,6 @@ class InlineQuery(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "InlineQuery":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["from_user"] = de_json_optional(data.pop("from", None), User, bot)
|
||||
data["location"] = de_json_optional(data.get("location"), Location, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
async def answer(
|
||||
self,
|
||||
results: (
|
||||
|
||||
@@ -22,7 +22,6 @@ from typing import TYPE_CHECKING, Final
|
||||
|
||||
from telegram import constants
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
from telegram._webappinfo import WebAppInfo
|
||||
|
||||
@@ -98,14 +97,6 @@ class InlineQueryResultsButton(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "InlineQueryResultsButton":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
|
||||
data["web_app"] = de_json_optional(data.get("web_app"), WebAppInfo, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
MIN_START_PARAMETER_LENGTH: Final[int] = (
|
||||
constants.InlineQueryResultsButtonLimit.MIN_START_PARAMETER_LENGTH
|
||||
)
|
||||
|
||||
@@ -254,12 +254,3 @@ class InputInvoiceMessageContent(InputMessageContent):
|
||||
self.currency,
|
||||
self.prices,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "InputInvoiceMessageContent":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["prices"] = de_list_optional(data.get("prices"), LabeledPrice, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -22,7 +22,6 @@ import datetime as dtm
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -66,14 +65,3 @@ class PreparedInlineMessage(TelegramObject):
|
||||
self._id_attrs = (self.id,)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "PreparedInlineMessage":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
data["expiration_date"] = from_timestamp(data.get("expiration_date"), tzinfo=loc_tzinfo)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -181,6 +181,12 @@ class KeyboardButton(TelegramObject):
|
||||
"web_app",
|
||||
)
|
||||
|
||||
__REMOVED_API_FIELDS__ = frozenset(
|
||||
{
|
||||
"request_user",
|
||||
}
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
text: str,
|
||||
@@ -222,27 +228,3 @@ class KeyboardButton(TelegramObject):
|
||||
)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "KeyboardButton":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["request_poll"] = de_json_optional(
|
||||
data.get("request_poll"), KeyboardButtonPollType, bot
|
||||
)
|
||||
data["request_users"] = de_json_optional(
|
||||
data.get("request_users"), KeyboardButtonRequestUsers, bot
|
||||
)
|
||||
data["request_chat"] = de_json_optional(
|
||||
data.get("request_chat"), KeyboardButtonRequestChat, bot
|
||||
)
|
||||
data["web_app"] = de_json_optional(data.get("web_app"), WebAppInfo, bot)
|
||||
|
||||
api_kwargs = {}
|
||||
# This is a deprecated field that TG still returns for backwards compatibility
|
||||
# Let's filter it out to speed up the de-json process
|
||||
if request_user := data.get("request_user"):
|
||||
api_kwargs = {"request_user": request_user}
|
||||
|
||||
return super()._de_json(data=data, bot=bot, api_kwargs=api_kwargs)
|
||||
|
||||
@@ -254,17 +254,3 @@ class KeyboardButtonRequestChat(TelegramObject):
|
||||
self._id_attrs = (self.request_id,)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "KeyboardButtonRequestChat":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["user_administrator_rights"] = de_json_optional(
|
||||
data.get("user_administrator_rights"), ChatAdministratorRights, bot
|
||||
)
|
||||
data["bot_administrator_rights"] = de_json_optional(
|
||||
data.get("bot_administrator_rights"), ChatAdministratorRights, bot
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -23,7 +23,6 @@ from typing import TYPE_CHECKING, Final
|
||||
from telegram import constants
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
from telegram._webappinfo import WebAppInfo
|
||||
|
||||
@@ -165,15 +164,6 @@ class MenuButtonWebApp(MenuButton):
|
||||
|
||||
self._id_attrs = (self.type, self.text, self.web_app)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "MenuButtonWebApp":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["web_app"] = de_json_optional(data.get("web_app"), WebAppInfo, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot) # type: ignore[return-value]
|
||||
|
||||
|
||||
class MenuButtonDefault(MenuButton):
|
||||
"""Describes that no specific value for the menu button was set.
|
||||
|
||||
@@ -28,8 +28,6 @@ from telegram import constants
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.strings import TextEncoding
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
@@ -183,19 +181,6 @@ class MessageEntity(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "MessageEntity":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["user"] = de_json_optional(data.get("user"), User, bot)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
data["unix_time"] = from_timestamp(data.get("unix_time"), tzinfo=loc_tzinfo)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@staticmethod
|
||||
def adjust_message_entities_to_utf_16(text: str, entities: _SEM) -> _SEM:
|
||||
"""Utility functionality for converting the offset and length of entities from
|
||||
|
||||
@@ -27,7 +27,6 @@ from telegram._reaction import ReactionCount, ReactionType
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional, de_list_optional, parse_sequence_arg
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -86,20 +85,6 @@ class MessageReactionCountUpdated(TelegramObject):
|
||||
self._id_attrs = (self.chat, self.message_id, self.date, self.reactions)
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "MessageReactionCountUpdated":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["date"] = from_timestamp(data.get("date"), tzinfo=loc_tzinfo)
|
||||
data["chat"] = de_json_optional(data.get("chat"), Chat, bot)
|
||||
data["reactions"] = de_list_optional(data.get("reactions"), ReactionCount, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class MessageReactionUpdated(TelegramObject):
|
||||
"""This class represents a change of a reaction on a message performed by a user.
|
||||
@@ -181,20 +166,3 @@ class MessageReactionUpdated(TelegramObject):
|
||||
self.new_reaction,
|
||||
)
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "MessageReactionUpdated":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["date"] = from_timestamp(data.get("date"), tzinfo=loc_tzinfo)
|
||||
data["chat"] = de_json_optional(data.get("chat"), Chat, bot)
|
||||
data["old_reaction"] = de_list_optional(data.get("old_reaction"), ReactionType, bot)
|
||||
data["new_reaction"] = de_list_optional(data.get("new_reaction"), ReactionType, bot)
|
||||
data["user"] = de_json_optional(data.get("user"), User, bot)
|
||||
data["actor_chat"] = de_json_optional(data.get("actor_chat"), Chat, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -30,7 +30,6 @@ from telegram._uniquegift import UniqueGift
|
||||
from telegram._user import User
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import de_json_optional, de_list_optional, parse_sequence_arg
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.entities import parse_message_entities, parse_message_entity
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
@@ -286,19 +285,6 @@ class OwnedGiftRegular(OwnedGift):
|
||||
|
||||
self._id_attrs = (self.type, self.gift, self.send_date)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "OwnedGiftRegular":
|
||||
"""See :meth:`telegram.OwnedGift.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
data["send_date"] = from_timestamp(data.get("send_date"), tzinfo=loc_tzinfo)
|
||||
data["sender_user"] = de_json_optional(data.get("sender_user"), User, bot)
|
||||
data["gift"] = de_json_optional(data.get("gift"), Gift, bot)
|
||||
data["entities"] = de_list_optional(data.get("entities"), MessageEntity, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot) # type: ignore[return-value]
|
||||
|
||||
def parse_entity(self, entity: MessageEntity) -> str:
|
||||
"""Returns the text in :attr:`text`
|
||||
from a given :class:`telegram.MessageEntity` of :attr:`entities`.
|
||||
@@ -438,18 +424,3 @@ class OwnedGiftUnique(OwnedGift):
|
||||
self.next_transfer_date: dtm.datetime | None = next_transfer_date
|
||||
|
||||
self._id_attrs = (self.type, self.gift, self.send_date)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "OwnedGiftUnique":
|
||||
"""See :meth:`telegram.OwnedGift.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
data["send_date"] = from_timestamp(data.get("send_date"), tzinfo=loc_tzinfo)
|
||||
data["sender_user"] = de_json_optional(data.get("sender_user"), User, bot)
|
||||
data["gift"] = de_json_optional(data.get("gift"), UniqueGift, bot)
|
||||
data["next_transfer_date"] = from_timestamp(
|
||||
data.get("next_transfer_date"), tzinfo=loc_tzinfo
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot) # type: ignore[return-value]
|
||||
|
||||
@@ -29,8 +29,6 @@ from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import (
|
||||
de_json_optional,
|
||||
de_list_optional,
|
||||
parse_sequence_arg,
|
||||
to_timedelta,
|
||||
)
|
||||
@@ -202,13 +200,6 @@ class PaidMediaPhoto(PaidMedia):
|
||||
|
||||
self._id_attrs = (self.type, self.photo)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "PaidMediaPhoto":
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["photo"] = de_list_optional(data.get("photo"), PhotoSize, bot)
|
||||
return super().de_json(data=data, bot=bot) # type: ignore[return-value]
|
||||
|
||||
|
||||
class PaidMediaVideo(PaidMedia):
|
||||
"""
|
||||
@@ -243,13 +234,6 @@ class PaidMediaVideo(PaidMedia):
|
||||
|
||||
self._id_attrs = (self.type, self.video)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "PaidMediaVideo":
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["video"] = de_json_optional(data.get("video"), Video, bot)
|
||||
return super().de_json(data=data, bot=bot) # type: ignore[return-value]
|
||||
|
||||
|
||||
class PaidMediaInfo(TelegramObject):
|
||||
"""
|
||||
@@ -287,13 +271,6 @@ class PaidMediaInfo(TelegramObject):
|
||||
self._id_attrs = (self.star_count, self.paid_media)
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "PaidMediaInfo":
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["paid_media"] = de_list_optional(data.get("paid_media"), PaidMedia, bot)
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class PaidMediaPurchased(TelegramObject):
|
||||
"""This object contains information about a paid media purchase.
|
||||
@@ -330,10 +307,3 @@ class PaidMediaPurchased(TelegramObject):
|
||||
|
||||
self._id_attrs = (self.from_user, self.paid_media_payload)
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "PaidMediaPurchased":
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["from_user"] = User.de_json(data=data.pop("from"), bot=bot)
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -233,15 +233,6 @@ class Credentials(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "Credentials":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["secure_data"] = de_json_optional(data.get("secure_data"), SecureData, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class SecureData(TelegramObject):
|
||||
"""
|
||||
@@ -340,31 +331,6 @@ class SecureData(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "SecureData":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["temporary_registration"] = de_json_optional(
|
||||
data.get("temporary_registration"), SecureValue, bot
|
||||
)
|
||||
data["passport_registration"] = de_json_optional(
|
||||
data.get("passport_registration"), SecureValue, bot
|
||||
)
|
||||
data["rental_agreement"] = de_json_optional(data.get("rental_agreement"), SecureValue, bot)
|
||||
data["bank_statement"] = de_json_optional(data.get("bank_statement"), SecureValue, bot)
|
||||
data["utility_bill"] = de_json_optional(data.get("utility_bill"), SecureValue, bot)
|
||||
data["address"] = de_json_optional(data.get("address"), SecureValue, bot)
|
||||
data["identity_card"] = de_json_optional(data.get("identity_card"), SecureValue, bot)
|
||||
data["driver_license"] = de_json_optional(data.get("driver_license"), SecureValue, bot)
|
||||
data["internal_passport"] = de_json_optional(
|
||||
data.get("internal_passport"), SecureValue, bot
|
||||
)
|
||||
data["passport"] = de_json_optional(data.get("passport"), SecureValue, bot)
|
||||
data["personal_details"] = de_json_optional(data.get("personal_details"), SecureValue, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class SecureValue(TelegramObject):
|
||||
"""
|
||||
@@ -445,20 +411,6 @@ class SecureValue(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "SecureValue":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["data"] = de_json_optional(data.get("data"), DataCredentials, bot)
|
||||
data["front_side"] = de_json_optional(data.get("front_side"), FileCredentials, bot)
|
||||
data["reverse_side"] = de_json_optional(data.get("reverse_side"), FileCredentials, bot)
|
||||
data["selfie"] = de_json_optional(data.get("selfie"), FileCredentials, bot)
|
||||
data["files"] = de_list_optional(data.get("files"), FileCredentials, bot)
|
||||
data["translation"] = de_list_optional(data.get("translation"), FileCredentials, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class _CredentialsBase(TelegramObject):
|
||||
"""Base class for DataCredentials and FileCredentials."""
|
||||
|
||||
@@ -27,9 +27,7 @@ from telegram._passport.passportfile import PassportFile
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import (
|
||||
de_json_decrypted_optional,
|
||||
de_json_optional,
|
||||
de_list_decrypted_optional,
|
||||
de_list_optional,
|
||||
parse_sequence_arg,
|
||||
)
|
||||
from telegram._utils.types import JSONDict
|
||||
@@ -195,19 +193,6 @@ class EncryptedPassportElement(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "EncryptedPassportElement":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["files"] = de_list_optional(data.get("files"), PassportFile, bot) or None
|
||||
data["front_side"] = de_json_optional(data.get("front_side"), PassportFile, bot)
|
||||
data["reverse_side"] = de_json_optional(data.get("reverse_side"), PassportFile, bot)
|
||||
data["selfie"] = de_json_optional(data.get("selfie"), PassportFile, bot)
|
||||
data["translation"] = de_list_optional(data.get("translation"), PassportFile, bot) or None
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@classmethod
|
||||
def de_json_decrypted(
|
||||
cls, data: JSONDict, bot: "Bot | None", credentials: "Credentials"
|
||||
|
||||
@@ -82,16 +82,6 @@ class PassportData(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "PassportData":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["data"] = de_list_optional(data.get("data"), EncryptedPassportElement, bot)
|
||||
data["credentials"] = de_json_optional(data.get("credentials"), EncryptedCredentials, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@property
|
||||
def decrypted_data(self) -> tuple[EncryptedPassportElement, ...]:
|
||||
"""
|
||||
|
||||
@@ -22,7 +22,6 @@ import datetime as dtm
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput
|
||||
|
||||
@@ -98,17 +97,6 @@ class PassportFile(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "PassportFile":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
data["file_date"] = from_timestamp(data.get("file_date"), tzinfo=loc_tzinfo)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@classmethod
|
||||
def de_json_decrypted(
|
||||
cls, data: JSONDict, bot: "Bot | None", credentials: "FileCredentials"
|
||||
|
||||
@@ -22,7 +22,6 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from telegram._payment.shippingaddress import ShippingAddress
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -70,14 +69,3 @@ class OrderInfo(TelegramObject):
|
||||
self._id_attrs = (self.name, self.phone_number, self.email, self.shipping_address)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "OrderInfo":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["shipping_address"] = de_json_optional(
|
||||
data.get("shipping_address"), ShippingAddress, bot
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -23,7 +23,6 @@ from typing import TYPE_CHECKING
|
||||
from telegram._payment.orderinfo import OrderInfo
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput
|
||||
|
||||
@@ -110,16 +109,6 @@ class PreCheckoutQuery(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "PreCheckoutQuery":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["from_user"] = de_json_optional(data.pop("from", None), User, bot)
|
||||
data["order_info"] = de_json_optional(data.get("order_info"), OrderInfo, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
async def answer(
|
||||
self,
|
||||
ok: bool,
|
||||
|
||||
@@ -24,7 +24,6 @@ from typing import TYPE_CHECKING
|
||||
from telegram._payment.shippingaddress import ShippingAddress
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.types import JSONDict, ODVInput
|
||||
|
||||
@@ -78,18 +77,6 @@ class ShippingQuery(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ShippingQuery":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["from_user"] = de_json_optional(data.pop("from", None), User, bot)
|
||||
data["shipping_address"] = de_json_optional(
|
||||
data.get("shipping_address"), ShippingAddress, bot
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
async def answer(
|
||||
self,
|
||||
ok: bool,
|
||||
|
||||
@@ -23,7 +23,6 @@ from typing import TYPE_CHECKING
|
||||
from telegram._chat import Chat
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -105,13 +104,3 @@ class AffiliateInfo(TelegramObject):
|
||||
self.nanostar_amount,
|
||||
)
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "AffiliateInfo":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["affiliate_user"] = de_json_optional(data.get("affiliate_user"), User, bot)
|
||||
data["affiliate_chat"] = de_json_optional(data.get("affiliate_chat"), Chat, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -25,7 +25,6 @@ from typing import TYPE_CHECKING, Final
|
||||
from telegram import constants
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -150,19 +149,6 @@ class RevenueWithdrawalStateSucceeded(RevenueWithdrawalState):
|
||||
self.date,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def de_json(
|
||||
cls, data: JSONDict, bot: "Bot | None" = None
|
||||
) -> "RevenueWithdrawalStateSucceeded":
|
||||
"""See :meth:`telegram.RevenueWithdrawalState.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
data["date"] = from_timestamp(data.get("date", None), tzinfo=loc_tzinfo)
|
||||
|
||||
return super().de_json(data=data, bot=bot) # type: ignore[return-value]
|
||||
|
||||
|
||||
class RevenueWithdrawalStateFailed(RevenueWithdrawalState):
|
||||
"""The withdrawal failed and the transaction was refunded.
|
||||
|
||||
@@ -25,7 +25,6 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_optional, de_list_optional, parse_sequence_arg
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
from .transactionpartner import TransactionPartner
|
||||
@@ -114,20 +113,6 @@ class StarTransaction(TelegramObject):
|
||||
)
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "StarTransaction":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
data["date"] = from_timestamp(data.get("date", None), tzinfo=loc_tzinfo)
|
||||
|
||||
data["source"] = de_json_optional(data.get("source"), TransactionPartner, bot)
|
||||
data["receiver"] = de_json_optional(data.get("receiver"), TransactionPartner, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class StarTransactions(TelegramObject):
|
||||
"""
|
||||
@@ -155,11 +140,3 @@ class StarTransactions(TelegramObject):
|
||||
|
||||
self._id_attrs = (self.transactions,)
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "StarTransactions":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["transactions"] = de_list_optional(data.get("transactions"), StarTransaction, bot)
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -30,10 +30,10 @@ from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import (
|
||||
de_json_optional,
|
||||
de_list_optional,
|
||||
parse_sequence_arg,
|
||||
to_timedelta,
|
||||
de_json_optional,
|
||||
de_list_optional,
|
||||
)
|
||||
from telegram._utils.types import JSONDict, TimePeriod
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from telegram._payment.orderinfo import OrderInfo
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -140,19 +138,3 @@ class SuccessfulPayment(TelegramObject):
|
||||
self._id_attrs = (self.telegram_payment_charge_id, self.provider_payment_charge_id)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "SuccessfulPayment":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["order_info"] = de_json_optional(data.get("order_info"), OrderInfo, bot)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["subscription_expiration_date"] = from_timestamp(
|
||||
data.get("subscription_expiration_date"), tzinfo=loc_tzinfo
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
+1
-53
@@ -29,16 +29,11 @@ from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import (
|
||||
de_json_optional,
|
||||
de_list_optional,
|
||||
parse_sequence_arg,
|
||||
to_timedelta,
|
||||
)
|
||||
from telegram._utils.datetime import (
|
||||
extract_tzinfo_from_defaults,
|
||||
from_timestamp,
|
||||
get_timedelta_value,
|
||||
)
|
||||
from telegram._utils.datetime import get_timedelta_value
|
||||
from telegram._utils.defaultvalue import DEFAULT_NONE
|
||||
from telegram._utils.entities import parse_message_entities, parse_message_entity
|
||||
from telegram._utils.types import JSONDict, ODVInput, TimePeriod
|
||||
@@ -100,15 +95,6 @@ class InputPollOption(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "InputPollOption":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["text_entities"] = de_list_optional(data.get("text_entities"), MessageEntity, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class PollOption(TelegramObject):
|
||||
"""
|
||||
@@ -161,15 +147,6 @@ class PollOption(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "PollOption":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["text_entities"] = de_list_optional(data.get("text_entities"), MessageEntity, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
def parse_entity(self, entity: MessageEntity) -> str:
|
||||
"""Returns the text in :attr:`text`
|
||||
from a given :class:`telegram.MessageEntity` of :attr:`text_entities`.
|
||||
@@ -305,16 +282,6 @@ class PollAnswer(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "PollAnswer":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["user"] = de_json_optional(data.get("user"), User, bot)
|
||||
data["voter_chat"] = de_json_optional(data.get("voter_chat"), Chat, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class Poll(TelegramObject):
|
||||
"""
|
||||
@@ -478,25 +445,6 @@ class Poll(TelegramObject):
|
||||
def open_period(self) -> int | dtm.timedelta | None:
|
||||
return get_timedelta_value(self._open_period, attribute="open_period")
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "Poll":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["options"] = de_list_optional(data.get("options"), PollOption, bot)
|
||||
data["explanation_entities"] = de_list_optional(
|
||||
data.get("explanation_entities"), MessageEntity, bot
|
||||
)
|
||||
data["close_date"] = from_timestamp(data.get("close_date"), tzinfo=loc_tzinfo)
|
||||
data["question_entities"] = de_list_optional(
|
||||
data.get("question_entities"), MessageEntity, bot
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
def parse_explanation_entity(self, entity: MessageEntity) -> str:
|
||||
"""Returns the text in :attr:`explanation` from a given :class:`telegram.MessageEntity` of
|
||||
:attr:`explanation_entities`.
|
||||
|
||||
@@ -22,7 +22,6 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -67,13 +66,3 @@ class ProximityAlertTriggered(TelegramObject):
|
||||
self._id_attrs = (self.traveler, self.watcher, self.distance)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ProximityAlertTriggered":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["traveler"] = de_json_optional(data.get("traveler"), User, bot)
|
||||
data["watcher"] = de_json_optional(data.get("watcher"), User, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -24,7 +24,6 @@ from typing import TYPE_CHECKING, Final, Literal
|
||||
from telegram import constants
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -220,12 +219,3 @@ class ReactionCount(TelegramObject):
|
||||
self.total_count,
|
||||
)
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ReactionCount":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["type"] = de_json_optional(data.get("type"), ReactionType, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -258,41 +258,6 @@ class ExternalReplyInfo(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ExternalReplyInfo":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["origin"] = de_json_optional(data.get("origin"), MessageOrigin, bot)
|
||||
data["chat"] = de_json_optional(data.get("chat"), Chat, bot)
|
||||
data["link_preview_options"] = de_json_optional(
|
||||
data.get("link_preview_options"), LinkPreviewOptions, bot
|
||||
)
|
||||
data["animation"] = de_json_optional(data.get("animation"), Animation, bot)
|
||||
data["audio"] = de_json_optional(data.get("audio"), Audio, bot)
|
||||
data["document"] = de_json_optional(data.get("document"), Document, bot)
|
||||
data["photo"] = de_list_optional(data.get("photo"), PhotoSize, bot)
|
||||
data["sticker"] = de_json_optional(data.get("sticker"), Sticker, bot)
|
||||
data["story"] = de_json_optional(data.get("story"), Story, bot)
|
||||
data["video"] = de_json_optional(data.get("video"), Video, bot)
|
||||
data["video_note"] = de_json_optional(data.get("video_note"), VideoNote, bot)
|
||||
data["voice"] = de_json_optional(data.get("voice"), Voice, bot)
|
||||
data["contact"] = de_json_optional(data.get("contact"), Contact, bot)
|
||||
data["dice"] = de_json_optional(data.get("dice"), Dice, bot)
|
||||
data["game"] = de_json_optional(data.get("game"), Game, bot)
|
||||
data["giveaway"] = de_json_optional(data.get("giveaway"), Giveaway, bot)
|
||||
data["giveaway_winners"] = de_json_optional(
|
||||
data.get("giveaway_winners"), GiveawayWinners, bot
|
||||
)
|
||||
data["invoice"] = de_json_optional(data.get("invoice"), Invoice, bot)
|
||||
data["location"] = de_json_optional(data.get("location"), Location, bot)
|
||||
data["poll"] = de_json_optional(data.get("poll"), Poll, bot)
|
||||
data["venue"] = de_json_optional(data.get("venue"), Venue, bot)
|
||||
data["paid_media"] = de_json_optional(data.get("paid_media"), PaidMediaInfo, bot)
|
||||
data["checklist"] = de_json_optional(data.get("checklist"), Checklist, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class TextQuote(TelegramObject):
|
||||
"""
|
||||
@@ -358,15 +323,6 @@ class TextQuote(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "TextQuote":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["entities"] = de_list_optional(data.get("entities"), MessageEntity, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class ReplyParameters(TelegramObject):
|
||||
"""
|
||||
@@ -477,14 +433,3 @@ class ReplyParameters(TelegramObject):
|
||||
self._id_attrs = (self.message_id,)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ReplyParameters":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["quote_entities"] = tuple(
|
||||
de_list_optional(data.get("quote_entities"), MessageEntity, bot)
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
+6
-31
@@ -70,6 +70,12 @@ class UsersShared(TelegramObject):
|
||||
|
||||
__slots__ = ("request_id", "users")
|
||||
|
||||
__REMOVED_API_FIELDS__ = frozenset(
|
||||
{
|
||||
"user_ids",
|
||||
}
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
request_id: int,
|
||||
@@ -85,21 +91,6 @@ class UsersShared(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "UsersShared":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["users"] = de_list_optional(data.get("users"), SharedUser, bot)
|
||||
|
||||
api_kwargs = {}
|
||||
# This is a deprecated field that TG still returns for backwards compatibility
|
||||
# Let's filter it out to speed up the de-json process
|
||||
if user_ids := data.get("user_ids"):
|
||||
api_kwargs = {"user_ids": user_ids}
|
||||
|
||||
return super()._de_json(data=data, bot=bot, api_kwargs=api_kwargs)
|
||||
|
||||
|
||||
class ChatShared(TelegramObject):
|
||||
"""
|
||||
@@ -171,14 +162,6 @@ class ChatShared(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ChatShared":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["photo"] = de_list_optional(data.get("photo"), PhotoSize, bot)
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@property
|
||||
def link(self) -> str | None:
|
||||
""":obj:`str`: Convenience property. If :attr:`username` is available, returns a t.me link
|
||||
@@ -281,11 +264,3 @@ class SharedUser(TelegramObject):
|
||||
.. versionadded:: 22.4
|
||||
"""
|
||||
return get_link(self)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "SharedUser":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["photo"] = de_list_optional(data.get("photo"), PhotoSize, bot)
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -71,14 +71,6 @@ class Story(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "Story":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["chat"] = Chat.de_json(data.get("chat", {}), bot)
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
async def repost(
|
||||
self,
|
||||
business_connection_id: str,
|
||||
|
||||
@@ -26,8 +26,6 @@ from telegram._message import Message
|
||||
from telegram._payment.stars.staramount import StarAmount
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -141,20 +139,6 @@ class SuggestedPostParameters(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "SuggestedPostParameters":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["price"] = de_json_optional(data.get("price"), SuggestedPostPrice, bot)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["send_date"] = from_timestamp(data.get("send_date"), tzinfo=loc_tzinfo)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class SuggestedPostInfo(TelegramObject):
|
||||
"""
|
||||
@@ -223,19 +207,6 @@ class SuggestedPostInfo(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "SuggestedPostInfo":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["price"] = de_json_optional(data.get("price"), SuggestedPostPrice, bot)
|
||||
data["send_date"] = from_timestamp(data.get("send_date"), tzinfo=loc_tzinfo)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class SuggestedPostDeclined(TelegramObject):
|
||||
"""
|
||||
@@ -281,17 +252,6 @@ class SuggestedPostDeclined(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "SuggestedPostDeclined":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["suggested_post_message"] = de_json_optional(
|
||||
data.get("suggested_post_message"), Message, bot
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class SuggestedPostPaid(TelegramObject):
|
||||
"""
|
||||
@@ -363,18 +323,6 @@ class SuggestedPostPaid(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "SuggestedPostPaid":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["suggested_post_message"] = de_json_optional(
|
||||
data.get("suggested_post_message"), Message, bot
|
||||
)
|
||||
data["star_amount"] = de_json_optional(data.get("star_amount"), StarAmount, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class SuggestedPostRefunded(TelegramObject):
|
||||
"""
|
||||
@@ -430,17 +378,6 @@ class SuggestedPostRefunded(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "SuggestedPostRefunded":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["suggested_post_message"] = de_json_optional(
|
||||
data.get("suggested_post_message"), Message, bot
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class SuggestedPostApproved(TelegramObject):
|
||||
"""
|
||||
@@ -496,22 +433,6 @@ class SuggestedPostApproved(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "SuggestedPostApproved":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["send_date"] = from_timestamp(data.get("send_date"), tzinfo=loc_tzinfo)
|
||||
data["price"] = de_json_optional(data.get("price"), SuggestedPostPrice, bot)
|
||||
data["suggested_post_message"] = de_json_optional(
|
||||
data.get("suggested_post_message"), Message, bot
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class SuggestedPostApprovalFailed(TelegramObject):
|
||||
"""
|
||||
@@ -559,15 +480,3 @@ class SuggestedPostApprovalFailed(TelegramObject):
|
||||
self._id_attrs = (self.price, self.suggested_post_message)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: Optional["Bot"] = None) -> "SuggestedPostApprovalFailed":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["price"] = de_json_optional(data.get("price"), SuggestedPostPrice, bot)
|
||||
data["suggested_post_message"] = de_json_optional(
|
||||
data.get("suggested_post_message"), Message, bot
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -435,7 +435,7 @@ class TelegramObject:
|
||||
"""
|
||||
init_fn = cls.__dict__.get("__init__")
|
||||
if init_fn is None:
|
||||
# No own __init__: inherit the nearest ancestor's plan. This is true for e.g. _ChatBase
|
||||
# No own __init__: inherit the nearest ancestor's plan. This is true for e.g. Chat
|
||||
parent = cls.__mro__[1]
|
||||
print("No __init__ for", cls.__name__, "inheriting from", parent.__name__)
|
||||
if "__DE_JSON_PLAN__" not in parent.__dict__:
|
||||
@@ -468,21 +468,25 @@ class TelegramObject:
|
||||
else from_timestamp(value, tzinfo=extract_tzinfo_from_defaults(bot))
|
||||
)
|
||||
elif isinstance(inner, type) and issubclass(inner, TelegramObject):
|
||||
print("Adding de_json plan for", cls.__name__, name, "→", inner.__name__)
|
||||
plan[name] = lambda v, b, _c=inner: _c.de_json(v, b) if isinstance(v, dict) else v
|
||||
elif origin is Sequence:
|
||||
args = get_args(inner)
|
||||
# args: tuple[object, ...] = getattr(inner, "__args__", ())
|
||||
if not args:
|
||||
continue
|
||||
item_type: object = args[0]
|
||||
# if isinstance(item_type, str):
|
||||
# print(f"Resolving forward reference for {cls.__name__}.{name}: {item_type}")
|
||||
# with contextlib.suppress(Exception):
|
||||
# item_type = eval(item_type, globalns, tg_ns) # noqa: S307
|
||||
# inspect.signature doesn't resolve the forward ref inside Sequence for some reason
|
||||
if isinstance(item_type, str):
|
||||
print(f"Resolving forward reference for {cls.__name__}.{name}: {item_type}")
|
||||
# with contextlib.suppress(Exception):
|
||||
item_type = eval(item_type, globalns, tg_ns) # noqa: S307
|
||||
if isinstance(item_type, type) and issubclass(item_type, TelegramObject):
|
||||
print("Adding de_list plan for", cls.__name__, name, "→", item_type.__name__)
|
||||
plan[name] = lambda v, b, _c=item_type: (
|
||||
_c.de_list(v, b) if isinstance(v, list) else v
|
||||
)
|
||||
else:
|
||||
print(f"No de_json plan for {cls.__name__}.{name} (annotation: {ann})")
|
||||
|
||||
cls.__DE_JSON_PLAN__ = plan
|
||||
return plan
|
||||
|
||||
@@ -29,7 +29,6 @@ from telegram._files.sticker import Sticker
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils import enum
|
||||
from telegram._utils.argumentparsing import de_json_optional, parse_sequence_arg
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -173,15 +172,6 @@ class UniqueGiftModel(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "UniqueGiftModel":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["sticker"] = de_json_optional(data.get("sticker"), Sticker, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class UniqueGiftSymbol(TelegramObject):
|
||||
"""This object describes the symbol shown on the pattern of a unique gift.
|
||||
@@ -228,15 +218,6 @@ class UniqueGiftSymbol(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "UniqueGiftSymbol":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["sticker"] = de_json_optional(data.get("sticker"), Sticker, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class UniqueGiftBackdropColors(TelegramObject):
|
||||
"""This object describes the colors of the backdrop of a unique gift.
|
||||
@@ -333,15 +314,6 @@ class UniqueGiftBackdrop(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "UniqueGiftBackdrop":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["colors"] = de_json_optional(data.get("colors"), UniqueGiftBackdropColors, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class UniqueGift(TelegramObject):
|
||||
"""This object describes a unique gift that was upgraded from a regular gift.
|
||||
@@ -483,19 +455,6 @@ class UniqueGift(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "UniqueGift":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["model"] = de_json_optional(data.get("model"), UniqueGiftModel, bot)
|
||||
data["symbol"] = de_json_optional(data.get("symbol"), UniqueGiftSymbol, bot)
|
||||
data["backdrop"] = de_json_optional(data.get("backdrop"), UniqueGiftBackdrop, bot)
|
||||
data["publisher_chat"] = de_json_optional(data.get("publisher_chat"), Chat, bot)
|
||||
data["colors"] = de_json_optional(data.get("colors"), UniqueGiftColors, bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class UniqueGiftInfo(TelegramObject):
|
||||
"""Describes a service message about a unique gift that was sent or received.
|
||||
@@ -627,16 +586,3 @@ class UniqueGiftInfo(TelegramObject):
|
||||
self._id_attrs = (self.gift, self.origin)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "UniqueGiftInfo":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
data["gift"] = de_json_optional(data.get("gift"), UniqueGift, bot)
|
||||
data["next_transfer_date"] = from_timestamp(
|
||||
data.get("next_transfer_date"), tzinfo=loc_tzinfo
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -35,7 +35,6 @@ from telegram._payment.precheckoutquery import PreCheckoutQuery
|
||||
from telegram._payment.shippingquery import ShippingQuery
|
||||
from telegram._poll import Poll, PollAnswer
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import de_json_optional
|
||||
from telegram._utils.types import JSONDict
|
||||
from telegram._utils.warnings import warn
|
||||
|
||||
@@ -754,58 +753,3 @@ class Update(TelegramObject):
|
||||
|
||||
self._effective_message = message
|
||||
return message
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "Update":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["message"] = de_json_optional(data.get("message"), Message, bot)
|
||||
data["edited_message"] = de_json_optional(data.get("edited_message"), Message, bot)
|
||||
data["inline_query"] = de_json_optional(data.get("inline_query"), InlineQuery, bot)
|
||||
data["chosen_inline_result"] = de_json_optional(
|
||||
data.get("chosen_inline_result"), ChosenInlineResult, bot
|
||||
)
|
||||
data["callback_query"] = de_json_optional(data.get("callback_query"), CallbackQuery, bot)
|
||||
data["shipping_query"] = de_json_optional(data.get("shipping_query"), ShippingQuery, bot)
|
||||
data["pre_checkout_query"] = de_json_optional(
|
||||
data.get("pre_checkout_query"), PreCheckoutQuery, bot
|
||||
)
|
||||
data["channel_post"] = de_json_optional(data.get("channel_post"), Message, bot)
|
||||
data["edited_channel_post"] = de_json_optional(
|
||||
data.get("edited_channel_post"), Message, bot
|
||||
)
|
||||
data["poll"] = de_json_optional(data.get("poll"), Poll, bot)
|
||||
data["poll_answer"] = de_json_optional(data.get("poll_answer"), PollAnswer, bot)
|
||||
data["my_chat_member"] = de_json_optional(
|
||||
data.get("my_chat_member"), ChatMemberUpdated, bot
|
||||
)
|
||||
data["chat_member"] = de_json_optional(data.get("chat_member"), ChatMemberUpdated, bot)
|
||||
data["chat_join_request"] = de_json_optional(
|
||||
data.get("chat_join_request"), ChatJoinRequest, bot
|
||||
)
|
||||
data["chat_boost"] = de_json_optional(data.get("chat_boost"), ChatBoostUpdated, bot)
|
||||
data["removed_chat_boost"] = de_json_optional(
|
||||
data.get("removed_chat_boost"), ChatBoostRemoved, bot
|
||||
)
|
||||
data["message_reaction"] = de_json_optional(
|
||||
data.get("message_reaction"), MessageReactionUpdated, bot
|
||||
)
|
||||
data["message_reaction_count"] = de_json_optional(
|
||||
data.get("message_reaction_count"), MessageReactionCountUpdated, bot
|
||||
)
|
||||
data["business_connection"] = de_json_optional(
|
||||
data.get("business_connection"), BusinessConnection, bot
|
||||
)
|
||||
data["business_message"] = de_json_optional(data.get("business_message"), Message, bot)
|
||||
data["edited_business_message"] = de_json_optional(
|
||||
data.get("edited_business_message"), Message, bot
|
||||
)
|
||||
data["deleted_business_messages"] = de_json_optional(
|
||||
data.get("deleted_business_messages"), BusinessMessagesDeleted, bot
|
||||
)
|
||||
data["purchased_paid_media"] = de_json_optional(
|
||||
data.get("purchased_paid_media"), PaidMediaPurchased, bot
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -65,12 +65,3 @@ class UserProfileAudios(TelegramObject):
|
||||
self._id_attrs = (self.total_count, self.audios)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "UserProfileAudios":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["audios"] = Audio.de_list(data.get("audios", []), bot)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -70,12 +70,3 @@ class UserProfilePhotos(TelegramObject):
|
||||
self._id_attrs = (self.total_count, self.photos)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "UserProfilePhotos":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["photos"] = [PhotoSize.de_list(photo, bot) for photo in data["photos"]]
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -25,11 +25,7 @@ from typing import TYPE_CHECKING
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._user import User
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg, to_timedelta
|
||||
from telegram._utils.datetime import (
|
||||
extract_tzinfo_from_defaults,
|
||||
from_timestamp,
|
||||
get_timedelta_value,
|
||||
)
|
||||
from telegram._utils.datetime import get_timedelta_value
|
||||
from telegram._utils.types import JSONDict, TimePeriod
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -146,14 +142,6 @@ class VideoChatParticipantsInvited(TelegramObject):
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "VideoChatParticipantsInvited":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
data["users"] = User.de_list(data.get("users", []), bot)
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
|
||||
class VideoChatScheduled(TelegramObject):
|
||||
"""This object represents a service message about a video chat scheduled in the chat.
|
||||
@@ -193,15 +181,3 @@ class VideoChatScheduled(TelegramObject):
|
||||
self._id_attrs = (self.start_date,)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "VideoChatScheduled":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["start_date"] = from_timestamp(data.get("start_date"), tzinfo=loc_tzinfo)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -24,7 +24,6 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from telegram._telegramobject import TelegramObject
|
||||
from telegram._utils.argumentparsing import parse_sequence_arg
|
||||
from telegram._utils.datetime import extract_tzinfo_from_defaults, from_timestamp
|
||||
from telegram._utils.types import JSONDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -162,18 +161,3 @@ class WebhookInfo(TelegramObject):
|
||||
)
|
||||
|
||||
self._freeze()
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "WebhookInfo":
|
||||
"""See :meth:`telegram.TelegramObject.de_json`."""
|
||||
data = cls._parse_data(data)
|
||||
|
||||
# Get the local timezone from the bot if it has defaults
|
||||
loc_tzinfo = extract_tzinfo_from_defaults(bot)
|
||||
|
||||
data["last_error_date"] = from_timestamp(data.get("last_error_date"), tzinfo=loc_tzinfo)
|
||||
data["last_synchronization_error_date"] = from_timestamp(
|
||||
data.get("last_synchronization_error_date"), tzinfo=loc_tzinfo
|
||||
)
|
||||
|
||||
return super().de_json(data=data, bot=bot)
|
||||
|
||||
@@ -69,11 +69,35 @@ class StickerTestBase:
|
||||
type = Sticker.REGULAR
|
||||
custom_emoji_id = "ThisIsSuchACustomEmojiID"
|
||||
needs_repainting = True
|
||||
mask_position = MaskPosition(point="forehead", x_shift=0.1, y_shift=-0.1, scale=1.0)
|
||||
thumbnail = PhotoSize(
|
||||
file_id="1",
|
||||
file_unique_id="1",
|
||||
width=thumb_width,
|
||||
height=thumb_height,
|
||||
file_size=thumb_file_size,
|
||||
)
|
||||
|
||||
sticker_file_id = "5a3128a4d2a04750b5b58397f3b5e812"
|
||||
sticker_file_unique_id = "adc3145fd2e84d95b64d68eaa22aa33e"
|
||||
|
||||
premium_animation = File("this_is_an_id", "this_is_an_unique_id")
|
||||
sticker = Sticker(
|
||||
file_id=sticker_file_id,
|
||||
file_unique_id=sticker_file_unique_id,
|
||||
width=width,
|
||||
height=height,
|
||||
is_animated=is_animated,
|
||||
is_video=is_video,
|
||||
type=type,
|
||||
emoji=emoji,
|
||||
file_size=file_size,
|
||||
mask_position=mask_position,
|
||||
premium_animation=premium_animation,
|
||||
custom_emoji_id=custom_emoji_id,
|
||||
thumbnail=thumbnail,
|
||||
needs_repainting=needs_repainting,
|
||||
)
|
||||
|
||||
|
||||
class TestStickerWithoutRequest(StickerTestBase):
|
||||
@@ -125,22 +149,8 @@ class TestStickerWithoutRequest(StickerTestBase):
|
||||
assert sticker_dict["type"] == sticker.type
|
||||
assert sticker_dict["needs_repainting"] == sticker.needs_repainting
|
||||
|
||||
def test_de_json(self, offline_bot, sticker):
|
||||
json_dict = {
|
||||
"file_id": self.sticker_file_id,
|
||||
"file_unique_id": self.sticker_file_unique_id,
|
||||
"width": self.width,
|
||||
"height": self.height,
|
||||
"is_animated": self.is_animated,
|
||||
"is_video": self.is_video,
|
||||
"thumbnail": sticker.thumbnail.to_dict(),
|
||||
"emoji": self.emoji,
|
||||
"file_size": self.file_size,
|
||||
"premium_animation": self.premium_animation.to_dict(),
|
||||
"type": self.type,
|
||||
"custom_emoji_id": self.custom_emoji_id,
|
||||
"needs_repainting": self.needs_repainting,
|
||||
}
|
||||
def test_de_json(self, offline_bot):
|
||||
json_dict = self.sticker.to_dict()
|
||||
json_sticker = Sticker.de_json(json_dict, offline_bot)
|
||||
assert json_sticker.api_kwargs == {}
|
||||
|
||||
@@ -152,7 +162,7 @@ class TestStickerWithoutRequest(StickerTestBase):
|
||||
assert json_sticker.is_video == self.is_video
|
||||
assert json_sticker.emoji == self.emoji
|
||||
assert json_sticker.file_size == self.file_size
|
||||
assert json_sticker.thumbnail == sticker.thumbnail
|
||||
assert json_sticker.thumbnail == self.thumbnail
|
||||
assert json_sticker.premium_animation == self.premium_animation
|
||||
assert json_sticker.type == self.type
|
||||
assert json_sticker.custom_emoji_id == self.custom_emoji_id
|
||||
@@ -494,6 +504,13 @@ class StickerSetTestBase:
|
||||
sticker_type = Sticker.REGULAR
|
||||
contains_masks = True
|
||||
thumbnail = PhotoSize("thumb_file_id", "thumb_file_un_id", 100, 100, False)
|
||||
sticker_set = StickerSet(
|
||||
name,
|
||||
title=title,
|
||||
stickers=stickers,
|
||||
sticker_type=sticker_type,
|
||||
thumbnail=thumbnail,
|
||||
)
|
||||
|
||||
|
||||
class TestStickerSetWithoutRequest(StickerSetTestBase):
|
||||
@@ -503,22 +520,15 @@ class TestStickerSetWithoutRequest(StickerSetTestBase):
|
||||
assert getattr(inst, attr, "err") != "err", f"got extra slot '{attr}'"
|
||||
assert len(mro_slots(inst)) == len(set(mro_slots(inst))), "duplicate slot"
|
||||
|
||||
def test_de_json(self, offline_bot, sticker):
|
||||
name = f"test_by_{offline_bot.username}"
|
||||
json_dict = {
|
||||
"name": name,
|
||||
"title": self.title,
|
||||
"stickers": [x.to_dict() for x in self.stickers],
|
||||
"thumbnail": sticker.thumbnail.to_dict(),
|
||||
"sticker_type": self.sticker_type,
|
||||
"contains_masks": self.contains_masks,
|
||||
}
|
||||
def test_de_json(self, offline_bot):
|
||||
json_dict = self.sticker_set.to_dict()
|
||||
json_dict["contains_masks"] = self.contains_masks
|
||||
sticker_set = StickerSet.de_json(json_dict, offline_bot)
|
||||
|
||||
assert sticker_set.name == name
|
||||
assert sticker_set.name == self.name
|
||||
assert sticker_set.title == self.title
|
||||
assert sticker_set.stickers == tuple(self.stickers)
|
||||
assert sticker_set.thumbnail == sticker.thumbnail
|
||||
assert sticker_set.thumbnail == self.thumbnail
|
||||
assert sticker_set.sticker_type == self.sticker_type
|
||||
assert sticker_set.api_kwargs == {"contains_masks": self.contains_masks}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user