Ë
    †jHR  ã                   óÐ   — d Z ddlZddl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 dd	lmZ dd
lmZmZ ddlmZ ddlmZ erddl
mZ ed   Z G d„ de«      Zy)zHThis module contains an object that represents a Telegram MessageEntity.é    N)ÚSequence)ÚTYPE_CHECKINGÚFinal)Ú	constants)ÚTelegramObject)ÚUser)Úenum)Úde_json_optional)Úextract_tzinfo_from_defaultsÚfrom_timestamp)ÚTextEncoding)ÚJSONDict)ÚBotÚMessageEntityc                   ó\  ‡ — e Zd ZU dZdZ	 	 	 	 	 	 d1ddœdededededz  d	edz  d
edz  dedz  dedz  dej                  dz  de
dz  fˆ fd„Zed2de
dddd fˆ fd„«       Zedededefd„«       Zedeez  dedefd„«       Zedeeef   eeeef   z  deeef   fd„«       Z eej.                  «      Zeee      ed<   	 ej.                  j6                  Zee   ed<   	 ej.                  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.                  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)<   	 ej.                  jP                  Z(ee   ed*<   	 ej.                  jR                  Z)ee   ed+<   	 ej.                  jT                  Z*ee   ed,<   	 ej.                  jV                  Z+ee   ed-<   	 ej.                  jX                  Z,ee   ed.<   	 ej.                  jZ                  Z-ee   ed/<   	 ej.                  j\                  Z.ee   ed0<   ˆ xZ/S )3r   aˆ  
    This object represents one special entity in a text message. For example, hashtags,
    usernames, URLs, etc.

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

    Args:
        type (:obj:`str`): Type of the entity. Can be :attr:`MENTION` (``@username``),
            :attr:`HASHTAG` (``#hashtag`` or ``#hashtag@chatusername``), :attr:`CASHTAG` (``$USD``
            or ``USD@chatusername``), :attr:`BOT_COMMAND` (``/start@jobs_bot``), :attr:`URL`
            (``https://telegram.org``), :attr:`EMAIL` (``do-not-reply@telegram.org``),
            :attr:`PHONE_NUMBER` (``+1-212-555-0123``),
            :attr:`BOLD` (**bold text**), :attr:`ITALIC` (*italic text*), :attr:`UNDERLINE`
            (underlined text), :attr:`STRIKETHROUGH`, :attr:`SPOILER` (spoiler message),
            :attr:`BLOCKQUOTE` (block quotation), :attr:`CODE` (monowidth string), :attr:`PRE`
            (monowidth block), :attr:`TEXT_LINK` (for clickable text URLs), :attr:`TEXT_MENTION`
            (for users without usernames), :attr:`CUSTOM_EMOJI` (for inline custom emoji stickers)
            or :attr:`DATE_TIME` (for formatted date and time).

            .. versionadded:: 20.0
                Added inline custom emoji

            .. versionadded:: 20.8
                Added block quotation

            .. versionadded:: 22.7
                Added date_time
        offset (:obj:`int`): Offset in UTF-16 code units to the start of the entity.
        length (:obj:`int`): Length of the entity in UTF-16 code units.
        url (:obj:`str`, optional): For :attr:`TEXT_LINK` only, url that will be opened after
            user taps on the text.
        user (:class:`telegram.User`, optional): For :attr:`TEXT_MENTION` only, the mentioned
             user.
        language (:obj:`str`, optional): For :attr:`PRE` only, the programming language of
            the entity text.
        custom_emoji_id (:obj:`str`, optional): For :attr:`CUSTOM_EMOJI` only, unique identifier
            of the custom emoji. Use :meth:`telegram.Bot.get_custom_emoji_stickers` to get full
            information about the sticker.

            .. versionadded:: 20.0
        date_time_format (:obj:`str`, optional): For :attr:`DATE_TIME` only, the string that
            defines the formatting of the date and time. See `date-time entity formatting
            <https://core.telegram.org/bots/api#date-time-entity-formatting>`_ for more details and
            :class:`telegram.constants.MessageEntityDateTimeFormats` for all possible formats.

            .. versionadded:: 22.7
        unix_time (:class:`datetime.datetime`, optional): For :attr:`DATE_TIME` only, the time
            associated with the entity.
            |datetime_localization|

            .. versionadded:: 22.7
    Attributes:
        type (:obj:`str`): Type of the entity.  Can be :attr:`MENTION` (``@username``),
            :attr:`HASHTAG` (``#hashtag`` or ``#hashtag@chatusername``), :attr:`CASHTAG` (``$USD``
            or ``USD@chatusername``), :attr:`BOT_COMMAND` (``/start@jobs_bot``), :attr:`URL`
            (``https://telegram.org``), :attr:`EMAIL` (``do-not-reply@telegram.org``),
            :attr:`PHONE_NUMBER` (``+1-212-555-0123``),
            :attr:`BOLD` (**bold text**), :attr:`ITALIC` (*italic text*), :attr:`UNDERLINE`
            (underlined text), :attr:`STRIKETHROUGH`, :attr:`SPOILER` (spoiler message),
            :attr:`BLOCKQUOTE` (block quotation), :attr:`CODE` (monowidth string), :attr:`PRE`
            (monowidth block), :attr:`TEXT_LINK` (for clickable text URLs), :attr:`TEXT_MENTION`
            (for users without usernames), :attr:`CUSTOM_EMOJI` (for inline custom emoji stickers)
            or :attr:`DATE_TIME` (for formatted date and time).

            .. versionadded:: 20.0
                Added inline custom emoji

            .. versionadded:: 20.8
                Added block quotation

            .. versionadded:: 22.7
                Added date_time
        offset (:obj:`int`): Offset in UTF-16 code units to the start of the entity.
        length (:obj:`int`): Length of the entity in UTF-16 code units.
        url (:obj:`str`): Optional. For :attr:`TEXT_LINK` only, url that will be opened after
            user taps on the text.
        user (:class:`telegram.User`): Optional. For :attr:`TEXT_MENTION` only, the mentioned
             user.
        language (:obj:`str`): Optional. For :attr:`PRE` only, the programming language of
            the entity text.
        custom_emoji_id (:obj:`str`): Optional. For :attr:`CUSTOM_EMOJI` only, unique identifier
            of the custom emoji. Use :meth:`telegram.Bot.get_custom_emoji_stickers` to get full
            information about the sticker.

            .. versionadded:: 20.0
        date_time_format (:obj:`str`): Optional. For :attr:`DATE_TIME` only, the string that
            defines the formatting of the date and time. See `date-time entity formatting
            <https://core.telegram.org/bots/api#date-time-entity-formatting>`_ for more details and
            :class:`telegram.constants.MessageEntityDateTimeFormats` for all possible formats.

            .. versionadded:: 22.7
        unix_time (:class:`datetime.datetime`): Optional. For :attr:`DATE_TIME` only, the time
            associated with the entity.
            |datetime_localization|

            .. versionadded:: 22.7

    )	Úcustom_emoji_idÚdate_time_formatÚlanguageÚlengthÚoffsetÚtypeÚ	unix_timeÚurlÚuserN©Ú
api_kwargsr   r   r   r   r   r   r   r   r   r   c
                óZ  •— t         ‰| �  |
¬«       t        j                  t        j
                  ||«      | _        || _        || _        || _	        || _
        || _        || _        || _        |	| _        | j                  | j                  | j                  f| _        | j!                  «        y )Nr   )ÚsuperÚ__init__r	   Ú
