o
    Ci                     @   s   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ed	ed
e je fddZde
de jeef d
e
fddZdS )    N)is_async_callable)run_in_threadpool)HTTPException)Request)ASGIAppExceptionHandlerHTTPExceptionHandlerMessageReceiveScopeSendWebSocketExceptionHandler)	WebSocketexc_handlersexcreturnc                 C   s(   t |jD ]}|| v r| |   S qd S )N)type__mro__)r   r   cls r   t/var/www/html/fyndo/python/python_agents/rag_suite/venv/lib/python3.10/site-packages/starlette/_exception_handler.py_lookup_exception_handler   s
   r   appconnc                    sX   z	j d \W n ty   i i Y nw dtdtdtdd f fdd}|S )Nzstarlette.exception_handlersscopereceivesendr   c              
      s  d dt dd f fdd}z| ||I d H  W d S  ty } zd }t|tr0|j}|d u r9t|}|d u r?| rHd}t||| d dkrzt	t
|}t	tt|rg||I d H }n	t||I d H }|| ||I d H  n6| d d	krt	t|}t	tt|r||I d H  nt||I d H  W Y d }~d S W Y d }~d S W Y d }~d S W Y d }~d S d }~ww )
NFmessager   c                    s$   | d dkr	d | I d H  d S )Nr   zhttp.response.startTr   )r   response_startedr   r   r   sender-   s   zAwrap_app_handling_exceptions.<locals>.wrapped_app.<locals>.senderz7Caught handled exception, but response already started.r   http	websocket)r	   	Exception
isinstancer   getstatus_coder   RuntimeErrortypingcastr   r   r   r   r   r   )r   r   r   r    r   handlermsgresponser   r   exception_handlersstatus_handlersr   r   wrapped_app*   sD   


 z1wrap_app_handling_exceptions.<locals>.wrapped_app)r   KeyErrorr   r
   r   )r   r   r0   r   r-   r   wrap_app_handling_exceptions    s   $-r2   )r(   starlette._utilsr   starlette.concurrencyr   starlette.exceptionsr   starlette.requestsr   starlette.typesr   r   r   r	   r
   r   r   r   starlette.websocketsr   DictAnyExceptionHandlersintStatusHandlersr#   Optionalr   Unionr2   r   r   r   r   <module>   s.    (

	