U
    e                     @   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                   @   s`   e Zd Zdeeejejee	ge
f  ddddZeeeddddZeeee
dd	d
ZdS )AuthenticationMiddlewareN)appbackendon_errorreturnc                 C   s$   || _ || _|d k	r|n| j| _d S )N)r   r   default_on_errorr   )selfr   r   r    r   d/var/www/html/assets/scripts/venv/lib/python3.8/site-packages/starlette/middleware/authentication.py__init__   s    z!AuthenticationMiddleware.__init__)scopereceivesendr   c              
      s   |d dkr$|  |||I d H  d S t|}z| j|I d H }W nh tk
r } zJ| ||}|d dkr|dddI d H  n||||I d H  W Y d S d }~X Y nX |d krt 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   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_error)N)__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)   Z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
   