
    sojr                     *   d Z ddlmZ ddlmZmZmZmZm	Z	m
Z
  G d de          ZdefdZ ed	          Z ed
          Z ed          Z ed          Z ed          Z ed          Z ed          Z ed          Z ed          Zd ZdS )al  
Shared Telethon -> telegram.error translation, used by every compat module
that makes a real Telethon call (Chat.leave, Message.delete, Bot.send_message,
etc), so that every `except BadRequest` / `except Forbidden` / `except
TelegramError` clause throughout the original codebase keeps behaving the
same regardless of which compat method raised it.

Telethon groups its RPC errors into a handful of base classes matching the
Bot-API-ish status categories (see telethon.errors.rpcbaseerrors), which is
what this maps onto telegram.error's hierarchy. A few specific, very common
errors are special-cased first because the original codebase string-matches
on their message text (e.g. "message is not modified").

Exception classes are looked up defensively (getattr with a dummy fallback)
rather than imported by name directly: if a Telethon version ever renames one
of these, the corresponding `except` clause just quietly never matches
instead of raising AttributeError while Python is trying to walk the except
chain - the outer `except Exception` catch-all still guarantees every error
surfaces as *some* telegram.error subclass.
    )errors   )
BadRequest	ForbiddenTimedOutNetworkError
RetryAfterTelegramErrorc                       e Zd ZdZdS )_NeverMatcheszFPlaceholder used when an expected Telethon error class can't be found.N)__name__
__module____qualname____doc__     /app/src/tg_compat/_errors.pyr   r      s        PPPPr   r   namec                 8    t          t          | t                    S )N)getattr	tl_errorsr   )r   s    r   _lookupr      s    9dM222r   FloodWaitErrorMessageNotModifiedErrorMessageIdInvalidErrorQueryIdInvalidErrorUserNotParticipantErrorForbiddenErrorUnauthorizedErrorBadRequestErrorNotFoundErrorc                   K   	 |  d{V S # t           $ r$}t          t          |dd                    |d}~wt          $ r}t	          d          |d}~wt
          $ r}t	          d          |d}~wt          $ r}t	          d          |d}~wt          $ r"}t	          t          |                    |d}~wt          $ r"}t          t          |                    |d}~wt          $ r"}t          t          |                    |d}~wt          $ r"}t	          t          |                    |d}~wt          $ r"}t	          t          |                    |d}~wt          t          t           f$ r"}t#          t          |                    |d}~wt$          $ r  t&          $ r"}t%          t          |                    |d}~ww xY w)zAwait `coro`, re-raising any Telethon/MTProto error as the matching
    telegram.error type. Pass an *unawaited* coroutine/awaitable in.Nseconds   zMessage is not modifiedzMessage to edit not foundzDQuery is too old and response timeout expired or query id is invalid)_FloodWaitErrorr	   r   _MessageNotModifiedErrorr   _MessageIdInvalidError_QueryIdInvalidError_UserNotParticipantErrorstr_ForbiddenErrorr   _UnauthorizedError_BadRequestError_NotFoundErrorTimeoutErrorConnectionErrorOSErrorr   r
   	Exception)coroes     r   translate_errorsr5   .   s&     +zzzzzz : : :Iq11229# ; ; ;233:! = = =4551<   R
 
	 $ ( ( (Q  a' ' ' 'AQ& ' ' 'AQ& ( ( (Q  a' ( ( (Q  a'/73 & & &s1vvA%    + + +CFF##*+s    
G5GAGA//G<BGB66GC  G-D

GD44GEG8FG,G		GN)r   telethonr   r   errorr   r   r   r   r	   r
   r2   r   r*   r   r%   r&   r'   r(   r)   r+   r,   r-   r.   r5   r   r   r   <module>r8      sP   * ) ( ( ( ( ( [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [Q Q Q Q QI Q Q Q3# 3 3 3 3 '*++"7#<==  !899 w455 "7#<== '*++W011 7,-- ))+ + + + +r   