U
    dd                     @   s   d Z dZddlmZmZ eeedd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dS )zThis module contains classes that represent Telegram errors.

.. versionchanged:: 20.0
    Replaced ``Unauthorized`` by :class:`Forbidden`.
)

BadRequestChatMigratedConflict	ForbiddenInvalidTokenNetworkErrorPassportDecryptionError
RetryAfterTelegramErrorTimedOut    )TupleUnion)in_slstrreturnc                 C   s   |  |r| t|d S | S )z
    Args:
        in_s (:obj:`str`): in string
        lstr (:obj:`str`): substr to strip from left side

    Returns:
        :obj:`str`: The stripped string.

    N)
startswithlen)r   r    r   2/tmp/pip-unpacked-wheel-e3anp165/telegram/error.py_lstrip_str)   s    
r   c                       s`   e Zd ZdZdZed fddZedddZeddd	Ze	e
e	e f d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>`
    messagec                    sB   t    t|d}t|d}t|d}||kr8| }|| _d S )NzError: z	[Error]: zBad Request: )super__init__r   
capitalizer   )selfr   msg	__class__r   r   r   E   s    



zTelegramError.__init__r   c                 C   s   | j S Nr   r   r   r   r   __str__P   s    zTelegramError.__str__c                 C   s   | j j d| j dS )Nz('z'))r   __name__r   r!   r   r   r   __repr__S   s    zTelegramError.__repr__c                 C   s   | j | jffS r    r   r   r!   r   r   r   
__reduce__V   s    zTelegramError.__reduce__)r#   
__module____qualname____doc__	__slots__strr   r"   r$   r   typer&   __classcell__r   r   r   r   r	   6   s   r	   c                   @   s   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   Z   s   	r   c                       s.   e Zd ZdZdZdedd 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   Nr   r   c                    s   t  |d krdn| d S )NzInvalid tokenr   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   g   s   r   c                   @   s   e Zd ZdZdZdS )r   zwBase class for exceptions due to networking errors.

    Examples:
        :any:`Raw API Bot <examples.rawapibot>`
    r   Nr.   r   r   r   r   r   v   s   r   c                   @   s   e Zd ZdZdZdS )r   z=Raised when Telegram could not process the request correctly.r   Nr.   r   r   r   r   r      s   r   c                       s.   e Zd ZdZdZdedd fddZ  ZS )r
   zRaised when a request took too long to finish.

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

            .. versionadded:: 20.0
    r   Nr/   c                    s   t  |pd d S )Nz	Timed outr0   r1   r   r   r   r      s    zTimedOut.__init__)Nr2   r   r   r   r   r
      s   r
   c                       sD   e Zd ZdZdZed fddZeeee f d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_idc                    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   s   | j | jffS r    )r   r3   r!   r   r   r   r&      s    zChatMigrated.__reduce__)r#   r'   r(   r)   r*   intr   r   r,   r&   r-   r   r   r   r   r      s   r   c                       sD   e Zd ZdZdZed fddZeeee	 f dddZ
  ZS )r   ar  
    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`): Time in seconds, after which the bot can retry the request.

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

    )retry_afterc                    s   t  d| d || _d S )Nz!Flood control exceeded. Retry in z seconds)r   r   r5   )r   r5   r   r   r   r      s    zRetryAfter.__init__r   c                 C   s   | j | jffS r    )r   r5   r!   r   r   r   r&      s    zRetryAfter.__reduce__)r#   r'   r(   r)   r*   r4   r   r   r,   floatr&   r-   r   r   r   r   r      s   r   c                   @   s.   e Zd ZdZdZeeee f dddZdS )r   z>Raised when a long poll or webhook conflicts with another one.r   r   c                 C   s   | j | jffS r    r%   r!   r   r   r   r&      s    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eeef d fddZe	e
e	e f d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+   r7   r1   r   r   r   r      s    z PassportDecryptionError.__init__r   c                 C   s   | j | jffS r    )r   r7   r!   r   r   r   r&      s    z"PassportDecryptionError.__reduce__)r#   r'   r(   r)   r*   r   r+   	Exceptionr   r   r,   r&   r-   r   r   r   r   r      s   r   N)r)   __all__typingr   r   r+   r   r8   r	   r   r   r   r   r
   r   r   r   r   r   r   r   r   <module>   s   $
	