o
    tf                     @  sr   d dl mZ d dlZd dlmZmZ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 G dd dZdS )	    )annotationsN)AuthCredentialsAuthenticationBackendAuthenticationErrorUnauthenticatedUser)HTTPConnection)PlainTextResponseResponse)ASGIAppReceiveScopeSendc                   @  s2   e Zd Z	ddd
dZdddZedddZdS )AuthenticationMiddlewareNappr
   backendr   on_errorGtyping.Callable[[HTTPConnection, AuthenticationError], Response] | NonereturnNonec                 C  s*   || _ || _|d ur|| _d S | j| _d S N)r   r   default_on_errorr   )selfr   r   r    r   l/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/starlette/middleware/authentication.py__init__   s   
z!AuthenticationMiddleware.__init__scoper   receiver   sendr   c              
     s   |d dvr|  |||I d H  d S t|}z| j|I d H }W n3 tyU } z'| ||}|d dkrA|dddI d H  n	||||I d H  W Y d }~d S d }~ww |d u r`t t f}|\|d< |d< |  |||I d H  d S )	Ntype)http	websocketr    zwebsocket.closei  )r   codeauthuser)r   r   r   Zauthenticater   r   r   r   )r   r   r   r   connZauth_resultexcresponser   r   r   __call__   s&   z!AuthenticationMiddleware.__call__r$   r   r%   	Exceptionr	   c                 C  s   t t|ddS )Ni  )status_code)r   str)r$   r%   r   r   r   r   3   s   z)AuthenticationMiddleware.default_on_errorr   )r   r
   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r$   r   r%   r(   r   r	   )__name__
__module____qualname__r   r'   staticmethodr   r   r   r   r   r      s    
r   )
__future__r   typingZstarlette.authenticationr   r   r   r   Zstarlette.requestsr   Zstarlette.responsesr   r	   Zstarlette.typesr
   r   r   r   r   r   r   r   r   <module>   s    