MCPcopy Index your code
hub / github.com/python-telegram-bot/python-telegram-bot / de_json

Method de_json

src/telegram/_chatmember.py:110–139  ·  view source on GitHub ↗

See :meth:`telegram.TelegramObject.de_json`.

(cls, data: JSONDict, bot: "Bot | None" = None)

Source from the content-addressed store, hash-verified

108
109 @classmethod
110 def de_json(cls, data: JSONDict, bot: "Bot | None" = None) -> "ChatMember":
111 """See :meth:`telegram.TelegramObject.de_json`."""
112 data = cls._parse_data(data)
113
114 _class_mapping: dict[str, type[ChatMember]] = {
115 cls.OWNER: ChatMemberOwner,
116 cls.ADMINISTRATOR: ChatMemberAdministrator,
117 cls.MEMBER: ChatMemberMember,
118 cls.RESTRICTED: ChatMemberRestricted,
119 cls.LEFT: ChatMemberLeft,
120 cls.BANNED: ChatMemberBanned,
121 }
122
123 if cls is ChatMember and data.get("status") in _class_mapping:
124 return _class_mapping[data.pop("status")].de_json(data=data, bot=bot)
125
126 data["user"] = de_json_optional(data.get("user"), User, bot)
127 if "until_date" in data:
128 # Get the local timezone from the bot if it has defaults
129 loc_tzinfo = extract_tzinfo_from_defaults(bot)
130
131 data["until_date"] = from_timestamp(data.get("until_date"), tzinfo=loc_tzinfo)
132
133 # This is a deprecated field that TG still returns for backwards compatibility
134 # Let's filter it out to speed up the de-json process
135 if cls is ChatMemberRestricted and data.get("can_send_media_messages") is not None:
136 api_kwargs = {"can_send_media_messages": data.pop("can_send_media_messages")}
137 return super()._de_json(data=data, bot=bot, api_kwargs=api_kwargs)
138
139 return super().de_json(data=data, bot=bot)
140
141
142class ChatMemberOwner(ChatMember):

Callers

nothing calls this directly

Calls 6

de_json_optionalFunction · 0.90
from_timestampFunction · 0.90
_parse_dataMethod · 0.80
popMethod · 0.80
_de_jsonMethod · 0.45

Tested by

no test coverage detected