a
    h
                     @  s   d dl mZ d dlmZ d dlm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mZ d d	lmZ G d
d dZdS )    )annotations)Mapping)Any)ExceptionHandlersStatusHandlerswrap_app_handling_exceptions)HTTPExceptionWebSocketException)Request)PlainTextResponseResponse)ASGIAppExceptionHandlerReceiveScopeSend)	WebSocketc                   @  sl   e Zd Zdddddddd	Zd
dddddZdddddddZddddddZddddddZdS ) ExceptionMiddlewareNFr   z%Mapping[Any, ExceptionHandler] | NoneboolNone)apphandlersdebugreturnc                 C  sN   || _ || _i | _t| jt| ji| _|d urJ| D ]\}}| 	|| q4d S N)
r   r   _status_handlersr   http_exceptionr	   websocket_exception_exception_handlersitemsadd_exception_handler)selfr   r   r   keyvalue r$   [/var/www/html/assistant/venv/lib/python3.9/site-packages/starlette/middleware/exceptions.py__init__   s    zExceptionMiddleware.__init__zint | type[Exception]r   )exc_class_or_status_codehandlerr   c                 C  s2   t |tr|| j|< nt|ts$J || j|< d S r   )
isinstanceintr   
issubclass	Exceptionr   )r!   r'   r(   r$   r$   r%   r    $   s    
z)ExceptionMiddleware.add_exception_handlerr   r   r   )scopereceivesendr   c                   sx   |d dvr$|  |||I d H  d S | j| jf|d< |d dkrNt|||}nt|||}t| j ||||I d H  d S )Ntype)http	websocketzstarlette.exception_handlersr1   )r   r   r   r
   r   r   )r!   r-   r.   r/   connr$   r$   r%   __call__/   s    zExceptionMiddleware.__call__r
   r,   r   )requestexcr   c                   s<   t |tsJ |jdv r(t|j|jdS t|j|j|jdS )N>   i0     )status_codeheaders)r)   r   r8   r   r9   r   Zdetail)r!   r5   r6   r$   r$   r%   r   A   s    
z"ExceptionMiddleware.http_exceptionr   )r2   r6   r   c                   s*   t |tsJ |j|j|jdI d H  d S )N)codereason)r)   r	   closer:   r;   )r!   r2   r6   r$   r$   r%   r   G   s    z'ExceptionMiddleware.websocket_exception)NF)__name__
__module____qualname__r&   r    r4   r   r   r$   r$   r$   r%   r      s     r   N)
__future__r   collections.abcr   typingr   Zstarlette._exception_handlerr   r   r   Zstarlette.exceptionsr   r	   Zstarlette.requestsr
   Zstarlette.responsesr   r   Zstarlette.typesr   r   r   r   r   Zstarlette.websocketsr   r   r$   r$   r$   r%   <module>   s   