get_memberr   ÚMessageEntityTyper   r   r   r   r   r   r   r   r   Ú	_id_attrsÚ_freeze)Úselfr   r   r   r   r   r   r   r   r   r   Ú	__class__s              €úV/var/www/html/datingFans/myenv/lib/python3.12/site-packages/telegram/_messageentity.pyr   zMessageEntity.__init__›   sŒ   ø€ ô 	‰Ñ JÐÔ/äŸ™¬×)DÑ)DÀdÈDÓQˆŒ	Ø!ˆŒØ!ˆŒà"ˆŒØ!%ˆŒ	Ø$,ˆŒØ+:ˆÔØ,<ˆÔØ.7ˆŒàŸ)™) T§[¡[°$·+±+Ð>ˆŒà�‰�ó    ÚdataÚbotz
Bot | NoneÚreturnc                 óâ   •— | j                  |«      }t        |j                  d«      t        |«      |d<   t	        |«      }t        |j                  d«      |¬«      |d<   t        ‰| �  ||¬«      S )z,See :meth:`telegram.TelegramObject.de_json`.r   r   )Útzinfo)r(   r)   )Ú_parse_datar
   Úgetr   r   r   r   Úde_json)Úclsr(   r)   Ú
loc_tzinfor%   s       €r&   r/   zMessageEntity.de_jsonº   sg   ø€ ð �‰˜tÓ$ˆä'¨¯©°Ó(8¼$ÀÓDˆˆV‰ô 2°#Ó6ˆ
Ü*¨4¯8©8°KÓ+@ÈÔTˆˆ[Ñä‰w‰ D¨cˆÓ2Ð2r'   ÚtextÚentitiesc                 ó&  — t        t        j                  d„ |D «       Ž «      }d}i }t        |«      D ]L  \  }}|dkD  r||dz
     nd}| || }|t	        |j                  t        j                  «      «      dz  z  }|||<   ŒN g }	|D ]}  }
