o
    "h                      @   s   d Z ddlZddlmZm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 )zThis module contains classes that represent Telegram errors.

.. versionchanged:: 20.0
    Replaced ``Unauthorized`` by :class:`Forbidden`.
    N)OptionalUnion)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__ A/var/www/html/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__I   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__Q   s   zTelegramError.__repr__c                 C      | j | jffS )zDefines how to serialize the exception for pickle.

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

        Returns:
            :obj:`tuple`
        r   r   r   r   r   r   
__reduce__Y   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   zRaised 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   e   s    	r   c                       4   e Zd ZdZdZddee ddf fddZ  ZS )	r   zRaised 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   r   r   s    $r   c                   @   r.   )r
   zRaised 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                       r0   )	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 outr1   r2   r   r   r   r      s   zTimedOut.__init__r3   r4   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_idr5   c                    s   t  d|  || _d S )Nz+Group migrated to supergroup. New chat id: )r   r   r5   )r   r5   r   r   r   r      s   
zChatMigrated.__init__r   c                 C   r#   r3   )r   r5   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	e
jf 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   r8   
isinstancer9   r7   r   r   )r   r9   r   r   r   r      s   
zRetryAfter.__init__r   c                 C   s   t | jddS )Nr9   )	attribute)r   r8   r   r   r   r   r9      s   zRetryAfter.retry_afterc                 C   s   | j t| j ffS r3   )r   r7   r8   total_secondsr   r   r   r   r%      s   zRetryAfter.__reduce__)r!   r&   r'   r(   r)   r   r   propertyr   r7   dtm	timedeltar9   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#   r3   r$   r   r   r   r   r%     r6   zConflict.__reduce__N)	r!   r&   r'   r(   r)   r+   r,   r*   r%   r   r   r   r   r	      s    r	   c                       sL   e Zd ZdZdZdeeef f fddZde	e
e	e f fddZ  ZS )	r   zSomething 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*   rA   r2   r   r   r   r     s   z PassportDecryptionError.__init__r   c                 C   r#   r3   )r   rA   r   r   r   r   r%     r6   z"PassportDecryptionError.__reduce__)r!   r&   r'   r(   r)   r   r*   	Exceptionr   r+   r,   r%   r-   r   r   r   r   r     s
    "r   )r(   datetimer>   typingr   r   telegram._utils.argumentparsingr   telegram._utils.datetimer   telegram._utils.typesr   __all__rB   r   r   r   r
   r   r   r   r   r   r	   r   r   r   r   r   <module>   s$   6
.	