o
    "hA                     @   s   d Z ddlZddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZmZmZ dd	lmZmZ dd
lmZmZ ddlmZ ddlmZ erVddlmZmZ G dd de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 objects related to Telegram checklists.    N)Sequence)TYPE_CHECKINGOptional)MessageEntity)TelegramObject)User)de_json_optionalde_list_optionalparse_sequence_arg)extract_tzinfo_from_defaultsfrom_timestamp)parse_message_entitiesparse_message_entity)JSONDict)	ZERO_DATE)BotMessagec                       s   e Zd ZdZdZ			ddddededeee	  dee
 d	eej d
ee f fddZeddeded dd f fddZde	defddZddeee  dee	ef fddZ  ZS )ChecklistTaska  
    Describes a task in a checklist.

    Objects of this class are comparable in terms of equality.
    Two objects of this class are considered equal, if all their :attr:`id` is equal.

    .. versionadded:: 22.3

    Args:
        id (:obj:`int`): Unique identifier of the task.
        text (:obj:`str`): Text of the task.
        text_entities (Sequence[:class:`telegram.MessageEntity`], optional): Special
            entities that appear in the task text.
        completed_by_user (:class:`telegram.User`, optional): User that completed the task; omitted
            if the task wasn't completed
        completion_date (:class:`datetime.datetime`, optional): Point in time when
            the task was completed; :attr:`~telegram.constants.ZERO_DATE` if the task wasn't
            completed

            |datetime_localization|

    Attributes:
        id (:obj:`int`): Unique identifier of the task.
        text (:obj:`str`): Text of the task.
        text_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. Special
            entities that appear in the task text.
        completed_by_user (:class:`telegram.User`): Optional. User that completed the task; omitted
            if the task wasn't completed
        completion_date (:class:`datetime.datetime`): Optional. Point in time when
            the task was completed; :attr:`~telegram.constants.ZERO_DATE` if the task wasn't
            completed

            |datetime_localization|
    )completed_by_usercompletion_dateidtexttext_entitiesN
api_kwargsr   r   r   r   r   r   c                   sF   t  j|d || _|| _t|| _|| _|| _| jf| _| 	  d S Nr   )
super__init__r   r   r
   r   r   r   	_id_attrs_freeze)selfr   r   r   r   r   r   	__class__ G/var/www/html/venv/lib/python3.10/site-packages/telegram/_checklists.pyr   Q   s   


zChecklistTask.__init__databotr   returnc                    sz   |  |}t|}|d }dkrt|d< nt||d|d< t|dt||d< t|dt||d< t	 j
||dS ),See :meth:`telegram.TelegramObject.de_json`.r   r   )tzinfor   r   r%   r&   )_parse_datar   getr   r   r   r   r	   r   r   de_json)clsr%   r&   
loc_tzinfodater!   r#   r$   r-   f   s   

zChecklistTask.de_jsonentityc                 C      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 ``ChecklistTask.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:`text_entities`.

        Returns:
            :obj:`str`: The text of the given entity.
        )r   r   r    r1   r#   r#   r$   parse_entityx      zChecklistTask.parse_entitytypesc                 C      t | j| j|S )a  
        Returns a :obj:`dict` that maps :class:`telegram.MessageEntity` to :obj:`str`.
        It contains entities from this checklist task 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.

        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    r6   r#   r#   r$   parse_entities      zChecklistTask.parse_entitiesNNNN)__name__
__module____qualname____doc__	__slots__intstrr   r   r   r   dtmdatetimer   r   classmethodr-   r4   listdictr9   __classcell__r#   r#   r!   r$   r   %   s2    #
",r   c                       s   e Zd ZdZdZ			ddddedee deee	  dee
 d	ee
 d
ee f fddZeddeded dd f fddZde	defddZddeee  dee	ef fddZ  ZS )	Checklista  
    Describes a checklist.

    Objects of this class are comparable in terms of equality.
    Two objects of this class are considered equal, if all their :attr:`tasks` are equal.

    .. versionadded:: 22.3

    Args:
        title (:obj:`str`): Title of the checklist.
        title_entities (Sequence[:class:`telegram.MessageEntity`], optional): Special
            entities that appear in the checklist title.
        tasks (Sequence[:class:`telegram.ChecklistTask`]): List of tasks in the checklist.
        others_can_add_tasks (:obj:`bool`, optional): :obj:`True` if users other than the creator
            of the list can add tasks to the list
        others_can_mark_tasks_as_done (:obj:`bool`, optional): :obj:`True` if users other than the
            creator of the list can mark tasks as done or not done

    Attributes:
        title (:obj:`str`): Title of the checklist.
        title_entities (Tuple[:class:`telegram.MessageEntity`]): Optional. Special
            entities that appear in the checklist title.
        tasks (Tuple[:class:`telegram.ChecklistTask`]): List of tasks in the checklist.
        others_can_add_tasks (:obj:`bool`): Optional. :obj:`True` if users other than the creator
            of the list can add tasks to the list
        others_can_mark_tasks_as_done (:obj:`bool`): Optional. :obj:`True` if users other than the
            creator of the list can mark tasks as done or not done
    )others_can_add_tasksothers_can_mark_tasks_as_donetaskstitletitle_entitiesNr   rN   rM   rO   rK   rL   r   c                   sJ   t  j|d || _t|| _t|| _|| _|| _| jf| _| 	  d S r   )
r   r   rN   r
   rO   rM   rK   rL   r   r   )r    rN   rM   rO   rK   rL   r   r!   r#   r$   r      s   