||
j                     }||
j                  |
j                  z      |z
  }t        j                  |
«      }|j                  «       5  ||_        ||_	        ddd«       |	j                  |«       Œ |	S # 1 sw Y   ŒxY w)uÁ  Utility functionality for converting the offset and length of entities from
        Unicode (:obj:`str`) to UTF-16 (``utf-16-le`` encoded :obj:`bytes`).

        Tip:
            Only the offsets and lengths calulated in UTF-16 is acceptable by the Telegram Bot API.
            If they are calculated using the Unicode string (:obj:`str` object), errors may occur
            when the text contains characters that are not in the Basic Multilingual Plane (BMP).
            For more information, see `Unicode <https://en.wikipedia.org/wiki/Unicode>`_ and
            `Plane (Unicode) <https://en.wikipedia.org/wiki/Plane_(Unicode)>`_.

        .. versionadded:: 21.4

        Examples:
            Below is a snippet of code that demonstrates how to use this function to convert
            entities from Unicode to UTF-16 space. The ``unicode_entities`` are calculated in
            Unicode and the `utf_16_entities` are calculated in UTF-16.

            .. code-block:: python

                text = "ð Œ• bold ð�„¢ italic underlined: ð�›™ð�Œ¢ð‘��"
                unicode_entities = [
                    MessageEntity(offset=2, length=4, type=MessageEntity.BOLD),
                    MessageEntity(offset=9, length=6, type=MessageEntity.ITALIC),
                    MessageEntity(offset=28, length=3, type=MessageEntity.UNDERLINE),
                ]
                utf_16_entities = MessageEntity.adjust_message_entities_to_utf_16(
                    text, unicode_entities
                )
                await bot.send_message(
                    chat_id=123,
                    text=text,
                    entities=utf_16_entities,
                )
                # utf_16_entities[0]: offset=3, length=4
                # utf_16_entities[1]: offset=11, length=6
                # utf_16_entities[2]: offset=30, length=6

        Args:
            text (:obj:`str`): The text that the entities belong to
            entities (Sequence[:class:`telegram.MessageEntity`]): Sequence of entities
                with offset and length calculated in Unicode

        Returns:
            Sequence[:class:`telegram.MessageEntity`]: Sequence of entities
            with offset and length calculated in UTF-16 encoding
        c              3   óf   K  — | ])  }|j                   |j                   |j                  z   f–— Œ+ y ­w©N)r   r   )Ú.0Úxs     r&   ú	<genexpr>zBMessageEntity.adjust_message_entities_to_utf_16.<locals>.<genexpr>ø   s'   è ø€ Ò,_ÐQR¨a¯h©h¸¿¹À1Ç8Á8Ñ8KÔ-LÑ,_ùs   ‚/1r   é   é   N)ÚsortedÚ	itertoolsÚchainÚ	enumerateÚlenÚencoder   Ú	UTF_16_LEr   r   ÚcopyÚ	_unfrozenÚappend)r2   r3   Ú	positionsÚaccumulated_lengthÚposition_translationÚiÚpositionÚlast_positionÚ
