L ij@dZddlZddlmZddlmZmZmZm Z ddl m Z ddl m Z ddlmZddlmZdd lmZdd lmZdd lmZmZmZmZdd lmZmZmZdd lm Z ddl!m"Z"m#Z#ddl$m%Z%m&Z&m'Z'erddl m(Z(GddeZ)GddeZ*GddeZ+GddeZ,y)z?This module contains an object that represents a Telegram Poll.N)Sequence) TYPE_CHECKINGFinalOptionalUnion) constants)Chat) MessageEntity)TelegramObject)User)enum)de_json_optionalde_list_optionalparse_sequence_arg to_timedelta)extract_tzinfo_from_defaultsfrom_timestampget_timedelta_value) DEFAULT_NONE)parse_message_entitiesparse_message_entity)JSONDictODVInput TimePeriod)Botc eZdZdZdZedfdddedeedee e dee ffd Z e dd e d ed d dffd ZxZS)InputPollOptiona This object contains information about one answer option in a poll to be sent. Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their :attr:`text` is equal. .. versionadded:: 21.2 Args: text (:obj:`str`): Option text, :tg-const:`telegram.PollOption.MIN_LENGTH`-:tg-const:`telegram.PollOption.MAX_LENGTH` characters. text_parse_mode (:obj:`str`, optional): |parse_mode| Currently, only custom emoji entities are allowed. text_entities (Sequence[:class:`telegram.MessageEntity`], optional): Special entities that appear in the option :paramref:`text`. It can be specified instead of :paramref:`text_parse_mode`. Currently, only custom emoji entities are allowed. This list is empty if the text does not contain entities. Attributes: text (:obj:`str`): Option text, :tg-const:`telegram.PollOption.MIN_LENGTH`-:tg-const:`telegram.PollOption.MAX_LENGTH` characters. text_parse_mode (:obj:`str`): Optional. |parse_mode| Currently, only custom emoji entities are allowed. text_entities (Sequence[:class:`telegram.MessageEntity`]): Special entities that appear in the option :paramref:`text`. It can be specified instead of :paramref:`text_parse_mode`. Currently, only custom emoji entities are allowed. This list is empty if the text does not contain entities. )text text_entitiestext_parse_modeN api_kwargsrr rr"ct||||_||_t ||_|jf|_|jyNr!)super__init__rr rr _id_attrs_freeze)selfrr rr" __class__s T/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/telegram/_poll.pyr&zInputPollOption.__init__VsG J/ .=8J=8Y)) databotrreturnc|j|}t|jdt||d<t|||S,See :meth:`telegram.TelegramObject.de_json`.rr-r. _parse_datargetr r%de_jsonclsr-r.r*s r+r7zInputPollOption.de_jsongCt$ 0/1JM[^ __wDc22r,N)__name__ __module__ __qualname____doc__ __slots__rstrrrrr rr& classmethodr7 __classcell__r*s@r+rr2sB=I *6;?  *. "#  78  X& "383(5/3EV33r,rc 2eZdZUdZdZ ddddededeee dee ffd Z e dd e d ed d dffd Z de d efdZddeeed ee effdZej&j(Zeeed< ej&j0Zeeed<xZS) PollOptiona8 This object contains information about one answer option in a poll. Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their :attr:`text` and :attr:`voter_count` are equal. Args: text (:obj:`str`): Option text, :tg-const:`telegram.PollOption.MIN_LENGTH`-:tg-const:`telegram.PollOption.MAX_LENGTH` characters. voter_count (:obj:`int`): Number of users that voted for this option. text_entities (Sequence[:class:`telegram.MessageEntity`], optional): Special entities that appear in the option text. Currently, only custom emoji entities are allowed in poll option texts. .. versionadded:: 21.2 Attributes: text (:obj:`str`): Option text, :tg-const:`telegram.PollOption.MIN_LENGTH`-:tg-const:`telegram.PollOption.MAX_LENGTH` characters. voter_count (:obj:`int`): Number of users that voted for this option. text_entities (tuple[:class:`telegram.MessageEntity`]): Special entities that appear in the option text. Currently, only custom emoji entities are allowed in poll option texts. This list is empty if the question does not contain entities. .. versionadded:: 21.2 )rr voter_countNr!rrGrr"ct||||_||_t ||_|j|jf|_|jyr$)r%r&rrGrrr'r()r)rrGrr"r*s r+r&zPollOption.__init__sP J/ +8J=8Y))T%5%56 r,r-r.rr/c|j|}t|jdt||d<t|||Sr1r4r8s r+r7zPollOption.de_jsonr:r,entityc.t|j|S)aReturns the text in :attr:`text` from a given :class:`telegram.MessageEntity` of :attr:`text_entities`. Note: This method is present because Telegram calculates the offset and length in UTF-16 codepoint pairs, which some versions of Python don't handle automatically. (That is, you can't just slice ``Message.text`` with the offset and length.) .. versionadded:: 21.2 Args: entity (:class:`telegram.MessageEntity`): The entity to extract the text from. It must be an entity that belongs to :attr:`text_entities`. Returns: :obj:`str`: The text of the given entity. )rrr)rJs r+ parse_entityzPollOption.parse_entitys$$DIIv66r,typescDt|j|j|S)a( Returns a :obj:`dict` that maps :class:`telegram.MessageEntity` to :obj:`str`. It contains entities from this polls question filtered by their ``type`` attribute as the key, and the text that each entity belongs to as the value of the :obj:`dict`. Note: This method should always be used instead of the :attr:`text_entities` attribute, since it calculates the correct substring from the message text based on UTF-16 codepoints. See :attr:`parse_entity` for more info. .. versionadded:: 21.2 Args: types (list[:obj:`str`], optional): List of ``MessageEntity`` types as strings. If the ``type`` attribute of an entity is contained in this list, it will be returned. Defaults to :attr:`telegram.MessageEntity.ALL_TYPES`. Returns: dict[:class:`telegram.MessageEntity`, :obj:`str`]: A dictionary of entities mapped to the text that belongs to them, calculated based on UTF-16 codepoints. )rrrr)rNs r+parse_entitieszPollOption.parse_entitiess,&dii1C1CUKKr, MIN_LENGTH MAX_LENGTHr;)r<r=r>r?r@rAintrrr rr&rBr7rMlistdictrQr PollLimitMIN_OPTION_LENGTHrRr__annotations__MAX_OPTION_LENGTHrSrCrDs@r+rFrFqs>9I <@  *.   78  X& "383(5/3\337=7S7(LHT#Y$7L4 WZHZC[L0'00BBJc B'00BBJc Br,rFc eZdZdZdZ ddddedeedee dee d ee f fd Z e dd e d ed ddffd ZxZS) PollAnswera This object represents an answer of a user in a non-anonymous poll. Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their :attr:`poll_id`, :attr:`user` and :attr:`option_ids` are equal. .. versionchanged:: 20.5 The order of :paramref:`option_ids` and :paramref:`user` is changed in 20.5 as the latter one became optional. .. versionchanged:: 20.6 Backward compatiblity for changed order of :paramref:`option_ids` and :paramref:`user` was removed. Args: poll_id (:obj:`str`): Unique poll identifier. option_ids (Sequence[:obj:`int`]): Identifiers of answer options, chosen by the user. May be empty if the user retracted their vote. .. versionchanged:: 20.0 |sequenceclassargs| user (:class:`telegram.User`, optional): The user that changed the answer to the poll, if the voter isn't anonymous. If the voter is anonymous, this field will contain the user :tg-const:`telegram.constants.ChatID.FAKE_CHANNEL` for backwards compatibility. .. versionchanged:: 20.5 :paramref:`user` became optional. voter_chat (:class:`telegram.Chat`, optional): The chat that changed the answer to the poll, if the voter is anonymous. .. versionadded:: 20.5 Attributes: poll_id (:obj:`str`): Unique poll identifier. option_ids (tuple[:obj:`int`]): Identifiers of answer options, chosen by the user. May be empty if the user retracted their vote. .. versionchanged:: 20.0 |tupleclassattrs| user (:class:`telegram.User`): Optional. The user, who changed the answer to the poll, if the voter isn't anonymous. If the voter is anonymous, this field will contain the user :tg-const:`telegram.constants.ChatID.FAKE_CHANNEL` for backwards compatibility .. versionchanged:: 20.5 :paramref:`user` became optional. voter_chat (:class:`telegram.Chat`): Optional. The chat that changed the answer to the poll, if the voter is anonymous. .. versionadded:: 20.5 ) option_idspoll_iduser voter_chatNr!r^r]r_r`r"ct||||_||_t ||_||_|j|j |j |jf|_|jyr$) r%r&r^r`rr]r_r'r()r)r^r]r_r`r"r*s r+r&zPollAnswer.__init__sh J/# *4+=j+I$(  LL OO II OO   r,r-r.rr/c|j|}t|jdt||d<t|jdt||d<t |||S)r2r_r`r3)r5rr6r r r%r7r8s r+r7zPollAnswer.de_json4s]t$'(8$DV -dhh|.DdCP\wDc22r,)NNr;)r<r=r>r?r@rArrTrr r rr&rBr7rCrDs@r+r\r\s2h@I $%) *.SMtn  TN X&0383(5/3\33r,r\c!eZdZUdZdZ d-dddededeeded e d e d ed e d e ede ede ee de e de e jde ee de effdZede eee j&ffdZed.dede dddffd Zde defdZ d.de eedee effdZde defdZ d.de eedee effd Zej<j>Ze ee!d!< ej<jDZ"e ee!d"< ejFjHZ$e ee!d#< ejFjJZ%e ee!d$< ejFjLZ&e ee!d%< ejFjNZ'e ee!d&< ejFjPZ(e ee!d'< ejFjRZ)e ee!d(< ejFjTZ*e ee!d)< ejFjVZ+e ee!d*< ejFjXZ,e ee!d+< ejFjZZ-e ee!d,<xZ.S)/PollaG This object contains information about a poll. Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their :attr:`id` is equal. Examples: :any:`Poll Bot ` Args: id (:obj:`str`): Unique poll identifier. question (:obj:`str`): Poll question, :tg-const:`telegram.Poll.MIN_QUESTION_LENGTH`- :tg-const:`telegram.Poll.MAX_QUESTION_LENGTH` characters. options (Sequence[:class:`~telegram.PollOption`]): List of poll options. .. versionchanged:: 20.0 |sequenceclassargs| is_closed (:obj:`bool`): :obj:`True`, if the poll is closed. is_anonymous (:obj:`bool`): :obj:`True`, if the poll is anonymous. type (:obj:`str`): Poll type, currently can be :attr:`REGULAR` or :attr:`QUIZ`. allows_multiple_answers (:obj:`bool`): :obj:`True`, if the poll allows multiple answers. correct_option_id (:obj:`int`, optional): A zero based identifier of the correct answer option. Available only for closed polls in the quiz mode, which were sent (not forwarded), by the bot or to a private chat with the bot. explanation (:obj:`str`, optional): Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-:tg-const:`telegram.Poll.MAX_EXPLANATION_LENGTH` characters. explanation_entities (Sequence[:class:`telegram.MessageEntity`], optional): Special entities like usernames, URLs, bot commands, etc. that appear in the :attr:`explanation`. This list is empty if the message does not contain explanation entities. .. versionchanged:: 20.0 * This attribute is now always a (possibly empty) list and never :obj:`None`. * |sequenceclassargs| open_period (:obj:`int` | :class:`datetime.timedelta`, optional): Amount of time in seconds the poll will be active after creation. .. versionchanged:: v22.2 |time-period-input| close_date (:obj:`datetime.datetime`, optional): Point in time (Unix timestamp) when the poll will be automatically closed. Converted to :obj:`datetime.datetime`. .. versionchanged:: 20.3 |datetime_localization| question_entities (Sequence[:class:`telegram.MessageEntity`], optional): Special entities that appear in the :attr:`question`. Currently, only custom emoji entities are allowed in poll questions. .. versionadded:: 21.2 Attributes: id (:obj:`str`): Unique poll identifier. question (:obj:`str`): Poll question, :tg-const:`telegram.Poll.MIN_QUESTION_LENGTH`- :tg-const:`telegram.Poll.MAX_QUESTION_LENGTH` characters. options (tuple[:class:`~telegram.PollOption`]): List of poll options. .. versionchanged:: 20.0 |tupleclassattrs| total_voter_count (:obj:`int`): Total number of users that voted in the poll. is_closed (:obj:`bool`): :obj:`True`, if the poll is closed. is_anonymous (:obj:`bool`): :obj:`True`, if the poll is anonymous. type (:obj:`str`): Poll type, currently can be :attr:`REGULAR` or :attr:`QUIZ`. allows_multiple_answers (:obj:`bool`): :obj:`True`, if the poll allows multiple answers. correct_option_id (:obj:`int`): Optional. A zero based identifier of the correct answer option. Available only for closed polls in the quiz mode, which were sent (not forwarded), by the bot or to a private chat with the bot. explanation (:obj:`str`): Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-:tg-const:`telegram.Poll.MAX_EXPLANATION_LENGTH` characters. explanation_entities (tuple[:class:`telegram.MessageEntity`]): Special entities like usernames, URLs, bot commands, etc. that appear in the :attr:`explanation`. This list is empty if the message does not contain explanation entities. .. versionchanged:: 20.0 |tupleclassattrs| .. versionchanged:: 20.0 This attribute is now always a (possibly empty) list and never :obj:`None`. open_period (:obj:`int` | :class:`datetime.timedelta`): Optional. Amount of time in seconds the poll will be active after creation. .. deprecated:: v22.2 |time-period-int-deprecated| close_date (:obj:`datetime.datetime`): Optional. Point in time when the poll will be automatically closed. .. versionchanged:: 20.3 |datetime_localization| question_entities (tuple[:class:`telegram.MessageEntity`]): Special entities that appear in the :attr:`question`. Currently, only custom emoji entities are allowed in poll questions. This list is empty if the question does not contain entities. .. versionadded:: 21.2 ) _open_periodallows_multiple_answers close_datecorrect_option_id explanationexplanation_entitiesid is_anonymous is_closedoptionsquestionquestion_entitiestotal_voter_counttypeNr!rkrornrqrmrlrrrfrhrirj open_periodrgrpr"ct||||_||_t ||_||_||_||_tjtj|||_ ||_| |_| |_t | |_t%| |_| |_t ||_|jf|_|j/yr$)r%r&rkrorrnrqrmrlr get_memberrPollTyperrrfrhrirjrrergrpr'r()r)rkrornrqrmrlrrrfrhrirjrsrgrpr"r*s r+r&z Poll.__init__s& J/% /A'/J &7(".););T4H -D$0A*5?Q @ !6B+5N2< CPY'7 HH+ ,mS(  #$,DHH\,B:V\$4 HH( )=#%  !wDc22r,rJc\|js tdt|j|S)aReturns the text in :attr:`explanation` from a given :class:`telegram.MessageEntity` of :attr:`explanation_entities`. Note: This method is present because Telegram calculates the offset and length in UTF-16 codepoint pairs, which some versions of Python don't handle automatically. (That is, you can't just slice ``Message.text`` with the offset and length.) Args: entity (:class:`telegram.MessageEntity`): The entity to extract the text from. It must be an entity that belongs to :attr:`explanation_entities`. Returns: :obj:`str`: The text of the given entity. Raises: RuntimeError: If the poll has no explanation. This Poll has no 'explanation'.)ri RuntimeErrorrrLs r+parse_explanation_entityzPoll.parse_explanation_entitys,(@A A#D$4$4f==r,rNcr|js tdt|j|j|S)aj Returns a :obj:`dict` that maps :class:`telegram.MessageEntity` to :obj:`str`. It contains entities from this polls explanation filtered by their ``type`` attribute as the key, and the text that each entity belongs to as the value of the :obj:`dict`. Note: This method should always be used instead of the :attr:`explanation_entities` attribute, since it calculates the correct substring from the message text based on UTF-16 codepoints. See :attr:`parse_explanation_entity` for more info. Args: types (list[:obj:`str`], optional): List of ``MessageEntity`` types as strings. If the ``type`` attribute of an entity is contained in this list, it will be returned. Defaults to :attr:`telegram.MessageEntity.ALL_TYPES`. Returns: dict[:class:`telegram.MessageEntity`, :obj:`str`]: A dictionary of entities mapped to the text that belongs to them, calculated based on UTF-16 codepoints. Raises: RuntimeError: If the poll has no explanation. r})rir~rrjrPs r+parse_explanation_entitieszPoll.parse_explanation_entities s54@A A%d&6&68Q8QSXYYr,c.t|j|S)aReturns the text in :attr:`question` from a given :class:`telegram.MessageEntity` of :attr:`question_entities`. .. versionadded:: 21.2 Note: This method is present because Telegram calculates the offset and length in UTF-16 codepoint pairs, which some versions of Python don't handle automatically. (That is, you can't just slice ``Message.text`` with the offset and length.) Args: entity (:class:`telegram.MessageEntity`): The entity to extract the text from. It must be an entity that belongs to :attr:`question_entities`. Returns: :obj:`str`: The text of the given entity. )rrorLs r+parse_question_entityzPoll.parse_question_entity,s$$DMM6::r,cDt|j|j|S)a6 Returns a :obj:`dict` that maps :class:`telegram.MessageEntity` to :obj:`str`. It contains entities from this polls question filtered by their ``type`` attribute as the key, and the text that each entity belongs to as the value of the :obj:`dict`. .. versionadded:: 21.2 Note: This method should always be used instead of the :attr:`question_entities` attribute, since it calculates the correct substring from the message text based on UTF-16 codepoints. See :attr:`parse_question_entity` for more info. Args: types (list[:obj:`str`], optional): List of ``MessageEntity`` types as strings. If the ``type`` attribute of an entity is contained in this list, it will be returned. Defaults to :attr:`telegram.MessageEntity.ALL_TYPES`. Returns: dict[:class:`telegram.MessageEntity`, :obj:`str`]: A dictionary of entities mapped to the text that belongs to them, calculated based on UTF-16 codepoints. )rrorprPs r+parse_question_entitieszPoll.parse_question_entities@s2&dmmT5K5KUSSr,REGULARQUIZMAX_EXPLANATION_LENGTHMAX_EXPLANATION_LINE_FEEDSMIN_OPEN_PERIODMAX_OPEN_PERIODMIN_QUESTION_LENGTHMAX_QUESTION_LENGTHrXrZMIN_OPTION_NUMBERMAX_OPTION_NUMBER)NNNNNNr;)/r<r=r>r?r@rArrFrTboolrr rdtmdatetimerr&propertyr timedeltarsrBr7rrUrVrrrrrvrrrYrrWrrrrrrrXrZrrrCrDs@r+rdrd?smaFI6,0%)BF,0-1?C'"*.#' ''*% '  '  '''"&'$C='c]''x '>?'j)'S\\*'$H]$;<'"X&#'ROXeC,>&?@OO383(5/3V33$>}>>4,0Zd3i(Z mS !Z>;M;c;*,0Td3i(T mS !T6$,,44GU3Z46 ))..D%*.3)2)<)<)S)SE#JS.7-@-@-[-[c [#,"5"5"E"EOU3ZE#,"5"5"E"EOU3ZE'0&9&9&M&MsM'0&9&9&M&MsM%.$7$7$I$IuSzI%.$7$7$I$IuSzI%.$7$7$I$IuSzI%.$7$7$I$IuSzIr,rd)-r?rrcollections.abcrtypingrrrrtelegramrtelegram._chatr telegram._messageentityr telegram._telegramobjectr telegram._userr telegram._utilsr telegram._utils.argumentparsingrrrrtelegram._utils.datetimerrrtelegram._utils.defaultvaluertelegram._utils.entitiesrrtelegram._utils.typesrrrrrrFr\rdr,r+rs&F$8813   6Q@@<3n<3~qqhW3W3tQ>Qr,