zChecklist.__init__r%   r&   r   r'   c                    sF   |  |}t|dt||d< t|dt||d< t j||dS )r(   rO   rM   r*   )r+   r	   r,   r   r   r   r-   )r.   r%   r&   r!   r#   r$   r-      s   
zChecklist.de_jsonr1   c                 C   r2   )a  Returns the text in :attr:`title`
        from a given :class:`telegram.MessageEntity` of :attr:`title_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 :attr:`title` 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:`title_entities`.

        Returns:
            :obj:`str`: The text of the given entity.
        )r   rN   r3   r#   r#   r$   r4      r5   zChecklist.parse_entityr6   c                 C   r7   )a  
        Returns a :obj:`dict` that maps :class:`telegram.MessageEntity` to :obj:`str`.
        It contains entities from this checklist's title 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:`title_entities`
            attribute, since it calculates the correct substring from the message text based on
            UTF-16 codepoints. See :attr:`parse_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   rN   rO   r8   r#   r#   r$   r9      r:   zChecklist.parse_entitiesr;   r<   )r=   r>   r?   r@   rA   rC   r   r   r   r   boolr   r   rF   r-   r4   rG   rH   r9   rI   r#   r#   r!   r$   rJ      s2    
"	,rJ   c                       s   e Zd ZdZdZ			dddded deee  deee  d	ee f fd
dZ	e
ddeded dd f fddZ  ZS )ChecklistTasksDonea  
    Describes a service message about checklist tasks marked as done or not done.

    Objects of this class are comparable in terms of equality.
    Two objects of this class are considered equal, if their :attr:`marked_as_done_task_ids` and
    :attr:`marked_as_not_done_task_ids` are equal.

    .. versionadded:: 22.3

    Args:
        checklist_message (:class:`telegram.Message`, optional): Message containing the checklist
            whose tasks were marked as done or not done. Note that the ~:class:`telegram.Message`
            object in this field will not contain the :attr:`~telegram.Message.reply_to_message`
            field even if it itself is a reply.
        marked_as_done_task_ids (Sequence[:obj:`int`], optional): Identifiers of the tasks that
            were marked as done
        marked_as_not_done_task_ids (Sequence[:obj:`int`], optional): Identifiers of the tasks that
            were marked as not done

    Attributes:
        checklist_message (:class:`telegram.Message`): Optional. Message containing the checklist
            whose tasks were marked as done or not done. Note that the ~:class:`telegram.Message`
            object in this field will not contain the :attr:`~telegram.Message.reply_to_message`
            field even if it itself is a reply.
        marked_as_done_task_ids (Tuple[:obj:`int`]): Optional. Identifiers of the tasks that were
            marked as done
        marked_as_not_done_task_ids (Tuple[:obj:`int`]): Optional. Identifiers of the tasks that
            were marked as not done
    )checklist_messagemarked_as_done_task_idsmarked_as_not_done_task_idsNr   rR   r   rS   rT   r   c                   sB   t  j|d || _t|| _t|| _| j| jf| _|   d S r   )r   r   rR   r
   rS   rT   r   r   )r    rR   rS   rT   r   r!   r#   r$   r   4  s   
zChecklistTasksDone.__init__r%   r&   r   r'   c                    s<   |  |}ddlm} t|d|||d< t j||dS )r(   r   r   rR   r*   )r+   telegramr   r   r,   r   r-   r.   r%   r&   r   r!   r#   r$   r-   G  s   
zChecklistTasksDone.de_jsonr;   r<   )r=   r>   r?   r@   rA   r   r   rB   r   r   rF   r-   rI   r#   r#   r!   r$   rQ     s&    

*rQ   c                	       sl   e Zd ZdZdZ	ddddee ded dee f fd	d
Z	e
ddeded dd f fddZ  ZS )ChecklistTasksAddedaX  
    Describes a service message about tasks added to a checklist.

    Objects of this class are comparable in terms of equality.
    Two objects of this class are considered equal, if their :attr:`tasks` are equal.

    .. versionadded:: 22.3

    Args:
        checklist_message (:class:`telegram.Message`, optional): Message containing the checklist
            to which tasks were added. Note that the ~:class:`telegram.Message`
            object in this field will not contain the :attr:`~telegram.Message.reply_to_message`
            field even if it itself is a reply.
        tasks (Sequence[:class:`telegram.ChecklistTask`]): List of tasks added to the checklist

    Attributes:
        checklist_message (:class:`telegram.Message`): Optional. Message containing the checklist
            to which tasks were added. Note that the ~:class:`telegram.Message`
            object in this field will not contain the :attr:`~telegram.Message.reply_to_message`
            field even if it itself is a reply.
        tasks (Tuple[:class:`telegram.ChecklistTask`]): List of tasks added to the checklist
    )rR   rM   Nr   rM   rR   r   r   c                   s4   t  j|d || _t|| _| jf| _|   d S r   )r   r   rR   r
   rM   r   r   )r    rM   rR   r   r!   r#   r$   r   n  s
   

zChecklistTasksAdded.__init__r%   r&   r   r'   c                    sT   |  |}ddlm} t|d|||d< t|dg ||d< t j||dS )r(   r   rU   rR   rM   r*   )	r+   rV   r   r   r,   r   de_listr   r-   rW   r!   r#   r$   r-   }  s
   
zChecklistTasksAdded.de_jsonr<   )r=   r>   r?   r@   rA   r   r   r   r   r   rF   r-   rI   r#   r#   r!   r$   rX   T  s    *rX   )#r@   rE   rD   collections.abcr   typingr   r   telegram._messageentityr   telegram._telegramobjectr   telegram._userr   telegram._utils.argumentparsingr   r	   r
   telegram._utils.datetimer   r   telegram._utils.entitiesr   r   telegram._utils.typesr   telegram.constantsr   rV   r   r   r   rJ   rQ   rX   r#   r#   r#   r$   <module>   s$   |nE