text_sliceÚoutÚentityÚtranslated_positionsÚtranslated_lengthÚ
new_entitys                 r&   Ú!adjust_message_entities_to_utf_16z/MessageEntity.adjust_message_entities_to_utf_16Ç   s6  € ôb œ9Ÿ?™?Ñ,_ÐV^Ô,_Ð`Óaˆ	ØÐð 02ÐÜ$ YÓ/ò 	@‰KˆAˆxØ01°A²˜I a¨!¡eÒ,¸1ˆMØ˜m¨HÐ5ˆJØ¤# j×&7Ñ&7¼×8NÑ8NÓ&OÓ"PÐTUÑ"UÑUÐØ-?Ð  Ò*ð		@ð ˆØò 		#ˆFØ#7¸¿¹Ñ#FÐ à$ V§]¡]°V·]±]Ñ%BÑCÐFZÑZð ô Ÿ™ 6Ó*ˆJØ×%Ñ%Ó'ñ 6Ø$8�
Ô!Ø$5�
Ô!÷6ð �J‰J�zÕ"ð		#ð ˆ
÷	6ð 6ús   ÃDÄD	Úbyc                 ó6  — t        | t        «      r| nt        | j                  d«      «      dz  }g }|D ]V  }t	        j                  |«      }|j                  «       5  |xj                  |z  c_        ddd«       |j                  |«       ŒX |S # 1 sw Y   ŒxY w)už  Utility functionality for shifting the offset of entities by a given amount.

        Examples:
            Shifting by an integer amount:

            .. code-block:: python

                text = "Hello, world!"
                entities = [
                    MessageEntity(offset=0, length=5, type=MessageEntity.BOLD),
                    MessageEntity(offset=7, length=5, type=MessageEntity.ITALIC),
                ]
                shifted_entities = MessageEntity.shift_entities(1, entities)
                await bot.send_message(
                    chat_id=123,
                    text="!" + text,
                    entities=shifted_entities,
                )

            Shifting using a string:

            .. code-block:: python

                text = "Hello, world!"
                prefix = "ð�„¢"
                entities = [
                    MessageEntity(offset=0, length=5, type=MessageEntity.BOLD),
                    MessageEntity(offset=7, length=5, type=MessageEntity.ITALIC),
                ]
                shifted_entities = MessageEntity.shift_entities(prefix, entities)
                await bot.send_message(
                    chat_id=123,
                    text=prefix + text,
                    entities=shifted_entities,
                )

        Tip:
            The :paramref:`entities` are *not* modified in place. The function returns a sequence
            of new objects.

        .. versionadded:: 21.5

        Args:
            by (:obj:`str` | :obj:`int`): Either the amount to shift the offset by or
                a string whose length will be used as the amount to shift the offset by. In this
                case, UTF-16 encoding will be used to calculate the length.
            entities (Sequence[:class:`telegram.MessageEntity`]): Sequence of entities

        Returns:
            Sequence[:class:`telegram.MessageEntity`]: Sequence of entities with the offset shifted
        z	utf-16-ler;   N)Ú
isinstanceÚintr@   rA   rC   rD   r   rE   )rS   r3   Úeffective_shiftrM   rN   rQ   s         r&   Úshift_entitieszMessageEntity.shift_entities  s�   € ôj !+¨2¬sÔ 3™"¼¸R¿Y¹YÀ{Ó=SÓ9TÐXYÑ9YˆàˆØò 	#ˆFÜŸ™ 6Ó*ˆJØ×%Ñ%Ó'ñ 5Ø×!Ò! _Ñ4Õ!÷5à�J‰J�zÕ"ð		#ð
 ˆ
÷5ð 5ús   ÁBÂB	Úargsc                 óÎ   — d}g }|D ]Y  }|d   |d   }}t        |«      dkD  r|d   du r| j                  ||«      }|j                  | j                  ||«      «       ||z  }Œ[ ||fS )uó
  Utility functionality for concatenating two text along with their formatting entities.

        Tip:
            This function is useful for prefixing an already formatted text with a new text and its
            formatting entities. In particular, it automatically correctly handles UTF-16 encoding.

        Examples:
            This example shows a callback function that can be used to add a prefix and suffix to
            the message in a :class:`~telegram.ext.CallbackQueryHandler`:

            .. code-block:: python

                async def prefix_message(update: Update, context: ContextTypes.DEFAULT_TYPE):
                    prefix = "ð Œ• bold ð�„¢ italic underlined: ð�›™ð�Œ¢ð‘�� | "
                    prefix_entities = [
                        MessageEntity(offset=2, length=4, type=MessageEntity.BOLD),
                        MessageEntity(offset=9, length=6, type=MessageEntity.ITALIC),
                        MessageEntity(offset=28, length=3, type=MessageEntity.UNDERLINE),
                    ]
                    suffix = " | ð Œ• bold ð�„¢ italic underlined: ð�›™ð�Œ¢ð‘��"
                    suffix_entities = [
                        MessageEntity(offset=5, length=4, type=MessageEntity.BOLD),
                        MessageEntity(offset=12, length=6, type=MessageEntity.ITALIC),
                        MessageEntity(offset=31, length=3, type=MessageEntity.UNDERLINE),
                    ]

                    message = update.effective_message
                    first = (prefix, prefix_entities, True)
                    second = (message.text, message.entities)
                    third = (suffix, suffix_entities, True)

                    new_text, new_entities = MessageEntity.concatenate(first, second, third)
                    await update.callback_query.edit_message_text(
                        text=new_text,
                        entities=new_entities,
                    )

        Hint:
            The entities are *not* modified in place. The function returns a
            new sequence of objects.

        .. versionadded:: 21.5

        Args:
            *args (tuple[:obj:`str`, Sequence[:class:`telegram.MessageEntity`]] |                 tuple[:obj:`str`, Sequence[:class:`telegram.MessageEntity`], :obj:`bool`]):
                Arbitrary number of tuples containing the text and its entities to concatenate.
                If the last element of the tuple is a :obj:`bool`, it is used to determine whether
                to adjust the entities to UTF-16 via
                :meth:`adjust_message_entities_to_utf_16`. UTF-16 adjustment is disabled by
                default.

        Returns:
            tuple[:obj:`str`, Sequence[:class:`telegram.MessageEntity`]]: The concatenated text
            and its entities
        Ú r   r:   r;   T)r@   rR   ÚextendrX   )r0   rY   Úoutput_textÚoutput_entitiesÚargr2   r3   s          r&   ÚconcatenatezMessageEntity.concatenateO  sˆ   € ðz ˆØ/1ˆØò 	 ˆCØ  ™V S¨¡V�(ˆDä�3‹x˜!Š|  A¡¨$¡Ø×@Ñ@ÀÀxÓP�à×"Ñ" 3×#5Ñ#5°kÀ8Ó#LÔMØ˜4Ñ‰Kð	 ð ˜OÐ+Ð+r'   Ú	ALL_TYPESÚ
BLOCKQUOTEÚBOLDÚBOT_COMMANDÚCASHTAGÚCODEÚCUSTOM_EMOJIÚ	DATE_TIMEÚEMAILÚEXPANDABLE_BLOCKQUOTEÚHASHTAGÚITALICÚMENTIONÚPHONE_NUMBERÚPREÚSPOILERÚSTRIKETHROUGHÚ	TEXT_LINKÚTEXT_MENTIONÚ	UNDERLINEÚURL)NNNNNNr6   )0Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__ÚstrrV   r   ÚdtmÚdatetimer   r   Úclassmethodr/   ÚstaticmethodÚ_SEMrR   rX   ÚtupleÚboolr`   Úlistr   r!   ra   r   Ú__annotations__rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   Ú__classcell__)r%   s   @r&   r   r   *   s  ø… ñbðH
€Ið" Ø Ø#Ø&*Ø'+Ø)-ðð '+òàðð ðð ð	ð
 �4‰Zðð �T‰kðð ˜‘*ðð ˜t™ðð  ™*ðð —<‘< $Ñ&ðð ˜t‘Oõð> ñ
