
    ՟fBi                     ,   d Z ddlZddlmZmZmZmZmZmZm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZ ddlmZ ddlmZmZ ddl m!Z!m"Z" erddl
m#Z#  G d de      Z$ G d de      Z% G d de      Z& G d de      Z'y)z?This module contains an object that represents a Telegram Poll.    N)TYPE_CHECKINGDictFinalListOptionalSequenceTuple)	constants)Chat)MessageEntity)TelegramObject)User)enum)parse_sequence_arg)extract_tzinfo_from_defaultsfrom_timestamp)DEFAULT_NONE)parse_message_entitiesparse_message_entity)JSONDictODVInput)Botc                        e Zd ZdZdZedfdddedee   dee	e
      dee   f fd	Ze	 dd
ee   ded   ded    f fd       Z xZS )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_entitiestext_parse_modeN
api_kwargsr   r   r   r   c                    t         |   |       || _        || _        t	        |      | _        | j                  f| _        | j                          y Nr   )super__init__r   r   r   r   	_id_attrs_freeze)selfr   r   r   r   	__class__s        I/var/www/cvtools/html/venv/lib/python3.12/site-packages/telegram/_poll.pyr#   zInputPollOption.__init__K   sG     	J/	.=8J=8Y))    databotr   returnc                     | j                  |      }|syt        j                  |j                  d      |      |d<   t        |   ||      S ,See :meth:`telegram.TelegramObject.de_json`.Nr   r*   r+   _parse_datar   de_listgetr"   de_jsonclsr*   r+   r'   s      r(   r5   zInputPollOption.de_json\   M    
 t$ - 5 5dhh6OQT U_wDc22r)   N)__name__
__module____qualname____doc__	__slots__r   strr   r   r   r   r   r#   classmethodr5   __classcell__r'   s   @r(   r   r   '   s    B =I
 *6;?	 *. "#   78	 X&" >B3H%3,4UO3	#	$3 3r)   r   c                   @    e Zd ZU dZdZ	 ddddededeee	      dee
   f fd	Ze	 dd
ee
   ded   ded    f fd       Zde	defdZddeee      dee	ef   fdZej&                  j(                  Zee   ed<   	 ej&                  j0                  Zee   ed<    xZS )
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

    )r   r   voter_countNr   r   rE   r   r   c                    t         |   |       || _        || _        t	        |      | _        | j                  | j                  f| _        | j                          y r!   )r"   r#   r   rE   r   r   r$   r%   )r&   r   rE   r   r   r'   s        r(   r#   zPollOption.__init__   sP     	J/	 +8J=8Y))T%5%56r)   r*   r+   r   r,   c                     | j                  |      }|syt        j                  |j                  d      |      |d<   t        |   ||      S r.   r1   r6   s      r(   r5   zPollOption.de_json   r8   r)   entityc                 .    t        | j                  |      S )a  Returns 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.
        )r   r   r&   rH   s     r(   parse_entityzPollOption.parse_entity   s    $ $DIIv66r)   typesc                 D    t        | 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.
        )r   r   r   r&   rL   s     r(   parse_entitieszPollOption.parse_entities   s    , &dii1C1CUKKr)   
MIN_LENGTH
MAX_LENGTHr9   )r:   r;   r<   r=   r>   r?   intr   r   r   r   r#   r@   r5   rK   r   r   rO   r
   	PollLimitMIN_OPTION_LENGTHrP   r   __annotations__MAX_OPTION_LENGTHrQ   rA   rB   s   @r(   rD   rD   k   s   > 9I <@	 *.    78	 X&" >B3H%3,4UO3	,	3 37= 7S 7(LHT#Y$7 L4WZHZC[ L0 '00BBJc
B '00BBJc
Br)   rD   c                        e Zd ZdZdZ	 	 ddddedee   dee	   dee
   d	ee   f
 fd
