
    9Cg
                        d dl mZ d dlZd dlmZmZmZ d dlmZm	Z	 d dl
mZ d dlmZmZ d dlmZmZmZmZ d dlmZ  G d	 d
          ZdS )    )annotationsN)ExceptionHandlersStatusHandlerswrap_app_handling_exceptions)HTTPExceptionWebSocketException)Request)PlainTextResponseResponse)ASGIAppReceiveScopeSend)	WebSocketc                  <    e Zd Z	 	 d!d"dZd#dZd$dZd%dZd&d ZdS )'ExceptionMiddlewareNFappr   handlersRtyping.Mapping[typing.Any, typing.Callable[[Request, Exception], Response]] | NonedebugboolreturnNonec                    || _         || _        i | _        t          | j        t
          | j        i| _        |0|                                D ]\  }}| 	                    ||           d S d S N)
r   r   _status_handlersr   http_exceptionr   websocket_exception_exception_handlersitemsadd_exception_handler)selfr   r   r   keyvalues         Q/var/www/api/venv/lib/python3.11/site-packages/starlette/middleware/exceptions.py__init__zExceptionMiddleware.__init__   s     
024. 87
  &nn.. 7 7
U**36666  7 7    exc_class_or_status_codeint | type[Exception]handler/typing.Callable[[Request, Exception], Response]c                    t          |t                    r|| j        |<   d S t          |t                    sJ || j        |<   d S r   )
isinstanceintr   
issubclass	Exceptionr   )r"   r(   r*   s      r%   r!   z)ExceptionMiddleware.add_exception_handler#   sW    
 .44 	I>ED!":;;;6	BBBBBAHD$%=>>>r'   scoper   receiver   sendr   c                (  K   |d         dvr|                      |||           d {V  d S | j        | j        f|d<   |d         dk    rt          |||          }nt	          |||          } t          | j         |          |||           d {V  d S )Ntype)http	websocketzstarlette.exception_handlersr6   )r   r   r   r	   r   r   )r"   r1   r2   r3   conns        r%   __call__zExceptionMiddleware.__call__.   s      = 555((5'4000000000F $!1
,- =F""5'400DDUGT22D:*48T::5'4PPPPPPPPPPPr'   requestr	   excr0   r   c                    t          |t                    sJ |j        dv rt          |j        |j                  S t          |j        |j        |j                  S )N>   0     )status_codeheaders)r-   r   r?   r   r@   r
   detail)r"   r:   r;   s      r%   r   z"ExceptionMiddleware.http_exception@   sY    #}-----?j((MMMM RUR]^^^^r'   r7   r   c                   K   t          |t                    sJ |                    |j        |j                   d {V  d S )N)codereason)r-   r   closerC   rD   )r"   r7   r;   s      r%   r   z'ExceptionMiddleware.websocket_exceptionF   sO      #122222oo38CJo???????????r'   )NF)r   r   r   r   r   r   r   r   )r(   r)   r*   r+   r   r   )r1   r   r2   r   r3   r   r   r   )r:   r	   r;   r0   r   r   )r7   r   r;   r0   r   r   )__name__
__module____qualname__r&   r!   r9   r   r    r'   r%   r   r      s         hl	7 7 7 7 7"	I 	I 	I 	IQ Q Q Q$_ _ _ _@ @ @ @ @ @r'   r   )
__future__r   typingstarlette._exception_handlerr   r   r   starlette.exceptionsr   r   starlette.requestsr	   starlette.responsesr
   r   starlette.typesr   r   r   r   starlette.websocketsr   r   rI   r'   r%   <module>rR      s	   " " " " " "          
 C B B B B B B B & & & & & & ; ; ; ; ; ; ; ; 9 9 9 9 9 9 9 9 9 9 9 9 * * * * * *7@ 7@ 7@ 7@ 7@ 7@ 7@ 7@ 7@ 7@r'   