o
    Zzjc   ã                   @   sè   d Z ddlZddlmZ ddlmZ ddlmZ d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G dd„ deƒ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G dd„ deƒZG dd„ deƒZdS )zŒThis module contains classes that represent Telegram errors.

.. versionchanged:: 20.0
    Replaced ``Unauthorized`` by :class:`Forbidden`.
é    N)Úto_timedelta)Úget_timedelta_value)Ú
TimePeriod)Ú
BadRequestÚChatMigratedÚConflictÚEndPointNotFoundÚ	ForbiddenÚInvalidTokenÚNetworkErrorÚPassportDecryptionErrorÚ
RetryAfterÚTelegramErrorÚTimedOutc                       s`   e Zd ZdZdZdef‡ fdd„Zdefdd„Zdefd	d
„Zde	e
e	e f fdd„Z‡  ZS )r   a  
    Base class for Telegram errors.

    Tip:
        Objects of this type can be serialized via Python's :mod:`pickle` module and pickled
        objects from one version of PTB are usually loadable in future versions. However, we can
        not guarantee that this compatibility will always be provided. At least a manual one-time
        conversion of the data may be needed on major updates of the library.

    .. seealso:: :wiki:`Exceptions, Warnings and Logging <Exceptions%2C-Warnings-and-Logging>`
    ©Úmessager   c                    sB   t ƒ  ¡  | d¡}| d¡}| d¡}||kr| ¡ }|| _d S )NzError: z	[Error]: zBad Request: )ÚsuperÚ__init__ÚremoveprefixÚ
capitalizer   )Úselfr   Úmsg©Ú	__class__© úI/var/www/kodo/tsheker/venv/lib/python3.10/site-packages/telegram/error.pyr   =   s   




zTelegramError.__init__Úreturnc                 C   s   | j S )zgGives the string representation of exceptions message.

        Returns:
           :obj:`str`
        r   ©r   r   r   r   Ú__str__H   s   zTelegramError.__str__c                 C   s   | j j› d| j› d�S )zmGives an unambiguous string representation of the exception.

        Returns:
           :obj:`str`
        z('z'))r   Ú__name__r   r   r   r   r   Ú__repr__P   s   zTelegramError.__repr__c                 C   ó   | j | jffS )z¸Defines how to serialize the exception for pickle.

        .. seealso::
               :py:meth:`object.__reduce__`, :mod:`pickle`.

        Returns:
            :obj:`tuple`
        ©r   r   r   r   r   r   Ú
__reduce__X   s   	zTelegramError.__reduce__)r   Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__Ústrr   r   r    ÚtupleÚtyper#   Ú__classcell__r   r   r   r   r   .   s    "r   c                   @   ó   e Zd ZdZdZdS )r	   zæRaised when the bot has not enough rights to perform the requested action.

    Examples:
        :any:`Raw API Bot <examples.rawapibot>`

    .. versionchanged:: 20.0
        This class was previously named ``Unauthorized``.
    r   N©r   r$   r%   r&   r'   r   r   r   r   r	   d   s    	r	   c                       ó4   e Zd ZdZdZddedB ddf‡ fdd„Z‡  ZS )	r
   z­Raised when the token is invalid.

    Args:
        message (:obj:`str`, optional): Any additional information about the exception.

            .. versionadded:: 20.0
    r   Nr   r   c                    s"   t ƒ  |d u rd¡ d S |¡ d S )NzInvalid token©r   r   ©r   r   r   r   r   r   |   s   "zInvalidToken.__init__©N©r   r$   r%   r&   r'   r(   r   r+   r   r   r   r   r
   q   s    $r
   c                   @   r,   )r   zŒRaised when the requested endpoint is not found. Only relevant for
    :meth:`telegram.Bot.do_api_request`.

    .. versionadded:: 20.8
    r   Nr-   r   r   r   r   r   €   s    r   c                   @   r,   )r   af  Base class for exceptions due to networking errors.

    Tip:
        This exception (and its subclasses) usually originates from the networking backend
        used by :class:`~telegram.request.HTTPXRequest`, or a custom implementation of
        :class:`~telegram.request.BaseRequest`. In this case, the original exception can be
        accessed via the ``__cause__``
        `attribute <https://docs.python.org/3/library/exceptions.html#exception-context>`_.

    Examples:
        :any:`Raw API Bot <examples.rawapibot>`

    .. seealso::
        :wiki:`Handling network errors <Handling-network-errors>`
    r   Nr-   r   r   r   r   r   Š   s    r   c                   @   r,   )r   z=Raised when Telegram could not process the request correctly.r   Nr-   r   r   r   r   r   ž   s    r   c                       r.   )	r   a  Raised when a request took too long to finish.

    .. seealso::
        :wiki:`Handling network errors <Handling-network-errors>`

    Args:
        message (:obj:`str`, optional): Any additional information about the exception.

            .. versionadded:: 20.0
    r   Nr   r   c                    s   t ƒ  |pd¡ d S )Nz	Timed outr/   r0   r   r   r   r   ²   s   zTimedOut.__init__r1   r2   r   r   r   r   r   ¤   s    $r   c                       sD   e Zd ZdZdZdef‡ fdd„Zdeeee f fdd„Z	‡  Z
