o
    ^~#g
                     @  s   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
 d
ZdS )    )annotationsN)ExceptionHandlersStatusHandlerswrap_app_handling_exceptions)HTTPExceptionWebSocketException)Request)PlainTextResponseResponse)ASGIApp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   handlersRtyping.Mapping[typing.Any, typing.Callable[[Request, Exception], Response]] | 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"   /var/www/static.ux5.de/https/Moving-Object-Detection-with-OpenCV/env/lib/python3.10/site-packages/starlette/middleware/exceptions.py__init__   s   zExceptionMiddleware.__init__exc_class_or_status_codeint | type[Exception]handler/typing.Callable[[Request, Exception], Response]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_handlersr1   )r   r   r   r   r   r   )r   r-   r.   r/   connr"   r"   r#   __call__.   s   zExceptionMiddleware.__call__requestr   excr,   r
   c                 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   r9   r
   r:   r	   detail)r   r5   r6   r"   r"   r#   r   @   s   
z"ExceptionMiddleware.http_exceptionr2   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   F   s   z'ExceptionMiddleware.websocket_exception)NF)r   r   r   r   r   r   r   r   )r%   r&   r'   r(   r   r   )r-   r   r.   r   r/   r   r   r   )r5   r   r6   r,   r   r
   )r2   r   r6   r,   r   r   )__name__
__module____qualname__r$   r   r4   r   r   r"   r"   r"   r#   r      s    


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   r"   r"   r"   r#   <module>   s    