o
     d                     @   sf   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 )    N)AuthCredentialsAuthenticationBackendAuthenticationErrorUnauthenticatedUser)HTTPConnection)PlainTextResponseResponse)ASGIAppReceiveScopeSendc                
   @   sr   e Zd Z	ddededejejee	ge
f  ddfddZded	ed
eddfddZededede
fddZdS )AuthenticationMiddlewareNappbackendon_errorreturnc                 C   s*   || _ || _|d ur|| _d S | j| _d S N)r   r   default_on_errorr   )selfr   r   r    r   N/usr/local/lib/python3.10/dist-packages/starlette/middleware/authentication.py__init__   s   
z!AuthenticationMiddleware.__init__scopereceivesendc              
      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   authenticater   r   r   r   )r   r   r   r   connauth_resultexcresponser   r   r   __call__   s&   z!AuthenticationMiddleware.__call__r"   r$   c                 C   s   t t|ddS )Ni  )status_code)r   str)r"   r$   r   r   r   r   2   s   z)AuthenticationMiddleware.default_on_errorr   )__name__
__module____qualname__r	   r   typingOptionalCallabler   r   r   r   r   r
   r   r&   staticmethod	Exceptionr   r   r   r   r   r      s     
r   )r,   starlette.authenticationr   r   r   r   starlette.requestsr   starlette.responsesr   r   starlette.typesr	   r
   r   r   r   r   r   r   r   <module>   s    