S )	r   ao  
    Raised when the requested group chat migrated to supergroup and has a new chat id.

    .. seealso::
        :wiki:`Storing Bot, User and Chat Related Data <Storing-bot%2C-user-and-chat-related-data>`

    Args:
        new_chat_id (:obj:`int`): The new chat id of the group.

    Attributes:
        new_chat_id (:obj:`int`): The new chat id of the group.

    )Únew_chat_idr3   c                    s   t ƒ  d|› �¡ || _d S )Nz+Group migrated to supergroup. New chat id: )r   r   r3   )r   r3   r   r   r   r   Ç   s   
zChatMigrated.__init__r   c                 C   r!   r1   )r   r3   r   r   r   r   r#   Ë   ó   zChatMigrated.__reduce__)r   r$   r%   r&   r'   Úintr   r)   r*   r#   r+   r   r   r   r   r   ¶   s
    "r   c                       s\   e Zd ZdZdZdef‡ fdd„Zedee	j
B fdd„ƒZdeeee f fd	d
„Z‡  ZS )r   aa  
    Raised when flood limits where exceeded.

    .. versionchanged:: 20.0
       :attr:`retry_after` is now an integer to comply with the Bot API.

    Args:
        retry_after (:obj:`int` | :class:`datetime.timedelta`): Time in seconds, after which the
            bot can retry the request.

            .. versionchanged:: v22.2
                |time-period-input|

    Attributes:
        retry_after (:obj:`int` | :class:`datetime.timedelta`): Time in seconds, after which the
            bot can retry the request.

            .. deprecated:: v22.2
                |time-period-int-deprecated|

    )Ú_retry_afterÚretry_afterc                    sH   t |ƒ| _t| jtƒrtƒ  d| j› d�¡ d S tƒ  d| j›�¡ d S )Nz!Flood control exceeded. Retry in z seconds)r   r6   Ú
isinstancer7   r5   r   r   )r   r7   r   r   r   r   è   s   
zRetryAfter.__init__r   c                 C   s   t | jdd�S )Nr7   )Ú	attribute)r   r6   r   r   r   r   r7   ð   s   ÿzRetryAfter.retry_afterc                 C   s   | j t| j ¡ ƒffS r1   )r   r5   r6   Útotal_secondsr   r   r   r   r#   ÷   s   zRetryAfter.__reduce__)r   r$   r%   r&   r'   r   r   Úpropertyr5   ÚdtmÚ	timedeltar7   r)   r*   Úfloatr#   r+   r   r   r   r   r   Ï   s    "r   c                   @   s.   e Zd ZdZdZdeeee f fdd„ZdS )r   z>Raised when a long poll or webhook conflicts with another one.r   r   c                 C   r!   r1   r"   r   r   r   r   r#     r4   zConflict.__reduce__N)	r   r$   r%   r&   r'   r)   r*   r(   r#   r   r   r   r   r   ý   s    r   c                       sH   e Zd ZdZdZdeeB f‡ fdd„Zdee	ee f fdd„Z
‡  ZS )	r   zÐSomething went wrong with decryption.

    .. versionchanged:: 20.0
        This class was previously named ``TelegramDecryptionError`` and was available via
        ``telegram.TelegramDecryptionError``.
    )Ú_msgr   c                    s    t ƒ  d|› �¡ t|ƒ| _d S )NzPassportDecryptionError: )r   r   r(   r?   r0   r   r   r   r     s   z PassportDecryptionError.__init__r   c                 C   r!   r1   )r   r?   r   r   r   r   r#     r4   z"PassportDecryptionError.__reduce__)r   r$   r%   r&   r'   r(   Ú	Exceptionr   r)   r*   r#   r+   r   r   r   r   r     s
    "r   )r&   Údatetimer<   Útelegram._utils.argumentparsingr   Útelegram._utils.datetimer   Útelegram._utils.typesr   Ú__all__r@   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   Ú<module>   s"   6
.	