U
    ¯ªhU  ã                   @   sÄ   d Z ddlZddlZddlm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-Errors not related to the Telegram API itselfé    Né   )Ú	TLRequestc                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚReadCancelledErrorz+Occurs when a read operation was cancelled.c                    s   t ƒ  d¡ d S )Nz!The read operation was cancelled.©ÚsuperÚ__init__©Úself©Ú	__class__© ú:/tmp/pip-unpacked-wheel-c81u5j2r/telethon/errors/common.pyr   
   s    zReadCancelledError.__init__©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__r   r   r
   r   r      s   r   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚTypeNotFoundErrorz|
    Occurs when a type is not found, for example,
    when trying to read a TLObject with an invalid constructor code.
    c                    s$   t ƒ  d ||¡¡ || _|| _d S )NzšCould not find a matching Constructor ID for the TLObject that was supposed to be read with ID {:08x}. See the FAQ for more details. Remaining bytes: {!r})r   r   ÚformatÚinvalid_constructor_idÚ	remaining)r	   r   r   r
   r   r   r      s     ýÿzTypeNotFoundError.__init__r   r   r   r
   r   r      s   r   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚInvalidChecksumErrorz|
    Occurs when using the TCP full mode and the checksum of a received
    packet doesn't match the expected checksum.
    c                    s$   t ƒ  d ||¡¡ || _|| _d S )NzJInvalid checksum ({} when {} was expected). This packet should be skipped.)r   r   r   ÚchecksumÚvalid_checksum)r	   r   r   r
   r   r   r   #   s     þÿzInvalidChecksumError.__init__r   r   r   r
   r   r      s   r   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚInvalidBufferErrorz˜
    Occurs when the buffer is invalid, and may contain an HTTP error code.
    For instance, 404 means "forgotten/broken authorization key", while
    c                    sZ   || _ t|ƒdkr<t d|¡d  | _tƒ  d | j¡¡ nd | _tƒ  d | j ¡¡ d S )Né   z<ir   z&Invalid response buffer (HTTP code {})z&Invalid response buffer (too short {}))ÚpayloadÚlenÚstructÚunpackÚcoder   r   r   )r	   r   r
   r   r   r   2   s    
ÿ
ÿzInvalidBufferError.__init__r   r   r   r
   r   r   -   s   r   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚAuthKeyNotFounda  
    The server claims it doesn't know about the authorization key (session
    file) currently being used. This might be because it either has never
    seen this authorization key, or it used to know about the authorization
    key but has forgotten it, either temporarily or permanently (possibly
    due to server errors).

    If the issue persists, you may need to recreate the session file and login
    again. This is not done automatically because it is not possible to know
    if the issue is temporary or permanent.
    c                    s   t ƒ  t | jj¡¡ d S )N)r   r   ÚtextwrapÚdedentr   r   r   r
   r   r   r   J   s    zAuthKeyNotFound.__init__r   r   r   r
   r   r"   >   s   r"   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚSecurityErrorzL
    Generic security error, mostly used when generating a new AuthKey.
    c                    s   |s
dg}t ƒ j|Ž  d S )NzA security check failed.r   )r	   Úargsr
   r   r   r   R   s    zSecurityError.__init__r   r   r   r
   r   r%   N   s   r%   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚCdnFileTamperedErrorzg
    Occurs when there's a hash mismatch between the decrypted CDN file
    and its expected hash.
    c                    s   t ƒ  d¡ d S )Nz9The CDN file has been altered and its download cancelled.r   r   r
   r   r   r   ]   s    ÿzCdnFileTamperedError.__init__r   r   r   r
   r   r'   X   s   r'   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚAlreadyInConversationErrorzP
    Occurs when another exclusive conversation is opened in the same chat.
    c                    s   t ƒ  d¡ d S )NzSCannot open exclusive conversation in a chat that already has one open conversationr   r   r
   r   r   r   g   s    ÿz#AlreadyInConversationError.__init__r   r   r   r
   r   r(   c   s   r(   c                       s<   e Zd ZdZdddddddd	d
dddœZ‡ fdd„Z‡  ZS )ÚBadMessageErrorz0Occurs when handling a bad_message_notification.a*  msg_id too low (most likely, client time is wrong it would be worthwhile to synchronize it using msg_id notifications and re-send the original message with the "correct" msg_id or wrap it in a container with a new msg_id if the original message had waited too long on the client to be transmitted).zˆmsg_id too high (similar to the previous case, the client time has to be synchronized, and the message re-sent with the correct msg_id).zfIncorrect two lower order msg_id bits (the server expects client message msg_id to be divisible by 4).zaContainer msg_id is the same as msg_id of a previously received message (this must never happen).zmMessage too old, and it cannot be verified whether the server has received a message with this msg_id or not.z…msg_seqno too low (the server has already received a message with a lower msg_id but with either a higher or an equal and odd seqno).zzmsg_seqno too high (similarly, there is a message with a higher msg_id but with either a lower or an equal and odd seqno).zBAn even msg_seqno expected (irrelevant message), but odd received.z=Odd msg_seqno expected (relevant message), but even received.zIncorrect server salt (in this case, the bad_server_salt response is received with the correct salt, and the message is to be re-sent with it).zInvalid container.)é   é   é   é   é   é    é!   é"   é#   é0   é@   c              	      s(   t ƒ  || j |d |¡¡¡ || _d S )Nz0Unknown error code (this should not happen): {}.)r   r   ÚErrorMessagesÚgetr   r!   )r	   Úrequestr!   r
   r   r   r   •   s
    þzBadMessageError.__init__)r   r   r   r   r5   r   r   r   r   r
   r   r)   n   s   Þ%r)   c                   @   s   e Zd ZdZdd„ ZdS )Ú
MultiErrorz/Exception container for multiple `TLRequest`'s.c                 C   s´   t |ƒt |ƒ  kr t |ƒkr,n ntdƒ‚t||ƒD ]<\}}t|tƒs\|d k	r\td| ƒ‚t|tƒs6td| ƒ‚q6t |ƒdkrˆ|d S t | ¡}t|ƒ|_	t|ƒ|_
t|ƒ|_|S )Nz1Need result, exception and request for each errorz&Expected an exception object, not '%r'z#Expected TLRequest object, not '%r'é   r   )r   Ú
ValueErrorÚzipÚ
isinstanceÚBaseExceptionÚ	TypeErrorr   Ú__new__ÚlistÚ
exceptionsÚresultsÚrequests)ÚclsrA   ÚresultrC   ÚeÚreqr	   r   r   r   r?       s(    $ÿÿ
ÿ



zMultiError.__new__N)r   r   r   r   r?   r   r   r   r   r8      s   r8   )r   r   r#   Útlr   Ú	Exceptionr   r   r   ÚBufferErrorr   r"   r%   r'   r(   r)   r8   r   r   r   r   Ú<module>   s   
/