U
    dd~?                     @   s   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mZ ddlmZ erddl
mZ G dd deZG dd deZG dd deZdS )z?This module contains an object that represents a Telegram Poll.    N)TYPE_CHECKINGClassVarDictListOptionalSequenceTuple)	constants)MessageEntity)TelegramObject)User)enum)parse_sequence_arg)extract_tzinfo_from_defaultsfrom_timestamp)JSONDict)Botc                       s^   e Zd ZU dZdZddeeed fddZe	j
jZee ed< e	j
jZee ed	<   ZS )

PollOptiona  
    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.

    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.

    )voter_counttextN
api_kwargs)r   r   r   c                   s4   t  j|d || _|| _| j| jf| _|   d S Nr   )super__init__r   r   	_id_attrs_freeze)selfr   r   r   	__class__ 2/tmp/pip-unpacked-wheel-e3anp165/telegram/_poll.pyr   ;   s
    zPollOption.__init__
MIN_LENGTH
MAX_LENGTH)__name__
__module____qualname____doc__	__slots__strintr   r   r	   	PollLimitMIN_OPTION_LENGTHr"   r   __annotations__MAX_OPTION_LENGTHr#   __classcell__r    r    r   r!   r   $   s   
	r   c                       s\   e Zd ZdZdZddeeee e	d fddZ
eee	 ded  d	 fd
dZ  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.

    Args:
        poll_id (:obj:`str`): Unique poll identifier.
        user (:class:`telegram.User`): The user, who changed the answer to the poll.
        option_ids (Sequence[:obj:`int`]): 0-based identifiers of answer options, chosen by the
            user. May be empty if the user retracted their vote.

            .. versionchanged:: 20.0
                |sequenceclassargs|

    Attributes:
        poll_id (:obj:`str`): Unique poll identifier.
        user (:class:`telegram.User`): The user, who changed the answer to the poll.
        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|

    )
option_idsuserpoll_idNr   )r3   r2   r1   r   c                   sF   t  j|d || _|| _t|| _| j| jt| jf| _|   d S r   )	r   r   r3   r2   r   r1   tupler   r   )r   r3   r2   r1   r   r   r    r!   r   m   s    
zPollAnswer.__init__r   databotreturnc                    s8   |  |}|sdS t|d||d< t j||dS ),See :meth:`telegram.TelegramObject.de_json`.Nr2   r6   r7   )_parse_datar   de_jsongetr   )clsr6   r7   r   r    r!   r<   y   s
    
zPollAnswer.de_json)r$   r%   r&   r'   r(   r)   r   r   r*   r   r   classmethodr   r<   r/   r    r    r   r!   r0   P   s      r0   c                       s  e Zd ZU dZdZdddeeee ee	e	ee	eeee
 eejed fddZeee ded  d	 fd
dZe
edddZdee ee
ef dddZ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j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j!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j%Z%ee ed<   Z&S ) Polla#  
    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|

    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|

    )total_voter_countallows_multiple_answersopen_periodoptionstypeexplanation_entitiesis_anonymous
close_date	is_closedidexplanationquestioncorrect_option_idNr   )rJ   rL   rD   rA   rI   rG   rE   rB   rM   rK   rF   rC   rH   r   c                   s   t  j|d || _|| _t|| _|| _|| _|| _t	
tj||| _|| _|	| _|
| _t|| _|| _|| _| jf| _|   d S r   )r   r   rJ   rL   r   rD   rA   rI   rG   r   Z
get_memberr	   PollTyperE   rB   rM   rK   rF   rC   rH   r   r   )r   rJ   rL   rD   rA   rI   rG   rE   rB   rM   rK   rF   rC   rH   r   r   r    r!   r      s$    

zPoll.__init__r   r5   c                    sp   |  |}|sdS t } fdd|d D |d< t|d |d< t|d|d|d< t j| dS )	r9   Nc                    s   g | ]}t | qS r    )r   r<   ).0optionr7   r    r!   
<listcomp>  s     z Poll.de_json.<locals>.<listcomp>rD   rF   rH   )tzinfor:   )r;   r   r
   Zde_listr=   r   r   r<   )r>   r6   r7   Z
loc_tzinfor   rQ   r!   r<     s    
zPoll.de_json)entityr8   c                 C   sB   | j std| j d}||jd |j|j d  }|dS )a  Returns the text from a given :class:`telegram.MessageEntity`.

        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 this message.

        Returns:
            :obj:`str`: The text of the given entity.

        Raises:
            RuntimeError: If the poll has no explanation.

        zThis Poll has no 'explanation'.z	utf-16-le   )rK   RuntimeErrorencodeoffsetlengthdecode)r   rT   Zentity_textr    r    r!   parse_explanation_entity!  s
    zPoll.parse_explanation_entity)typesr8   c                    s$   dkrt j fdd jD S )a  
        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.

        Nc                    s"   i | ]}|j kr| |qS r    )rE   r[   )rO   rT   r   r\   r    r!   
<dictcomp>T  s   
 z3Poll.parse_explanation_entities.<locals>.<dictcomp>)r
   Z	ALL_TYPESrF   r]   r    r]   r!   parse_explanation_entities<  s
    zPoll.parse_explanation_entitiesREGULARQUIZMAX_EXPLANATION_LENGTHMAX_EXPLANATION_LINE_FEEDSMIN_OPEN_PERIODMAX_OPEN_PERIODMIN_QUESTION_LENGTHMAX_QUESTION_LENGTHr,   r.   MIN_OPTION_NUMBERMAX_OPTION_NUMBER)NNNNN)N)'r$   r%   r&   r'   r(   r)   r   r   r*   boolr
   datetimer   r   r?   r   r<   r[   r   r   r_   r	   rN   r`   r   r-   ra   r+   rb   rc   rd   re   rf   rg   r,   r.   rh   ri   r/   r    r    r   r!   r@      sT   
R     ' r@   )r'   rk   typingr   r   r   r   r   r   r   Ztelegramr	   Ztelegram._messageentityr
   Ztelegram._telegramobjectr   Ztelegram._userr   Ztelegram._utilsr   Ztelegram._utils.argumentparsingr   Ztelegram._utils.datetimer   r   Ztelegram._utils.typesr   r   r   r0   r@   r    r    r    r!   <module>   s   $,6