Ze	 ddee   ded   ded    f fd       Z xZS )
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_idspoll_iduser
voter_chatNr   rZ   rY   r[   r\   r   c                    t         |   |       || _        || _        t	        |      | _        || _        | j                  | j
                  | j                  | j                  f| _        | j                          y r!   )	r"   r#   rZ   r\   r   rY   r[   r$   r%   )r&   rZ   rY   r[   r\   r   r'   s         r(   r#   zPollAnswer.__init__  sh     	J/#*4+=j+I$(	 LLOOIIOO	
 	r)   r*   r+   r   r,   c                     | j                  |      }|syt        j                  |j                  d      |      |d<   t	        j                  |j                  d      |      |d<   t
        | 	  ||      S )r/   Nr[   r\   r0   )r2   r   r5   r4   r   r"   r6   s      r(   r5   zPollAnswer.de_json3  sg    
 t$||DHHV$4c:V!\\$((<*@#F\wDc22r)   )NNr9   )r:   r;   r<   r=   r>   r?   r   rR   r   r   r   r   r#   r@   r5   rA   rB   s   @r(   rX   rX      s    2h @I  $%) *. SM tn	
 TN X&0 >B3H%3,4UO3	,	3 3r)   rX   c            !       Z    e Zd ZU dZdZ	 	 	 	 	 	 d,dddededee   ded	e	d
e	dede	de
e   de
e   de
ee      de
e   de
ej                     de
ee      de
e   f fdZed-de
e   de
d   de
d    f fd       ZdedefdZ	 d-de
ee      deeef   fdZdedefdZ	 d-de
ee      deeef   fdZej0                  j2                  Zee   ed <   	 ej0                  j8                  Zee   ed!<   	 ej:                  j<                  Zee   ed"<   	 ej:                  j>                  Zee   ed#<   	 ej:                  j@                  Z ee   ed$<   	 ej:                  jB                  Z!ee   ed%<   	 ej:                  jD                  Z"ee   ed&<   	 ej:                  jF                  Z#ee   ed'<   	 ej:                  jH                  Z$ee   ed(<   	 ej:                  jJ                  Z%ee   ed)<   	 ej:                  jL                  Z&ee   ed*<   	 ej:                  jN                  Z'ee   ed+<    xZ(S ).Pollap  
    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 <examples.pollbot>`

    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`, optional): Amount of time in seconds the poll will be active
            after creation.
        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`): Optional. Amount of time in seconds the poll will be active
            after creation.
        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

    )allows_multiple_answers
close_datecorrect_option_idexplanationexplanation_entitiesidis_anonymous	is_closedopen_periodoptionsquestionquestion_entitiestotal_voter_counttypeNr   rf   rk   rj   rm   rh   rg   rn   ra   rc   rd   re   ri   rb   rl   r   c                   t         |   |       || _        || _        t	        |      | _        || _        || _        || _        t        j                  t        j                  ||      | _        || _        |	| _        |
| _        t	        |      | _        || _        || _        t	        |      | _        | j                  f| _        | j-                          y r!   )r"   r#   rf   rk   r   rj   rm   rh   rg   r   
get_memberr
   PollTypern   ra   rc   rd   re   ri   rb   rl   r$   r%   )r&   rf   rk   rj   rm   rh   rg   rn   ra   rc   rd   re   ri   rb   rl   r   r'   s                   r(   r#   zPoll.__init__  s    & 	J/%/A'/J&7(".););T4H	-D$0A*5?Q @
! +67A<NO`<a''r)   r*   r+   r   r,   c                    | j                  |      }|syt        |      }|d   D cg c]  }t        j                  ||       c}|d<   t	        j
                  |j                  d      |      |d<   t        |j                  d      |      |d<   t	        j
                  |j                  d      |      |d<   t        |   ||      S c c}w )r/   Nrj   re   rb   )tzinforl   r0   )	r2   r   rD   r5   r   r3   r4   r   r"   )r7   r*   r+   
loc_tzinfooptionr'   s        r(   r5   zPoll.de_json  s     t$ 2#6
IMiYv:--fc:YY'4'<'<TXXF\=]_b'c#$+DHH\,B:V\$1$9$9$((CV:WY\$] !wDc22 Zs   CrH   c                 \    | j                   st        d      t        | j                   |      S )a  Returns 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'.)rd   RuntimeErrorr   rJ   s     r(   parse_explanation_entityzPoll.parse_explanation_entity  s,    ( @AA#D$4$4f==r)   rL   c                 r    | j                   st        d      t        | 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.

        rw   )rd   rx   r   re   rN   s     r(   parse_explanation_entitieszPoll.parse_explanation_entities  s5    4 @AA%d&6&68Q8QSXYYr)   c                 .    t        | j                  |      S )a  Returns 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.
        )r   rk   rJ   s     r(   parse_question_entityzPoll.parse_question_entity%  s    $ $DMM6::r)   c                 D    t        | 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.

        )r   rk   rl   rN   s     r(   parse_question_entitieszPoll.parse_question_entities9  s    2 &dmmT5K5KUSSr)   REGULARQUIZMAX_EXPLANATION_LENGTHMAX_EXPLANATION_LINE_FEEDSMIN_OPEN_PERIODMAX_OPEN_PERIODMIN_QUESTION_LENGTHMAX_QUESTION_LENGTHrT   rV   MIN_OPTION_NUMBERMAX_OPTION_NUMBER)NNNNNNr9   ))r:   r;   r<   r=   r>   r?   r   rD   rR   boolr   r   datetimer   r#   r@   r5   ry   r   r   r{   r}   r   r
   rq   r   r   rU   r   rS   r   r   r   r   r   r   rT   rV   r   r   rA   rB   s   @r(   r`   r`   C  sH   [zI6 ,0%)BF%)26?C'" *.#'' ' *%	'
 ' ' ' ' "&' $C=' c]' 'x'>?' c]' X../' $H]$;<'" X&#'R 38H- 3HUO 3xX^O_ 3 3">} > >4 ,0Zd3i(Z	mS 	!Z>;M ;c ;* ,0Td3i(T	mS 	!T6 $,,44GU3Z46 ))..D%*.3)2)<)<)S)SE#JS .7-@-@-[-[c
[ #,"5"5"E"EOU3ZE #,"5"5"E"EOU3ZE '0&9&9&M&MsM '0&9&9&M&MsM %.$7$7$I$IuSzI %.$7$7$I$IuSzI %.$7$7$I$IuSzI %.$7$7$I$IuSzIr)   r`   )(r=   r   typingr   r   r   r   r   r   r	   telegramr
   telegram._chatr   telegram._messageentityr   telegram._telegramobjectr   telegram._userr   telegram._utilsr   telegram._utils.argumentparsingr   telegram._utils.datetimer   r   telegram._utils.defaultvaluer   telegram._utils.entitiesr   r   telegram._utils.typesr   r   r   r   rD   rX   r`    r)   r(   <module>r      sy   & F  N N N   1 3    > Q 5 Q 4A3n A3Hv vr\3 \3~F> Fr)   