a
    c	g&                     @  s   d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZmZmZmZmZmZmZmZ d dlmZ ejejef Zejeef Zd	d
ddddZddddddZdS )    )annotationsN)is_async_callable)run_in_threadpool)HTTPException)Request)ASGIAppExceptionHandlerHTTPExceptionHandlerMessageReceiveScopeSendWebSocketExceptionHandler)	WebSocketExceptionHandlers	ExceptionzExceptionHandler | None)exc_handlersexcreturnc                 C  s(   t |jD ]}|| v r
| |   S q
d S )N)type__mro__)r   r   cls r   _/var/www/html/llm_bihealth/app/venv/lib/python3.9/site-packages/starlette/_exception_handler.py_lookup_exception_handler   s    r   r   zRequest | WebSocket)appconnr   c                   sR   zj d \W n ty.   i i  Y n0 ddddd fdd}|S )	Nzstarlette.exception_handlersr   r   r   None)scopereceivesendr   c              
     sb  d ddd fdd}z| ||I d H  W n* t y\ } zd }t|tr`|j}|d u rrt|}|d u r~| rd}t||| d d	krtt	|}tt
t|r||I d H }nt||I d H }|| ||I d H  nT| d d
krHtt|}ttt|r6||I d H  nt||I d H  W Y d }~n
d }~0 0 d S )NFr
   r   )messager   c                   s"   | d dkrd | I d H  d S )Nr   zhttp.response.startTr   )r!   Zresponse_startedr    r   r   sender-   s    zAwrap_app_handling_exceptions.<locals>.wrapped_app.<locals>.senderz7Caught handled exception, but response already started.r   httpZ	websocket)r   
isinstancer   getstatus_coder   RuntimeErrortypingcastr	   r   r   r   r   r   )r   r   r    r#   r   handlermsgresponser   r   Zexception_handlersZstatus_handlersr"   r   wrapped_app*   s8    



z1wrap_app_handling_exceptions.<locals>.wrapped_app)r   KeyError)r   r   r/   r   r.   r   wrap_app_handling_exceptions"   s    -r1   )
__future__r   r)   Zstarlette._utilsr   Zstarlette.concurrencyr   Zstarlette.exceptionsr   Zstarlette.requestsr   Zstarlette.typesr   r   r	   r
   r   r   r   r   Zstarlette.websocketsr   DictAnyr   intZStatusHandlersr   r1   r   r   r   r   <module>   s   (
	