o
    "h                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ de	dede	fd	d
Z
	dde	dee deee	  deee	f fddZdS )a.  This module contains auxiliary functionality for parsing MessageEntity objects.

Warning:
    Contents of this module are intended to be used internally by the library and *not* by the
    user. Changes to this module are not considered breaking changes and may not be documented in
    the changelog.
    )Sequence)Optional)MessageEntity)TextEncodingtextentityreturnc                 C   s6   |  tj}||jd |j|j d  }|tjS )a%  Returns the text from a given :class:`telegram.MessageEntity`.

    Args:
        text (:obj:`str`): The text to extract the entity from.
        entity (:class:`telegram.MessageEntity`): The entity to extract the text from.

    Returns:
        :obj:`str`: The text of the given entity.
       )encoder   	UTF_16_LEoffsetlengthdecode)r   r   entity_text r   K/var/www/html/venv/lib/python3.10/site-packages/telegram/_utils/entities.pyparse_message_entity!   s   
r   Nentitiestypesc                    s"   du rt j fdd|D S )aS  
    Returns a :obj:`dict` that maps :class:`telegram.MessageEntity` to :obj:`str`.
    It contains entities filtered by their ``type`` attribute as
    the key, and the text that each entity belongs to as the value of the :obj:`dict`.

    Args:
        text (:obj:`str`): The text to extract the entity from.
        entities (list[:class:`telegram.MessageEntity`]): The entities to extract the text from.
        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 v r|t |qS r   )typer   ).0r   r   r   r   r   
<dictcomp>G   s    z*parse_message_entities.<locals>.<dictcomp>)r   	ALL_TYPES)r   r   r   r   r   r   parse_message_entities1   s
   r   )N)__doc__collections.abcr   typingr   telegram._messageentityr   telegram._utils.stringsr   strr   dictr   r   r   r   r   <module>   s    