3˜8ð 
3¨,ð 
3À/ô 
3ó ð
3ð ðF°ð F¸tð FÈò Fó ðFðP ð<˜3 ™9ð <°ð <¸ò <ó ð<ð| ðG,à�S˜$�YÑ %¨¨T°4¨Ñ"8Ñ8ðG,ð 
ˆs�DˆyÑ	òG,ó ðG,ñR #' y×'BÑ'BÓ"C€Iˆu�T˜#‘YÑÓCØIØ&×8Ñ8×CÑC€J��c‘
ÓCðð !×2Ñ2×7Ñ7€Dˆ%�‰*Ó7Ø<Ø'×9Ñ9×EÑE€K��s‘ÓEØCØ#×5Ñ5×=Ñ=€GˆU�3‰ZÓ=Ø?Ø ×2Ñ2×7Ñ7€Dˆ%�‰*Ó7Ø<Ø(×:Ñ:×GÑG€L�%˜‘*ÓGðð &×7Ñ7×AÑA€Iˆu�S‰zÓAðð "×3Ñ3×9Ñ9€Eˆ5�‰:Ó9Ø=Ø(1×(CÑ(C×(YÑ(YÐ˜5 ™:ÓYðð $×5Ñ5×=Ñ=€GˆU�3‰ZÓ=Ø?Ø"×4Ñ4×;Ñ;€FˆE�#‰JÓ;Ø>Ø#×5Ñ5×=Ñ=€GˆU�3‰ZÓ=Ø?Ø(×:Ñ:×GÑG€L�%˜‘*ÓGØDØ×1Ñ1×5Ñ5€Cˆˆs‰Ó5Ø;Ø#×5Ñ5×=Ñ=€GˆU�3‰ZÓ=ðð !*× ;Ñ ;× IÑ I€M�5˜‘:ÓIØEØ%×7Ñ7×AÑA€Iˆu�S‰zÓAØAØ(×:Ñ:×GÑG€L�%˜‘*ÓGØDØ%×7Ñ7×AÑA€Iˆu�S‰zÓAØAØ×1Ñ1×5Ñ5€Cˆˆs‰Ó5Û;r'   )ry   rC   r}   r|   r=   Úcollections.abcr   Útypingr   r   Útelegramr   Útelegram._telegramobjectr   Útelegram._userr   Útelegram._utilsr	   Útelegram._utils.argumentparsingr
   Útelegram._utils.datetimer   r   Útelegram._utils.stringsr   Útelegram._utils.typesr   r   r€   r   © r'   r&   ú<module>r‘      sP   ðñ& Oã Û Û Ý $ß 'å Ý 3Ý Ý  Ý <ß QÝ 0Ý *áÝà�Ñ €ôg<�Nõ g<r'   