o
    ùT·jà
  ã                   @  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%   úb/home/dinkstrade/pdmp-scanner/venv/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    