U
    ‰¾úgÎ  ã                   @   sp   d Z ddlmZmZmZ ddlmZ ddlmZ e	ee	dœdd„Z
de	ee eee	  eee	f d	œ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.
é    )ÚDictÚOptionalÚSequence)Ú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   Z	UTF_16_LEÚoffsetÚlengthÚdecode)r   r   Zentity_text© r   ú</tmp/pip-unpacked-wheel-swnnwir2/telegram/_utils/entities.pyÚparse_message_entity    s    
r   N)r   ÚentitiesÚtypesr	   c                    s"   ˆdk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 ˆkr|tˆ |ƒ“qS r   )Útyper   )Ú.0r   ©r   r   r   r   Ú
<dictcomp>F   s    
  z*parse_message_entities.<locals>.<dictcomp>)r   Z	ALL_TYPES)r   r   r   r   r   r   Úparse_message_entities0   s
    ÿr   )N)Ú__doc__Útypingr   r   r   Ztelegram._messageentityr   Ztelegram._utils.stringsr   Ústrr   r   r   r   r   r   Ú<module>   s    ÿ  

þ