
    ic                      n   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e
          Z G d	 d
e          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          ZdS )zThis 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                   l     e Zd ZdZdZdef fdZdefdZdefdZde	e
e	e         f         fdZ x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                    t                                                       |                    d          }|                    d          }|                    d          }||k    r|                                }|| _        d S )NzError: z	[Error]: zBad Request: )super__init__removeprefix
capitalizer   )selfr   msg	__class__s      N/Users/shanyulin/my-agent/.venv/lib/python3.11/site-packages/telegram/error.pyr   zTelegramError.__init__=   su    ""9--{++//'>>..""C    returnc                     | j         S )zgGives the string representation of exceptions message.

        Returns:
           :obj:`str`
        r   r   s    r   __str__zTelegramError.__str__H   s     |r   c                 0    | j         j         d| j         dS )zmGives an unambiguous string representation of the exception.

        Returns:
           :obj:`str`
        z('z'))r   __name__r   r    s    r   __repr__zTelegramError.__repr__P   s"     .)==T\====r   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    s    r   
__reduce__zTelegramError.__reduce__X   s     ~..r   )r#   
__module____qualname____doc__	__slots__strr   r!   r$   tupletyper'   __classcell__r   s   @r   r   r   .   s        
 
 I	  	  	  	  	  	  	     ># > > > >	/E$c
"23 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/r   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``.
     Nr#   r(   r)   r*   r+   r2   r   r   r
   r
   d   s          IIIr   r
   c                   8     e Zd ZdZdZddedz  ddf fdZ xZS )r   zRaised when the token is invalid.

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

            .. versionadded:: 20.0
    r2   Nr   r   c                 R    t                                          |dn|           d S )NzInvalid tokenr   r   r   r   r   s     r   r   zInvalidToken.__init__|   s)    GOIIIIIr   Nr#   r(   r)   r*   r+   r,   r   r/   r0   s   @r   r   r   q   sr          IJ Jd
 Jd J J J J J J J J J Jr   r   c                       e Zd ZdZdZdS )r	   zRaised when the requested endpoint is not found. Only relevant for
    :meth:`telegram.Bot.do_api_request`.

    .. versionadded:: 20.8
    r2   Nr3   r2   r   r   r	   r	      s          IIIr   r	   c                       e Zd ZdZdZdS )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>`
    r2   Nr3   r2   r   r   r   r      s           IIIr   r   c                       e Zd ZdZdZdS )r   z=Raised when Telegram could not process the request correctly.r2   Nr3   r2   r   r   r   r      s        GGIIIr   r   c                   8     e Zd ZdZdZddedz  ddf fdZ xZS )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
    r2   Nr   r   c                 N    t                                          |pd           d S )Nz	Timed outr6   r7   s     r   r   zTimedOut.__init__   s&    /K00000r   r8   r9   r0   s   @r   r   r      se        	 	 I1 1d
 1d 1 1 1 1 1 1 1 1 1 1r   r   c                   T     e Zd ZdZdZdef fdZdeeee         f         fdZ	 x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_idr@   c                 ^    t                                          d|            || _        d S )Nz+Group migrated to supergroup. New chat id: )r   r   r@   )r   r@   r   s     r   r   zChatMigrated.__init__   s2    T{TTUUU +r   r   c                      | j         | j        ffS r8   )r   r@   r    s    r   r'   zChatMigrated.__reduce__   s    ~ 0222r   )r#   r(   r)   r*   r+   intr   r-   r.   r'   r/   r0   s   @r   r   r      s~          !I,C , , , , , ,3E$c
"23 3 3 3 3 3 3 3 3r   r   c                        e Zd ZdZdZdef fdZedee	j
        z  fd            Zdeeee         f         fdZ x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                    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   rE   
isinstancerF   rC   r   r   )r   rF   r   s     r   r   zRetryAfter.__init__   s    +7+D+Dd&,, 	WGG[AQ[[[\\\\\GGUAQUUVVVVVr   r   c                 .    t          | j        d          S )NrF   )	attribute)r   rE   r    s    r   rF   zRetryAfter.retry_after   s#     #
 
 
 	
r   c                 ^    | j         t          | j                                                  ffS r8   )r   rC   rE   total_secondsr    s    r   r'   zRetryAfter.__reduce__   s+     ~D$5$C$C$E$E F FHHHr   )r#   r(   r)   r*   r+   r   r   propertyrC   dtm	timedeltarF   r-   r.   floatr'   r/   r0   s   @r   r   r      s         , "IWJ W W W W W W 
S3=0 
 
 
 X
IE$e"45 I I I I I I I Ir   r   c                   >    e Zd ZdZdZdeeee         f         fdZdS )r   z>Raised when a long poll or webhook conflicts with another one.r2   r   c                      | j         | j        ffS r8   r&   r    s    r   r'   zConflict.__reduce__  s    ~..r   N)	r#   r(   r)   r*   r+   r-   r.   r,   r'   r2   r   r   r   r      sH        HHI/E$c
"23 / / / / / /r   r   c                   Z     e Zd ZdZdZdeez  f fdZdee	ee         f         fdZ
 x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                 x    t                                          d|            t          |          | _        d S )NzPassportDecryptionError: )r   r   r,   rT   r7   s     r   r   z PassportDecryptionError.__init__  s5    >W>>???LL			r   r   c                      | j         | j        ffS r8   )r   rT   r    s    r   r'   z"PassportDecryptionError.__reduce__  s    ~	|++r   )r#   r(   r)   r*   r+   r,   	Exceptionr   r-   r.   r'   r/   r0   s   @r   r   r     s          I!i ! ! ! ! ! !,E$c
"23 , , , , , , , ,r   r   )r*   datetimerN   telegram._utils.argumentparsingr   telegram._utils.datetimer   telegram._utils.typesr   __all__rW   r   r
   r   r	   r   r   r   r   r   r   r   r2   r   r   <module>r]      sD  &      8 8 8 8 8 8 8 8 8 8 8 8 , , , , , ,3/ 3/ 3/ 3/ 3/I 3/ 3/ 3/l
 
 
 
 
 
 
 
J J J J J= J J J    }       =   (       1 1 1 1 1| 1 1 1$3 3 3 3 3= 3 3 32+I +I +I +I +I +I +I +I\/ / / / /} / / /, , , , ,m , , , , ,r   