o
    ђ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                   @  sD   e Zd Z		d&d'ddZd(ddZd)ddZd*d d!Zd+d$d%ZdS ),ExceptionMiddlewareNFappr   handlers%Mapping[Any, ExceptionHandler] | NonedebugboolreturnNonec                 C  sR   || _ || _i | _t| jt| ji| _|d ur%| D ]\}}| 	|| qd S d S N)
r   r   _status_handlersr   http_exceptionr	   websocket_exception_exception_handlersitemsadd_exception_handler)selfr   r   r   keyvalue r%   X/var/www/html/govbot/env/lib/python3.10/site-packages/starlette/middleware/exceptions.py__init__   s   zExceptionMiddleware.__init__exc_class_or_status_codeint | type[Exception]handlerr   c                 C  s4   t |tr|| j|< d S t|tsJ || j|< d S r   )
isinstanceintr   
issubclass	Exceptionr   )r"   r(   r*   r%   r%   r&   r!   $   s   
z)ExceptionMiddleware.add_exception_handlerscoper   receiver   sendr   c                   sz   |d dvr|  |||I d H  d S | j| jf|d< |d dkr(t|||}nt|||}t| j ||||I d H  d S )Ntype)http	websocketzstarlette.exception_handlersr3   )r   r   r   r
   r   r   )r"   r/   r0   r1   connr%   r%   r&   __call__/   s   zExceptionMiddleware.__call__requestr
   excr.   r   c                   s>   t |tsJ |jdv rt|j|jdS t|j|j|jdS )N>   0     )status_codeheaders)r+   r   r;   r   r<   r   detail)r"   r7   r8   r%   r%   r&   r   A   s
   
z"ExceptionMiddleware.http_exceptionr4   r   c                   s,   t |tsJ |j|j|jdI d H  d S )N)codereason)r+   r	   closer>   r?   )r"   r4   r8   r%   r%   r&   r   G   s   z'ExceptionMiddleware.websocket_exception)NF)r   r   r   r   r   r   r   r   )r(   r)   r*   r   r   r   )r/   r   r0   r   r1   r   r   r   )r7   r
   r8   r.   r   r   )r4   r   r8   r.   r   r   )__name__
__module____qualname__r'   r!   r6   r   r   r%   r%   r%   r&   r      s    


r   N)
__future__r   collections.abcr   typingr   starlette._exception_handlerr   r   r   starlette.exceptionsr   r	   starlette.requestsr
   starlette.responsesr   r   starlette.typesr   r   r   r   r   starlette.websocketsr   r   r%   r%   r%   r&   <module>   s    